# Changeset 564 for mds-and-trees/tree-genealogy.py

Ignore:
Timestamp:
08/05/16 23:25:02 (7 years ago)
Message:

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

File:
1 edited

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

 r563 def svg_generate_line_style(percent): # hotdog from_col = [100, 70, 0] to_col = [100, 0, 0] # from_col = [0, 100, 50] # to_col = [20, 0, 100] percent = 1 - ((1-percent)**10) to_col = [60, 0, 0] # neon # from_col = [30, 200, 255] # to_col = [240, 0, 220] from_opa = 0.2 to_opa = 1.0 from_stroke = 1 to_stroke = 3 opa = from_opa*(1-percent) + to_opa*percent stroke = from_stroke*(1-percent) + to_stroke*percent percent = 1 - ((1-percent)**20) return 'stroke="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \ + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \ + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="1" stroke-opacity="0.8"' + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="' + str(stroke) + '" stroke-opacity="' + str(opa) + '"' def svg_generate_dot_style(percent): from_col = [100, 90, 0] to_col = [100, 0, 0] # from_col = [0, 100, 50] # to_col = [20, 0, 100] percent = 1 - ((1-percent)**10) to_col = [60, 0, 0] # neon # from_col = [30, 200, 255] # to_col = [240, 0, 220] from_opa = 0.2 to_opa = 1.0 opa = from_opa*(1-percent) + to_opa*percent percent = 1 - ((1-percent)**20) return 'fill="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \ + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \ + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" r="1.5" stroke="black" stroke-width="0.2"' #fill-opacity="0.5"' + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" r="1.5" stroke="black" stroke-width="0.2" fill-opacity="' + str(opa) + '" ' \ 'stroke-opacity="' + str(opa) + '"' # ------------------- #print("B" +str(creature)) if "FromIDs" in creature: assert(len(creature["FromIDs"]) == 1) nodes[creature["ID"]] = creature["FromIDs"][0] if not creature["FromIDs"][0] in nodes: for c in inv_nodes[node]: #print(node + "->" + c) dissimilarity = random.gauss(0,0.3) dissimilarity = 0.5 #random.gauss(0,0.3) if TIME == "REAL": id = "" if c in inv_nodes: draw_children_recurrent(c, max_depth) line_style = (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth)) dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[c]/max_depth)) 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), (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_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth))) 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_dot_style if args.mono_tree else svg_generate_dot_style(depth[c]/max_depth))) (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) 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) def draw_children(): max_depth = 0 max_depth = max(max_depth, v) draw_children_recurrent(firstnode, max_depth) 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), (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[firstnode]/max_depth))) dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[firstnode]/max_depth)) 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) def draw_spine_recurrent(node): if c in inv_nodes: draw_spine_recurrent(c) line_style = svg_spine_line_style 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), (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) (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) #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) def draw_spine(): if c in inv_nodes: draw_skeleton_reccurent(c, max_depth) line_style = svg_spine_line_style 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), (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) (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) #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) #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), #             svg_spine_dot_style)
Note: See TracChangeset for help on using the changeset viewer.