Building a pie chart morph


Building the pie chart morph

Next we can build the morph that will contain the wedges.

Again, we start with a circleMorph. The wedges will be submorphs. To be sure that we can distinguish wedges from other kinds of submorphs (should these be added later), we add this slot to the wedge:

	morphTypeName = 'pieWedgeMorph'
The type name is also used in the object's header; as soon as the method is added, the header updates.

Next, to make the chart morph, we make another copy of the circleMorph prototype, and start adding slots. The first will be a method that computes the list of wedges in the morph.

	wedges = (| wList |
		wList: list copyRemoveAll.
		morphsDo: [| :m |
			m morphTypeName = 'pieWedgeMorph' ifTrue: [
				wList add: m.
			].
		].
		wList
	).
Note that we defensively use copyRemoveAll when making a new list; this protects us against prototype corruption.

[ Previous ] [ Index ] [ Next ]