Saint Louis University |
Computer Science 1020
|
Computer Science Department |
Topic: | Circular chronograms |
Collaboration Policy: | The lab should be completed working in pairs |
Submission Deadline: | 11:50am Friday, 8 March 2019 |
As the grand finale of our tree visualizations, we explore the
rendering of phylogenetic chronograms when using a circular layout as
follows.
While this rendering might seem wildly different than
our previous chronogram for
this tree, it turns out that it is drawn with what is essentially
the same recursive algorithm, with just a bit more care surrounding
the geometry. In particular, if you recall our original discussion
focused on the "T" shape that is used to extend from one branch to its two
subtrees. That same structure is used in the circular rendering, as
highlighted in a few parts of the following image:
Note that what in our previous drawing was the horizontal section of the "T" with a length proportional to the evolutionary time, remains a straight line segment but now eminating outward from the central origin of the diagram. What used to be the asymetric vertical line in our "T" shape, connecting to the two subsequent subtrees, is now an arc on a circle centered at the origin. Just as all the leaves in the traditional chronogram were aligned at the far right and with equal vertical separation, in our new diagram all leaves are evenly spaced along the outermost circle.
Circles
Fortunately, the Python turtle package already has precisely the
support we need for walking along an arc of a circle. In
particular, there is a command with signature
turtle.circle(distanceToOrigin, arcDegrees)That works as follows. It presume that you have oriented the turtle so that the origin of the circle lies due to the left of the turtle and at the indicated distance. With this orientation, a positive arc angle will cause the turtle to walk counterclockwise around the indicated origin (again so that the origin is always position due left of the turtle).
Distance
As noted above, you will need to know the distance to the origin
in order to draw an appropriate circular arc. Fortunately, the
turtle module has eactly what we need (again). There is a
function
Rotated text
This is a bit more challenging as the turtle module is
built on top of another Python module that only started
supporting rotated text in a relatively recent release. You will
not need to worry about implementing this feature. I've already
take care of writing a more complicated drawLabel
command that checks if the newest version is availble and if so
which positions the rotated text appropriately. If it finds that
the most recent package is unavailable, it reverts to drawing
all labels horizontally but truncating to at most five
characters so that they don't cluter the diagram quite so much.
We will start you with valid code for the prevoius lab, and thus the more traditional left-to-right chronograms. It turns out that the change is quite trivially, as soon as you can adjust to thinking about the geometry as polar coordiantes rather than the usual x/y coordinates. The only meaningful change that is needed is to replace the portion of the "T" with a circular arc rather than a straight line. Of course, more carefully bookkeeping will be necessary to produce such arcs.
While you could keep the old names, we recommend you rewrite the recursive signature of the draw function as follows.
def draw(tree, radiusScale, angleScale, parentTime):
The radiusScale parameter serves a similar purpose to the old xScale as it defines the distance of outward emination relative to each unit of evolutionary time being represented.
Whereas the old yScale was a vertical separation between neighboring leaves, the new angleScale defines the number of degrees of rotation between neighboring leaves. (To create our drawings, we set angleScale at the onset to be 360 divided by the total number of leaves.)
The parameter parentTime should be used similarly as the previous lab in denoting the evolutionary age of the presumed parent of the current branch being drawn, so that we can determine the difference between the parent's age and the current branch's presumed age.
In additional to change the recursive parameterization, you are responsible for rewriting the lateral() function that draws the circular portion of a "T" shape. To do this you will need to use the turtle circle function appropriately. Since all of the circular arcs should be based on the origin of the screen, you may use the turtle.distance(0,0) function to determine the current distance of the turtle from the origin.
We are providing you with two files:
circular.py
This is a working solution to the
previous lab. this should be your starting
point for this lab, though you will need to understand what
modifications to make in order to produce the new illustration
style.
samples.py
The four sample trees that include evoluationary time as
integer labels for internal nodes.
The samples file includes four example trees.
The biggest one, named
complex is the one used to generate the rendering in the
overview. Specifically, we rendered that with an original call to
The tree frog example can be rendered as
The chronogram from
page 118 of our text book could be rerendered as
Finally, although not particularly interest, the smallest sample
can be rendered as
One member of your partnership should electronically submit your modified file circular.py. The comments at the beginning of the file should clearly identify the member(s) of the partnernship.
The assignment is worth 25 points.