MCPcopy
hub / github.com/programthink/zhao / Graph

Class Graph

bin/make.py:126–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124
125
126class Graph :
127 def __init__(self, yaml) :
128 self._name = yaml[u'name']
129 self._families = yaml[u'families']
130 self._families.reverse()
131 self._nodes = []
132 self._relations = []
133 for f in self._families :
134 family = Family.all[f]
135 for n in family.members :
136 if n not in self._nodes :
137 self._nodes.append(n)
138 for r in Relation.keys :
139 relation = Relation.all[r]
140 if relation.node_from in family.members \
141 and relation.node_to in family.members \
142 and r not in self._relations :
143 self._relations.append(r)
144
145
146 def dump(self) :
147 output = StringIO()
148
149 for n in self._nodes :
150 output.write(self._dot_node(n))
151 output.write(u'\n')
152
153 for r in self._relations :
154 output.write(self._dot_relation(r))
155 output.write(u'\n')
156
157 if len(self._families) > 1 :
158 for f in self._families :
159 output.write(self._dot_sub_graph(f))
160
161 template = u'''
162digraph %s
163{
164\trankdir = "LR";
165\tranksep = 0.5;
166\tlabel = "%s";
167\tlabelloc = "t";
168\tfontsize = "24";
169\tfontname = "SimHei";
170
171\tgraph [style="filled", color="lightgrey"];
172\tnode [fontname="SimSun"];
173\tedge [fontname="SimSun"];
174
175%s
176}
177'''
178 return template % (self._name, self._name, output.getvalue())
179
180
181 def _node_color(self, node) :
182 if u'company' == node.type :
183 return u'green'

Callers 1

doMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected