8 sys.path.append('/home/naath/familyTreeProject/familyTree')
9 import askQuestion as aQ
10 import englishUtils as eU
14 return '\"'+str(s)+'\"'
16 def add_node(node,node_attr):
17 na = attr_string(node_attr)
18 if not has_node(node):
20 elif node_attr[-2][1]==highlight_attr[0][1]:
24 if node in nodes.keys():
29 edge[0] = add_quotes(edge[0])
30 edge[1] = add_quotes(edge[1])
31 if edge in edges.keys():
36 def add_edge(n1,n2,edge_attr):
37 edge = (add_quotes(n1),add_quotes(n2))
38 edge_attr = attr_string(edge_attr)
39 if edge not in edges.keys():
40 edges[edge] = 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):
60 if len(children)>0 and joinChildren==1:
62 tcNode = cNode + children[0]
64 if cNodes.has_key(cNode):
65 if not has_node(tcNode):
66 if len(cNodes[cNode])>0:
67 last = cNodes[cNode][-1]
69 cNodes[cNode].append(tcNode)
70 add_no_arrow(last,tcNode)
71 add_subgraph([tcNode,last])
74 cNodes[cNode] = [tcNode]
75 add_no_arrow(jN,tcNode)
88 id1 = int(n1.split(',')[-1])
89 id2 = int(n2.split(',')[-1])
91 m = aQ.is_married(id1,id2)
97 add_edge(n,jN,marriage_attr)
99 add_edge(n,jN,not_marriage_attr)
100 add_subgraph([n1,n2])
103 def add_subgraph(myG):
105 if myG not in subgraphs:
106 subgraphs.append(myG)
120 dot = dot + "ranksep = 0.2 nodesep = 0.1\n"
127 for node in nodes.keys():
128 dot +=add_quotes(node) + nodes[node] + ";\n"
130 for edge in edges.keys():
131 dot += edge[0] + ' -> ' + edge[1] + edges[edge] + ";\n"
136 line = "\n{rank=same "
139 line +=add_quotes(n) + ' '
150 def arrange_name(name):
152 ln = name.replace(' ',' ')
153 ln = ln.replace(', ','\\n')
154 ln = ln.replace(',','\\n')
155 ln = ln.replace(' ','\\n')
159 def add_highlight(name):
165 myLabel =str(arrange_name(name))
168 add_node(name,king_attr+[('label',myLabel)]+highlight_attr)
170 add_node(name,person_attr+[('label',myLabel)]+highlight_attr)
172 def add_person(name):
177 myLabel = str(arrange_name(name))
180 add_node(name,king_attr+[('label',myLabel)])
182 add_node(name,person_attr+[('label',myLabel)])
185 add_node(name,spot_attr)
190 global highlight_attr
198 global not_marriage_attr
200 global debug_edge_attr
201 zero_size = [('width','0'),('height','0'),('fontsize',str(fs))]
202 person_attr = [('shape','plaintext'),('margin','0')] +\
204 highlight_attr = [('fillcolor','yellow'),('style','filled,bold')]
205 king_attr = person_attr +\
206 [('fontcolor','purple4'),('shape','house'),('color','purple4')]
207 debug_attr = person_attr + [('fontcolor','green')]
208 spot_attr = [('shape','point')] + zero_size
209 edge_attr = [('len','0'),('arrowsize','0.5')]
210 debug_edge_attr = edge_attr + [('color','green')]
211 invis_attr = edge_attr + [('style','invis')]
212 nodir_attr = edge_attr + [('dir','none')]
213 marriage_attr = nodir_attr + [('weight','10'),('color','red')]
214 not_marriage_attr = nodir_attr+[('weight','10'),('color','blue')]
215 ignored_attr =edge_attr + [('constraint','false')] + nodir_attr
217 def attr_string(attr):
221 attr_str = attr_str + a[0] + '="' + a[1]+'"'
223 attr_str = attr_str +','
225 attr_str = attr_str + ']'
230 f = open('tempfile','w')
234 gvv = gv.readstring(dot)
239 print "Content-type: image/" + format + "\n"
240 print gv.render(gvv,format)
243 def render_to_file(file):
244 f = open('/home/naath/familyTreeProject/cgiFiles/biggraphfile','w')
247 gvv = gv.readstring(dot)
250 gv.render(gvv,format,file)