This lab is a follow-up to Lab 7. In this lab, you will learn how to add color to the bar chart visualization program.
The visualization program we will use here is a bit different than the
one used in the previous lab. Download and file in Visualization.st, then execute:
Visualization demo.
You should get a window that looks like this:

The most important difference between the new version and the old in
terms of OOP is the way they create the graphics. The old program
uses GraphicsContext objects to draw things; when the
scratch window gets obscured by other windows, the graphics
information is lost; when the scratch window is exposed again, it
needs some special mechanism in the program to get the image redrawn.
The new program uses the VisualWorks user interface framework (see
chapter 30 of the VisualWorks book); the line, rectangle, and text
string objects it creates are managed by the UI framework and redrawn
when necessary; there is no special mechanism needed to handle
redrawing the graphics in case of exposure.
The structure of the new visualization is quite similar to that of the previous one:
Visualization class:
data: binds a dictionary database
with the visualization.
forHeight: binds an array of
values in the dictionary with the height attributes of
the bars.
setName: binds an array of strings
in the dictionary with the name label attributes of the
bars.
show: creates the bars and tell
the bars to show themselves.
demo: creates an example dictionary
and an example visualization.
Bar class:
showOn: creates a graphical
representation of the bar.
showAxes: draws the background
graphics (the zero line in this implementation).
The class method show in the Visualization
class creates an instance of ScheduledWindow and an
instance of CompositePart to be the content of the
window. The latter object then manages the rectangle and text
objects created by the bars.
The Rectangle objects can not be managed by the
CompositePart directly. They have to be converted to
VisualComponent objects. The asFiller
message sent to a Rectangle object in the following code
segment will do just that, and also makes the rectangle to be drawn as
filled as opposed to outlined:
composite add: aBarShape asFiller at: boundX @ boundY.
You will find this code segment in the showOn method of
the Bar class.
You can create VisualComponent objects as
wrappers of other VisualComponent objects.
Using wrappers, you can change the colors, fonts, and other properties
of the original, otherwise dull, visual objects. Try the following
code in VisualWorks:
Geometric circles.
In the circles class method of Geometric,
(GraphicsAttributesWrapper on: aVisualComponent)
attributes: (GraphicsAttributes new paint: aColorValue)
creates a wrapper object for a visual component and tells the wrapper to change the color of the visual component to the new color.
(For a detailed discussion of the UI framework, consult your text book.)
In the commonly used RGB color space, every color can be composed from three basic color components: red, green, and blue. For example,
| RGB triplet | Corresponding color |
|---|---|
| (0, 0, 0) | black |
| (1, 0, 0) | red |
| (1, 1, 0) | yellow |
| (1, 1, 1) | white |
| (1/2, 1/2, 1/2) | grey |
A ColorValue object represents a specific color. The
following creates the purple color:
ColorValue red:1 green: 0 blue: 1.
Now take a close look at the example code circles of
Geometric, and map population values to the color of the
bars in the visualization. The bar of the country with the most
population should be colored medium-red,
and the bar of the country with the least population should be colored
medium-blue:

These should help you code up the visualization:
forColor method and instance variables
colors and colorsMax in the
Visualization class, plus something in the
Bar class, etc.
File-out your visualization category and mail it
cat Visualization.st | elm -s "TI,Lab8,0123456789" cs2390@prism
Please quit from VisualWorks before you logout.
News Page | CS2390 Sum'97 Home Page | MMC-CaMILE | STABLE
Questions/comments/concerns to guzdial@cc.gatech.edu
Page last updated 8/15/97; 3:54:43 PM