Visualizer and Bar.
Visualizer
bars
I am using. I set their heights after I am specified which collection in
that dictionary I will visualize. After I set up the window in which all
bars will be displayed, I will tell those bars to display themselves.
Bar
Visualizer demo and do it. You will see a window popped
up with several bars! (In some window management system, you need to
"do it" twice to see the result.)
Now read the code carefully before you begin to start your job.
Explanations of given code:
In the class method demo of Visualizer, at first a dataset
as an array was formed.
Then, you feed the dataset to the Visualizer then tell it what binding
you want.
v forHeight: #avetempThis should tell the visualizer that you want to visualize average temperatures as heightbars. Then, all the bars are shown by execution of
show.
The data: method in class Visualizer is just to tell which
dictionary is wanted, and the instance variable bars is
initialized. In forHeight: method, the bars are generated
and added to bars.
The method show is one of the most important method here.
gc := (ExamplesBrowser prepareScratchWindowOfSize: 500 @ 200 )
graphicsContext.
This line is to create a GraphicsContext (a kind of window)
with size 500X200. The reason why numberOfBars is calculated
is we want the visualizer to know how many entries there are, and
assign an area for each bar. The maximum value of the data been visualized
is needed in order to create the mapping from values to heights of bars
in a give space.
In the showAt: withSize: highest method of Bar class,
The size of the rectangle to be drawn is decided in this way: the "full size"
rectangle will take a space in the given area with a quarter of the wide
room in the left and right, and 1/5 space in top and bottom. The "full size"
rectangle will be displayed if the height of this value is the highest
among those of the bars. The size of rectangle is proportional to the height
of this bar. The coordinations of the rectangle are added to aBarShape
.
gc displayPolygon: aBarShape at: index * x @ 0This line is to display a polygon specified in
aBarShape.
The coordinations in aBarShape are relative, referred to the
point after at:.
You need to change the demo method as:
v := Visualizer new data: cities.
v setName: #names.
v forHeight: #avetemp.
v show
Your job includes:
Hints:
gc displayString: aString at: aPoint.
while aString can be something like 12 printString and aPoint
can be something like 50@27. Notice that aPoint is an absolute
coordination.
show method.
After you finished, change your demo to see if you can use your visualizer to show the population of each city.
cat Visualizer.st | mail -s "lab 8 - YOUR NAME" cs2390@prism.gatech.edu
Please quit from VisualWorks before you logout.