def compute(self, objectlist): assert objectlist[0] is MARKER self.objectlist = objectlist dotgen = DotGen('reftracker') id2typename = {} nodes = {} edges = {} def addedge(o1, o2): key = (uid(o1), uid(o2)) edges[key] = self.edgelabel(o1, o2) for i in range(1, len(objectlist)): typename, s, linktext = self.formatobject(objectlist[i]) word = '0x%x' % uid(objectlist[i]) if linktext: self.links[word] = linktext s = '<%s> %s\\n%s' % (typename, word, s) nodename = 'node%d' % len(nodes) dotgen.emit_node(nodename, label=s, shape="box") nodes[uid(objectlist[i])] = nodename for o2 in self.get_referents(objectlist[i]): if o2 is None: continue addedge(objectlist[i], o2) id2typename[uid(o2)] = self.shortrepr(o2) del o2 for o2 in self.get_referrers(objectlist[i]): if o2 is None: continue if type(o2) is list and o2 and o2[0] is MARKER: continue addedge(o2, objectlist[i]) id2typename[uid(o2)] = self.shortrepr(o2) del o2 for ids, label in edges.items(): for id1 in ids: if id1 not in nodes: nodename = 'node%d' % len(nodes) word = '0x%x' % id1 s = '<%s> %s' % (id2typename[id1], word) dotgen.emit_node(nodename, label=s) nodes[id1] = nodename self.links[word] = s id1, id2 = ids dotgen.emit_edge(nodes[id1], nodes[id2], label=label) self.source = dotgen.generate(target=None)
def compute(self): dotgen = DotGen('mathgraph') names = {} for i, v in enumerate(vertices): names[v] = 'node%d' % i for i, v in enumerate(vertices): dotgen.emit_node(names[v], label=str(v)) for edge in edges[v]: dotgen.emit_edge(names[edge.source], names[edge.target]) self.source = dotgen.generate(target=None)