10 return '\"'+str(s)+'\"'
12 def add_node(node,node_attr):
15 node_attr = attr_string(node_attr)
17 dot = dot + add_quotes(node) + node_attr + ";\n"
26 edge[0] = add_quotes(edge[0])
27 edge[1] = add_quotes(edge[1])
33 def add_edge(n1,n2,edge_attr):
36 edge = (add_quotes(n1),add_quotes(n2))
37 edge_attr = attr_string(edge_attr)
39 dot = dot + edge[0] + ' -> ' + edge[1] + edge_attr + ";"
43 add_edge(n1,n2,edge_attr)
45 def add_no_arrow(n1,n2):
46 add_edge(n1,n2,nodir_attr)
48 def add_marriage(n1,n2,children,joinChildren):
61 if len(children)>0 and joinChildren==1:
63 e = [cNode,children[0]]
65 tcNode = cNode + children[0]
66 if len(cNodes[cNode])>0:
67 last = cNodes[cNode][-1]
71 cNodes[cNode].append(tcNode)
72 add_no_arrow(last,tcNode)
73 add_subgraph([tcNode,cNode])
78 add_no_arrow(jN,cNode)
87 add_edge(n,jN,marriage_attr)
91 def add_subgraph(myG):
98 line = "\n{rank=same "
101 line = line +add_quotes(n) + ' '
121 dot = dot + "ranksep = 0.5 nodesep = 0\n"
125 def add_highlight(name):
126 add_node(name,highlight_attr)
128 def add_person(name):
129 add_node(name,person_attr)
132 add_node(name,spot_attr)
137 global highlight_attr
145 global debug_edge_attr
146 zero_size = [('width','0'),('height','0')]
147 person_attr = [('fontsize','8'),('shape','plaintext')] + zero_size
148 highlight_attr = person_attr + \
149 [('fontcolor','red'),('shape','box'),('color','red')]
150 debug_attr = person_attr + [('fontcolor','green')]
151 spot_attr = [('shape','point')] + zero_size
152 edge_attr = [('len','0'),('arrowsize','0.5')]
153 debug_edge_attr = edge_attr + [('color','green')]
154 invis_attr = edge_attr + [('style','invis')]
155 nodir_attr = edge_attr + [('dir','none')]
156 marriage_attr = nodir_attr + [('weight','10'),('color','red')]
157 ignored_attr =edge_attr + [('constraint','false')] + nodir_attr
159 def attr_string(attr):
163 attr_str = attr_str + a[0] + '=' + a[1]
165 attr_str = attr_str +','
167 attr_str = attr_str + ']'
171 gvv = gv.readstring(dot)
176 print "Content-type: image/" + format + "\n"
177 print gv.render(gvv,format)