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 tcNode = cNode + children[0]
65 if cNodes.has_key(cNode):
66 if not has_node(tcNode):
67 if len(cNodes[cNode])>0:
68 last = cNodes[cNode][-1]
70 cNodes[cNode].append(tcNode)
71 add_no_arrow(last,tcNode)
72 add_subgraph([tcNode,last])
75 cNodes[cNode] = [tcNode]
76 add_no_arrow(jN,tcNode)
86 add_edge(n,jN,marriage_attr)
90 def add_subgraph(myG):
97 line = "\n{rank=same "
100 line = line +add_quotes(n) + ' '
120 dot = dot + "ranksep = 0.5 nodesep = 0\n"
124 def add_highlight(name):
125 add_node(name,highlight_attr)
127 def add_person(name):
128 add_node(name,person_attr)
131 add_node(name,spot_attr)
136 global highlight_attr
144 global debug_edge_attr
145 zero_size = [('width','0'),('height','0')]
146 person_attr = [('fontsize',str(fs)),('shape','plaintext')] + zero_size
147 highlight_attr = person_attr + \
148 [('fontcolor','red'),('shape','box'),('color','red')]
149 debug_attr = person_attr + [('fontcolor','green')]
150 spot_attr = [('shape','point')] + zero_size
151 edge_attr = [('len','0'),('arrowsize','0.5')]
152 debug_edge_attr = edge_attr + [('color','green')]
153 invis_attr = edge_attr + [('style','invis')]
154 nodir_attr = edge_attr + [('dir','none')]
155 marriage_attr = nodir_attr + [('weight','10'),('color','red')]
156 ignored_attr =edge_attr + [('constraint','false')] + nodir_attr
158 def attr_string(attr):
162 attr_str = attr_str + a[0] + '=' + a[1]
164 attr_str = attr_str +','
166 attr_str = attr_str + ']'
170 gvv = gv.readstring(dot)
175 print "Content-type: image/" + format + "\n"
176 print gv.render(gvv,format)