Testing the pie chart

  • Add a copy method that makes a complete pie with wedges

  • Need a name for the prototypical wedge.



Testing the pie chart

We are now ready to test the chart and wedge. We can do this by making copies of the wedge, setting amounts, then embedding the wedge morphs into the chart, but this soon gets tedious.

Instead, let's add a method to make a whole chart, including wedges. We'll put the method in the chart. It needs some way to name the prototypical wedge, so we'll add a slot called pieWedgeMorph to the chart object and connect it to our prototypical wedge by arrow-dragging.

We should also add a morphTypeName slot to the chart, so that the header is more informative:

morphTypeName = 'pieChartMorph' The method copyData: will take a collection of values, build wedges corresponding to them, and return a new chart containing the wedges:

	copyNewData: data = (| new. wList. |
		new: copyRemoveAllMorphs.
		wList:
			data copy mapBy: [| :val. w |
				w: pieWedgeMorph copyRemoveAllMorphs.
				w color: paint copyRandom.
				w amount: val.
			].
		new addAllMorphs: wList.
		new
	).
Sending copyNewData: (10 & 20 & 40 & 30) asVector to the chart gives us a new chart. We can drag this to the other window, then apply `Show Morph'. We should get a pie chart like the one shown (but with differently colored wedges).

Try the following:


    1. Resizing the pie chart
    2. Copying the pie chart
    3. Using the core sampler to extract a wedge
    4. Add the wedge to the other pie chart
    5. Get an object view of a wedge via the core sampler, change its amount, then send it layoutChanged to force layout to be updated.
This last test points out a weakness in the design: changing the amount does not automatically change the visual representation.

To fix this we rename the amount slot to rawAmount, then add these methods:

	amount = (rawAmount)

	amount: a = (rawAmount: a. layoutChanged)
rawAmount should be declared as private. Be sure to make the change in the prototype, not a copy!

[ Previous ] [ Index ] [ Next ]