Object subclass: #Visualizer instanceVariableNames: 'data bars ' classVariableNames: '' poolDictionaries: '' category: 'Visualizer'! !Visualizer methodsFor: 'showing'! show | gc numberOfBars max| numberOfBars := bars size. gc := (ExamplesBrowser prepareScratchWindowOfSize: 500 @ 200 ) graphicsContext. max := bars first height. bars do: [:aBar | (max < (aBar height)) ifTrue: [max := aBar height]]. bars do: [:aBar | aBar showAt: gc withSize: (500/numberOfBars)@200 highest:max]! ! !Visualizer methodsFor: 'initialization'! data: aDictionary "connect this visualizer to a dictionary" data := aDictionary. bars := OrderedCollection new.! forHeight: anItem | collection aBar i| collection := data at: anItem. i := 0. collection do: [:aValue | aBar := Bar new. aBar height: aValue. aBar index: i. bars add: aBar. i := i+1].! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Visualizer class instanceVariableNames: ''! !Visualizer class methodsFor: 'demo'! demo | cities v | cities := Dictionary new. cities at: #names put: #(#Atlanta #Detroit #MexicoCity #Oz #NYC). cities at: #populations put: #(100000 1000000 10000000 10.78 3000000). cities at: #avetemp put: #(72 61 91 13 65). cities at: #meanness put: #(4 7 5 2 6). v := Visualizer new data: cities. "Opens up the Visualization window --just a Graphics pane." v forHeight: #avetemp. v show! ! Object subclass: #Bar instanceVariableNames: 'height index ' classVariableNames: '' poolDictionaries: '' category: 'Visualizer'! !Bar methodsFor: 'showing'! showAt: gc withSize: size highest: max | aBarShape x y | aBarShape := OrderedCollection new. x := size x. y := size y * 4 / 5. aBarShape add: x / 4 @ (y - (height * y * 3 / (max * 4))); add: x * 3 / 4 @ (y - (height * y * 3 / (max * 4))); add: x * 3 / 4 @ y; add: x / 4 @ y. gc displayPolygon: aBarShape at: index * x @ 0! ! !Bar methodsFor: 'accessing'! height ^height! height: aValue height := aValue! index: anIndex index := anIndex! !