Package visgraph :: Package layouts
[hide private]
[frames] | no frames]

Source Code for Package visgraph.layouts

 1  ''' 
 2  A package for each of the different layout managers. 
 3  ''' 
 4   
 5   
 6  # Some helper utils... 
7 -def exit_pos(ninfo):
8 x,y = ninfo.get('position') 9 xsize, ysize = ninfo.get('size', (0,0)) 10 return (x + xsize/2, y + ysize)
11
12 -def entry_pos(ninfo):
13 x,y = ninfo.get('position') 14 xsize, ysize = ninfo.get('size', (0,0)) 15 return (x + xsize/2, y)
16
17 -def center_pos(ninfo):
18 x,y = ninfo.get('position') 19 xsize, ysize = ninfo.get('size', (0,0)) 20 return (x + (xsize/2), y + (ysize/2))
21
22 -class GraphLayout:
23
24 - def __init__(self, graph):
25 self.graph = graph
26
27 - def layoutGraph(self):
28 ''' 29 Layout the graph nodes and edges 30 ''' 31 raise Exception('%s must implement layoutGraph()!' % self.__class__.__name__)
32
33 - def getLayoutSize(self):
34 raise Exception('%s must implement getLayoutSize()!' % self.__class__.__name__)
35
36 - def renderGraph(self, rend):
37 ''' 38 Render the graph to the given renderer. 39 ''' 40 rend.setNodeSizes(self.graph) 41 self.layoutGraph() 42 43 width, height = self.getLayoutSize() 44 rend.beginRender(width, height) 45 46 # Render each of the nodes (except ghost nodes...) 47 for nid,ninfo in self.graph.getNodes(): 48 if ninfo.get('ghost'): 49 continue 50 xpos, ypos = ninfo.get('position') 51 rend.renderNode(nid, ninfo, xpos, ypos) 52 53 # Render the edges 54 for eid, fromid, toid, einfo in self.graph.getEdges(): 55 points = einfo.get('edge_points') 56 if points != None: 57 rend.renderEdge(eid, einfo, points) 58 59 rend.endRender()
60