In particular, don't lose edges to/from subgraphs.
Fixes https://github.com/jrfonseca/xdot.py/issues/65
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,8 @@ |
| 1 |
+graph {
|
|
| 2 |
+ graph [layout=fdp] |
|
| 3 |
+ subgraph cluster_d2dd739afc71e4eabc8b572ae98ca5e9 {}
|
|
| 4 |
+ node_0831ce381fb8a3782996a1d40cf8935d |
|
| 5 |
+ node_166562e3c47ae9436f911047fb660528 |
|
| 6 |
+ cluster_d2dd739afc71e4eabc8b572ae98ca5e9 -- node_166562e3c47ae9436f911047fb660528 |
|
| 7 |
+ cluster_d2dd739afc71e4eabc8b572ae98ca5e9 -- node_0831ce381fb8a3782996a1d40cf8935d |
|
| 8 |
+} |
| ... | ... |
@@ -325,6 +325,8 @@ class DotParser(Parser): |
| 325 | 325 |
if self.lookahead.type == ID: |
| 326 | 326 |
id = self.lookahead.text |
| 327 | 327 |
self.consume() |
| 328 |
+ # A subgraph is also a node. |
|
| 329 |
+ self.handle_node(id, {})
|
|
| 328 | 330 |
if self.lookahead.type == LCURLY: |
| 329 | 331 |
self.consume() |
| 330 | 332 |
while self.lookahead.type != RCURLY: |
| ... | ... |
@@ -477,6 +479,12 @@ class XDotParser(DotParser): |
| 477 | 479 |
try: |
| 478 | 480 |
pos = attrs['pos'] |
| 479 | 481 |
except KeyError: |
| 482 |
+ # Node without pos attribute, most likely a subgraph. We need to |
|
| 483 |
+ # create a Node object nevertheless, so that any edges to/from it |
|
| 484 |
+ # don't get lost. |
|
| 485 |
+ # TODO: Extract the position from subgraph > graph > bb attribute. |
|
| 486 |
+ node = elements.Node(id, 0.0, 0.0, 0.0, 0.0, [], None) |
|
| 487 |
+ self.node_by_name[id] = node |
|
| 480 | 488 |
return |
| 481 | 489 |
|
| 482 | 490 |
x, y = self.parse_node_pos(pos) |