TreeLayout

class visualife.diagrams.TreeLayout(id, viewport, max_screen_x, max_screen_y, **kwargs)

Bases: object

Base class for drawing a tree

Parameters:id – (string) a string that is used to identify graphical elements of this tree.

ID of a node will be created as ID-idx where ID is the ID of this layout object and idx is the index of a node :param viewport: (SvgViewport) or its derivative :param max_screen_x: (int) - right screen coordinate :param max_screen_y: (int) - bottom screen coordinate :param kwargs: - see below

Keyword Arguments (**kwargs)(**kwargs):
 
  • width (number) – width of each node in pixels
  • height (number) – height of each node in pixels
  • separation (number) – minimum separation between nodes in pixels
  • x_margin (number) – white space margin for the diagram on both sides along X axis (in viewport units, e.g. pixels)
  • y_margin (number) – white space margin for the diagram on both sides along Y axis

Attributes Summary

id Returns ID string that identifies this drawing

Methods Summary

draw(root_node) Draws a binary tree given by its root node :param root_node: (BTreeNode) - root of the tree
get_edge_color(node) Returns the color of a line that connects a given node The color is defined by self.edge_color property of this class as follows: - self.edge_color is callable : self.edge_color(node.id) will be returned - self.edge_color is a list : self.edge_color[node.id] will be returned - self.edge_color is a string : self.edge_color will be returned :param node: (TreeNode) - a node that defines the line color :return: color (str)
set_style(**kwargs) parses parameters to style this tree :param kwargs: see below

Attributes Documentation

id

Returns ID string that identifies this drawing

Methods Documentation

draw(root_node: visualife.diagrams.TreeNode.TreeNode)

Draws a binary tree given by its root node :param root_node: (BTreeNode) - root of the tree

get_edge_color(node)

Returns the color of a line that connects a given node The color is defined by self.edge_color property of this class as follows:

  • self.edge_color is callable : self.edge_color(node.id) will be returned
  • self.edge_color is a list : self.edge_color[node.id] will be returned
  • self.edge_color is a string : self.edge_color will be returned
Parameters:node – (TreeNode) - a node that defines the line color
Returns:color (str)
set_style(**kwargs)

parses parameters to style this tree :param kwargs: see below

Keyword Arguments:
 
  • leaves_on_axis (boolean) –
    if True, all leaves (singletons) will be placed on X axis; otherwise they will be plotted on the Y coordinate accordingly to the clustering hierarchy
  • scale_edges (boolean) –
    if True, the length of radial edges will be determined proportionally to the distances stored in a given phylogenetic trees
  • node_shape (char) –
    a single character defining the shape of each mid-node: t and s draw triangles and squares respectively; both o and c draw circles
  • node_color (string, list[string] or callable) –
    color of a mid-tree node
  • node_size (float) –
    size of a mid-tree node, e.g. circle radius
  • node_stroke (string) –
    color of a mid-tree node outline
  • node_stroke_width (float) –
    width of a mid-tree node outline
  • leaf_shape (char) –
    a single character defining the shape of each leaf node: t and s draw triangles and squares respectively; both o and c draw circles
  • leaf_color (string, list[string] or callable) –
    color of a leaf node (i.e. representing a specie or a sequence)
  • leaf_size (float) –
    size of a leaf node, e.g. circle radius
  • leaf_stroke (string) –
    color of leaf node outline
  • leaf_stroke_width (float) –
    width of leaf node outline
  • label_color (string, list[string] or callable) –
    color of a label string, if drawn