Browse code

Ignore empty nodes, when a proper node already exists.

As suggested by notEvil.

Fixes https://github.com/jrfonseca/xdot.py/issues/94

Jose Fonseca authored on 04/09/2021 09:14:04
Showing 2 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+digraph {
2
+  {
3
+    node [ shape=box ]
4
+    a
5
+    b
6
+  }
7
+  {
8
+    a -> b
9
+  }
10
+}
... ...
@@ -488,11 +488,12 @@ class XDotParser(DotParser):
488 488
             pos = attrs['pos']
489 489
         except KeyError:
490 490
             # Node without pos attribute, most likely a subgraph.  We need to
491
-            # create a Node object nevertheless, so that any edges to/from it
492
-            # don't get lost.
493
-            # TODO: Extract the position from subgraph > graph > bb attribute.
494
-            node = elements.Node(id, 0.0, 0.0, 0.0, 0.0, [], None, None)
495
-            self.node_by_name[id] = node
491
+            # create a Node object nevertheless, when one doesn't exist
492
+            # already, so that any edges to/from it don't get lost.
493
+            if id not in self.node_by_name:
494
+                # TODO: Extract the position from subgraph > graph > bb attribute.
495
+                node = elements.Node(id, 0.0, 0.0, 0.0, 0.0, [], None, None)
496
+                self.node_by_name[id] = node
496 497
             return
497 498
 
498 499
         x, y = self.parse_node_pos(pos)