def _render_helper_host(fig, node, show_internal_labels): """ Render helper for host tree """ global _g_host_counter if node.is_leaf(): # set up layout for node (will be used later for drawing lines between nodes) leaf_layout = tree.NodeLayout() leaf_layout.col = -VERTICAL_OFFSET leaf_layout.row = _g_host_counter _g_host_counter += LEAF_SPACING node.layout = leaf_layout # plot node using leaf_layout plot_loc = (leaf_layout.col, leaf_layout.row) fig.text(plot_loc, node.name, col=plot_tools.BLUE, h_a='left') else: # recursively call helper funciton on child nodes _render_helper_host(fig, node.left_node, show_internal_labels) _render_helper_host(fig, node.right_node, show_internal_labels) # get layouts for child nodes to determine position of current node right_layout = node.right_node.layout left_layout = node.left_node.layout # create layout for current node node.layout = tree.NodeLayout() node.layout.col = min(right_layout.col, left_layout.col) - HORIZONTAL_SPACING y_avg = (right_layout.row + left_layout.row) / 2 node.layout.row = y_avg # plot node using node_layout current_loc = (node.layout.col, node.layout.row) if show_internal_labels: fig.text(current_loc, node.name, col=plot_tools.BLUE, h_a='left') # draw line from current node to left node left_loc = (left_layout.col, left_layout.row) fig.line(current_loc, (node.layout.col, left_layout.row), col=plot_tools.BLACK) fig.line((node.layout.col, left_layout.row), left_loc, col=plot_tools.BLACK) # draw line from current node to right node right_loc = (right_layout.col, right_layout.row) fig.line(current_loc, (node.layout.col, right_layout.row), col=plot_tools.BLACK) fig.line((node.layout.col, right_layout.row), right_loc, col=plot_tools.BLACK)
def _render_helper_host(fig, node, show_internal_labels): """ Render helper for host tree """ global _g_host_counter if node.is_leaf(): # set up layout for node (will be used later for drawing lines between nodes) leaf_layout = tree.NodeLayout() leaf_layout.col = -VERTICAL_OFFSET leaf_layout.row = _g_host_counter _g_host_counter += LEAF_SPACING node.layout = leaf_layout # plot node using leaf_layout plot_loc = (leaf_layout.col, leaf_layout.row) textbox = fig.text(plot_loc, node.name, size=FONTSIZE, col=render_settings.BLUE, h_a='right') else: # recursively call helper function on child nodes _render_helper_host(fig, node.left_node, show_internal_labels) _render_helper_host(fig, node.right_node, show_internal_labels) # get layouts for child nodes to determine position of current node right_layout = node.right_node.layout left_layout = node.left_node.layout # create layout for current node node.layout = tree.NodeLayout() node.layout.col = min(right_layout.col, left_layout.col) - HORIZONTAL_SPACING # If this node has a leaf child, extend the length of the branch to allow extra spacing to render label if node.right_node.is_leaf() or node.left_node.is_leaf(): node.layout.col -= EXTRA_SPACING_FOR_LABEL y_avg = (right_layout.row + left_layout.row) / 2 node.layout.row = y_avg # plot node using node_layout current_loc = (node.layout.col, node.layout.row) if show_internal_labels: fig.text(current_loc, node.name, size=FONTSIZE, col=render_settings.BLUE, h_a='left') # draw line from current node to left node left_loc = (left_layout.col, left_layout.row) fig.line(current_loc, (node.layout.col, left_layout.row), col=render_settings.BLACK) fig.line((node.layout.col, left_layout.row), left_loc, col=render_settings.BLACK) # draw line from current node to right node right_loc = (right_layout.col, right_layout.row) fig.line(current_loc, (node.layout.col, right_layout.row), col=render_settings.BLACK) fig.line((node.layout.col, right_layout.row), right_loc, col=render_settings.BLACK)
def populate_nodes_with_order(tree_node, tree_type, ordering_dict, leaf_order): """ :param tree_node: the root node of the subtree we want to populate the temporal order information :param tree_type: the type of the tree :param ordering_dict: a dictionary that maps node tuples to their temporal order as described in topological_order :param leaf_order: the temporal order we should assign to the leaves of the tree """ layout = tree.NodeLayout() if tree_node.is_leaf(): layout.col = leaf_order tree_node.layout = layout else: node_tuple = (tree_node.name, tree_type) layout.col = ordering_dict[node_tuple] tree_node.layout = layout populate_nodes_with_order(tree_node.left_node, tree_type, ordering_dict, leaf_order) populate_nodes_with_order(tree_node.right_node, tree_type, ordering_dict, leaf_order)