def __iter__(self): cur = gv.firstedge(self.parent.handle) while gv.ok(cur): yield (decode_page(gv.nameof(gv.tailof(cur))), decode_page(gv.nameof(gv.headof(cur)))), \ dict(self.graph._iterattrs(cur)) cur = gv.nextedge(self.parent.handle, cur)
def generate(self, filename): ''' Displays the graph on the canvas Uses python-igraph fruchterman-reingold algorithm to decide about position of the nodes, then draw these nodes on the canvas and draw connections between them Author: Jan Vorcak <*****@*****.**> ''' g = gv.readstring(self.source) gv.layout(g, 'dot') gv.render(g) context = CanvasContext().dictionary node = gv.firstnode(g) while node is not None: props = { 'filepath' : gv.getv(node, 'filepath'), 'title' : gv.getv(node, 'label'), 'lineno' : gv.getv(node, 'lineno'), } pos = gv.getv(node, 'pos').split(',') width = gv.getv(node, 'width') height = gv.getv(node, 'height') x, y = map(int, pos) class_box = ClassBox(props, width, height) class_box.matrix.translate(x, y) self.view.canvas.add(class_box) context[(props['filepath'], props['title'])] = class_box node = gv.nextnode(g, node) edge = gv.firstedge(g) while edge is not None: props = { 'arrowhead' : gv.getv(edge, 'arrowhead'), 'arrowtail' : gv.getv(edge, 'arrowtail'), } head = gv.headof(edge) tail = gv.tailof(edge) head_str = (gv.getv(head, 'filepath'), gv.getv(head, 'label')) tail_str = (gv.getv(tail, 'filepath'), gv.getv(tail, 'label')) context[head_str] context[tail_str] edge = gv.nextedge(g, edge) set_association(self.view.canvas, context[head_str], \ context[tail_str], props)
def main(): # create a new empty graph G = gv.digraph('G') # define a simple graph ( A->B ) gv.edge(gv.node(G, 'A'), gv.node(G, 'B')) # compute a directed graph layout gv.layout(G, 'dot') # annotate the graph with the layout information gv.render(G) # do something with the layout n = gv.firstnode(G) while n: print 'node ' + gv.nameof(n) + ' is at ' + gv.getv(n, 'pos') e = gv.firstout(n) while e: print 'edge ' + gv.nameof(gv.tailof(e)) + '->' + gv.nameof( gv.headof(e)) + ' is at ' + gv.getv(e, 'pos') e = gv.nextout(n, e) n = gv.nextnode(G, n)
def tail(self): handle = gv.tailof(self.handle) if handle is None: return None else: return Node(handle)
#!/usr/bin/python import sys import gv # create a new empty graph G = gv.digraph('G') # define a simple graph ( A->B ) gv.edge(gv.node(G, 'A'), gv.node(G, 'B')) # compute a directed graph layout gv.layout(G, 'dot') # annotate the graph with the layout information gv.render(G) # do something with the layout n = gv.firstnode(G) while n: print 'node ' + gv.nameof(n) + ' is at ' + gv.getv(n, 'pos') e = gv.firstout(n) while e: print 'edge ' + gv.nameof(gv.tailof(e)) + '->' + gv.nameof( gv.headof(e)) + ' is at ' + gv.getv(e, 'pos') e = gv.nextout(n, e) n = gv.nextnode(G, n)
def __str__(self): return "(u'" + decode_page(gv.nameof(gv.tailof(self.handle))) + \ "', u'" + decode_page(gv.nameof(gv.headof(self.handle))) + "')"
#!/usr/bin/python import sys import gv # create a new empty graph G = gv.digraph('G') # define a simple graph ( A->B ) gv.edge(gv.node(G, 'A'),gv.node(G, 'B')) # compute a directed graph layout gv.layout(G, 'dot') # annotate the graph with the layout information gv.render(G) # do something with the layout n = gv.firstnode(G) while n : print 'node '+gv.nameof(n)+' is at '+gv.getv(n,'pos') e = gv.firstout(n) while e : print 'edge '+gv.nameof(gv.tailof(e))+'->'+gv.nameof(gv.headof(e))+' is at '+gv.getv(e,'pos') e = gv.nextout(n,e) n = gv.nextnode(G,n)