Changeset 564 for mds-and-trees


Ignore:
Timestamp:
08/05/16 23:25:02 (8 years ago)
Author:
konrad
Message:

some changes to drawing style + non-random dissimilarity + assertion

File:
1 edited

Legend:

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

    r563 r564  
    2525
    2626def svg_generate_line_style(percent):
     27    # hotdog
    2728    from_col = [100, 70, 0]
    28     to_col = [100, 0, 0]
    29     # from_col = [0, 100, 50]
    30     # to_col = [20, 0, 100]
    31 
    32     percent = 1 - ((1-percent)**10)
     29    to_col = [60, 0, 0]
     30    # neon
     31    # from_col = [30, 200, 255]
     32    # to_col = [240, 0, 220]
     33
     34    from_opa = 0.2
     35    to_opa = 1.0
     36    from_stroke = 1
     37    to_stroke = 3
     38
     39    opa = from_opa*(1-percent) + to_opa*percent
     40    stroke = from_stroke*(1-percent) + to_stroke*percent
     41
     42    percent = 1 - ((1-percent)**20)
    3343
    3444    return 'stroke="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \
    3545           + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \
    36            + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="1" stroke-opacity="0.8"'
     46           + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="' + str(stroke) + '" stroke-opacity="' + str(opa) + '"'
    3747
    3848def svg_generate_dot_style(percent):
    3949    from_col = [100, 90, 0]
    40     to_col = [100, 0, 0]
    41     # from_col = [0, 100, 50]
    42     # to_col = [20, 0, 100]
    43 
    44     percent = 1 - ((1-percent)**10)
     50    to_col = [60, 0, 0]
     51    # neon
     52    # from_col = [30, 200, 255]
     53    # to_col = [240, 0, 220]
     54
     55    from_opa = 0.2
     56    to_opa = 1.0
     57
     58    opa = from_opa*(1-percent) + to_opa*percent
     59
     60    percent = 1 - ((1-percent)**20)
    4561
    4662    return 'fill="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \
    4763           + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \
    48            + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" r="1.5" stroke="black" stroke-width="0.2"' #fill-opacity="0.5"'
     64           + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" r="1.5" stroke="black" stroke-width="0.2" fill-opacity="' + str(opa) + '" ' \
     65           'stroke-opacity="' + str(opa) + '"'
    4966
    5067# -------------------
     
    6077                #print("B" +str(creature))
    6178                if "FromIDs" in creature:
     79                    assert(len(creature["FromIDs"]) == 1)
    6280                    nodes[creature["ID"]] = creature["FromIDs"][0]
    6381                    if not creature["FromIDs"][0] in nodes:
     
    131149    for c in inv_nodes[node]:
    132150        #print(node + "->" + c)
    133         dissimilarity = random.gauss(0,0.3)
     151        dissimilarity = 0.5 #random.gauss(0,0.3)
    134152        if TIME == "REAL":
    135153            id = ""
     
    165183        if c in inv_nodes:
    166184            draw_children_recurrent(c, max_depth)
     185
     186        line_style = (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth))
     187        dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[c]/max_depth))
     188
    167189        svg_add_line( (w_margin+w_no_margs*(positions[node][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[node][1]/max_height),
    168             (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height),
    169                       (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth)))
    170         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),
    171                      (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[c]/max_depth)))
     190            (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)
     191        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)
    172192def draw_children():
    173193    max_depth = 0
     
    175195            max_depth = max(max_depth, v)
    176196    draw_children_recurrent(firstnode, max_depth)
    177     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),
    178                  (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[firstnode]/max_depth)))
     197    dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[firstnode]/max_depth))
     198    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)
    179199
    180200def draw_spine_recurrent(node):
     
    184204            if c in inv_nodes:
    185205                draw_spine_recurrent(c)
     206
     207            line_style = svg_spine_line_style
    186208            svg_add_line( (w_margin+w_no_margs*(positions[node][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[node][1]/max_height),
    187                 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), svg_spine_line_style)
     209                (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)
    188210            #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), svg_spine_dot_style)
    189211def draw_spine():
     
    197219            if c in inv_nodes:
    198220                draw_skeleton_reccurent(c, max_depth)
     221
     222            line_style = svg_spine_line_style
    199223            svg_add_line( (w_margin+w_no_margs*(positions[node][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[node][1]/max_height),
    200                 (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height),
    201                           svg_spine_line_style)
     224                (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)
    202225            #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),
    203226            #             svg_spine_dot_style)
     
    210233    #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),
    211234    #             svg_spine_dot_style)
    212 
    213235
    214236
Note: See TracChangeset for help on using the changeset viewer.