Changeset 617


Ignore:
Timestamp:
09/21/16 17:52:27 (8 years ago)
Author:
konrad
Message:

Added non-recurrent verion of tree drawing function, draw_children_norec(). Not tested yet! Should it work, it will take the place of the current, recurrent method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mds-and-trees/tree-genealogy.py

    r615 r617  
    314314    svg_add_dot( (w_margin+w_no_margs*(positions[firstnode][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[firstnode][1]/max_height), dot_style)
    315315
     316
     317
     318def draw_children_norec():
     319    global visited
     320    visited = {}
     321    visited[firstnode] = True
     322
     323    max_depth = 0
     324    for k, v in depth.items():
     325            max_depth = max(max_depth, v)
     326
     327    nodes_to_visit = [firstnode]
     328    while True:
     329        current_node = nodes_to_visit[0]
     330
     331        for c in inv_nodes[current_node]:
     332
     333            # we want to draw the node just once
     334            if not all_parents_visited(c):
     335                continue
     336            else:
     337                visited[c] = True
     338
     339            if c in inv_nodes:
     340                nodes_to_visit.append(c)
     341
     342            line_style = ""
     343            if COLORING == "NONE":
     344                line_style = svg_line_style
     345            elif COLORING == "TYPE":
     346                line_style = (svg_mutation_line_style if len(nodes[c]) == 1 else svg_crossover_line_style)
     347            else: # IMPORTANCE, default
     348                line_style = svg_generate_line_style(depth[c]/max_depth)
     349
     350            for k, v in sorted(nodes[c].items()):
     351                svg_add_line( (w_margin+w_no_margs*(positions[k][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[k][1]/max_height),
     352                    (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), line_style)
     353
     354            if DOT_STYLE == "NONE":
     355                continue
     356            elif DOT_STYLE == "TYPE":
     357                dot_style = svg_generate_dot_style(kind[c] if c in kind else 0) #type
     358            else: # NORMAL, default
     359                dot_style = svg_clear_dot_style #svg_generate_dot_style(depth[c]/max_depth)
     360            svg_add_dot( (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), dot_style)
     361            #svg_add_text( str(depth[c]), (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), "end")
     362
     363        # we remove the current node from the list
     364        nodes_to_visit = nodes_to_visit[1:]
     365        # if none left, we can stop
     366        if len(nodes_to_visit) == 0:
     367            break
     368
     369    if DOT_STYLE == "NONE":
     370        return
     371    elif DOT_STYLE == "TYPE":
     372        dot_style = svg_generate_dot_style(kind[firstnode] if firstnode in kind else 0)
     373    else: # NORMAL, default
     374        dot_style = svg_clear_dot_style #svg_generate_dot_style(depth[c]/max_depth)
     375    svg_add_dot( (w_margin+w_no_margs*(positions[firstnode][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[firstnode][1]/max_height), dot_style)
     376
    316377def draw_spine_recurrent(node):
    317378    global visited
Note: See TracChangeset for help on using the changeset viewer.