Skip to content

Commit f68fd87

Browse files
committed
fix parsing cluster subgraph (fix #112)
Signed-off-by: Stefan Niederhauser <[email protected]>
1 parent 239d37a commit f68fd87

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

graphviz-java/src/main/java/guru/nidi/graphviz/parse/Parser.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ private MutableGraph subgraph(boolean directed) {
131131
if (token.type == SUBGRAPH) {
132132
nextToken();
133133
if (token.type == ID) {
134-
sub.setName(label(token).toString());
134+
final String name = label(token).toString();
135+
if (name.startsWith("cluster_")) {
136+
sub.setName(name.substring(8));
137+
sub.setCluster(true);
138+
} else {
139+
sub.setName(name);
140+
}
135141
nextToken();
136142
}
137143
}

graphviz-java/src/test/java/guru/nidi/graphviz/parse/ParserTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,10 @@ void multiLinkAttr() throws IOException {
135135
assertEquals(mutGraph().add(a, b),
136136
Parser.read("graph { edge[color=red, width=1] a -- b edge[color=blue, a=b] a -- b }"));
137137
}
138+
139+
@Test
140+
void cluster() throws IOException {
141+
assertEquals(mutGraph().add(mutGraph("sub").setCluster(true)),
142+
Parser.read("graph { subgraph cluster_sub {} }"));
143+
}
138144
}

0 commit comments

Comments
 (0)