Browse code

Associate nodes to edges.

From: Marius Gedminas <marius@gedmin.as>

Jose.R.Fonseca authored on 13/07/2008 03:22:08
Showing 1 changed files

  • xdot.py index 0418427..a868499 100755
... ...
@@ -346,9 +346,10 @@ def square_distance(x1, y1, x2, y2):
346 346
 
347 347
 class Edge(Element):
348 348
 
349
-    def __init__(self, points, shapes):
349
+    def __init__(self, src, dst, points, shapes):
350 350
         Element.__init__(self, shapes)
351
-
351
+        self.src = src
352
+        self.dst = dst
352 353
         self.points = points
353 354
 
354 355
     RADIUS = 10
... ...
@@ -577,6 +578,7 @@ class XDotParser:
577 578
 
578 579
         nodes = []
579 580
         edges = []
581
+        node_by_name = {}
580 582
 
581 583
         for node in graph.get_node_list():
582 584
             if node.pos is None:
... ...
@@ -590,8 +592,11 @@ class XDotParser:
590 592
                     parser = XDotAttrParser(self, getattr(node, attr))
591 593
                     shapes.extend(parser.parse())
592 594
             url = node.URL
595
+            my_node = Node(x, y, w, h, shapes, url)
596
+            node_name = node.get_name().strip('"') # XXX
597
+            node_by_name[node_name] = my_node
593 598
             if shapes:
594
-                nodes.append(Node(x, y, w, h, shapes, url))
599
+                nodes.append(my_node)
595 600
 
596 601
         for edge in graph.get_edge_list():
597 602
             if edge.pos is None:
... ...
@@ -603,7 +608,9 @@ class XDotParser:
603 608
                     parser = XDotAttrParser(self, getattr(edge, attr))
604 609
                     shapes.extend(parser.parse())
605 610
             if shapes:
606
-                edges.append(Edge(points, shapes))
611
+                src = node_by_name[edge.get_source()]
612
+                dst = node_by_name[edge.get_destination()]
613
+                edges.append(Edge(src, dst, points, shapes))
607 614
 
608 615
         return Graph(width, height, nodes, edges)
609 616