various: Up to 15 points
This exercise is meant to give you some practice adding a new feature to an existing program. The feature itself is simple: you’ll need to modify the VisualDataSet
class to add the ability to define a margin between the edges of the image and the area in which the foreground bars can appear:
For this exercise, the margin will always be the same on all sides of the image. In the example above, the display is 640 x 440 pixels and has a margin of 40 pixels, so the “data display area” shown is a 560 x 360 pixel rectangle in the center of the image.
VisualDataSet
with different margins.size
of the dataset, as well as its maximum
and minimum
values should be based on the size of the data display area rather than the entire image.main.py
or any python files other than visualdataset.py
.To check that your margin feature is implemented correctly, modify test_visualdataset_class
to test a margin of 20 using values of 640, 440 and 18 for width
, height
and bar_width
, respectively. If working properly, running python3 visualdataset
should produce terminal output similar to the following:
Expected number of values: 30
Actual number of values: 30
The lowest value should be no lower than 20.
Actual lowest value: 34
The highest value should be no higher than 400.
Actual highest value: 377
Generated values:
[94, 257, 241, 162, 145, 34, 75, 319, 46, 188, 275, 293, 377, 318, 70, 302, 35, 352, 242, 100, 278, 136, 66, 191, 259, 336, 35, 210, 329, 366]
Using the generated values listed above, the display would look like this:
__init__
method will affect any code you have anywhere in your program that creates a VisualDataSet
object. You will need to update this to avoid breaking your program.VisualDataSet
class should behave exactly as it was supposed to before you added this feature.Caution!
Watch out for unintended side-effects! Make sure to check all your code carefully to verify that it still works and its behavior has not changed.