Skip to content

Commit

Permalink
set subgraph label in mermaid
Browse files Browse the repository at this point in the history
  • Loading branch information
emicklei committed Jul 22, 2024
1 parent 95cd1ec commit c2eeec0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mermaid.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func diagram(g *Graph, diagramType string, orientation int) string {
diagramGraph(g, sb)
for _, id := range g.sortedSubgraphsKeys() {
each := g.subgraphs[id]
fmt.Fprintf(sb, "subgraph %s;\n", id)
fmt.Fprintf(sb, "subgraph %s [%s];\n", id, each.attributes["label"])
diagramGraph(each, sb)
fmt.Fprintln(sb, "end;")
}
Expand Down
4 changes: 2 additions & 2 deletions mermaid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ func TestMermaidSubgraph(t *testing.T) {
sub1.Node("a1").Edge(sub1.Node("a2"))
sub2 := di.Subgraph("two")
sub2.Node("b1").Edge(sub2.Node("b2"))
sub3 := di.Subgraph("three")
sub3 := di.Subgraph("THREE").Label("three")
sub3.Node("c1").Edge(sub3.Node("c2"))

sub3.Node("c1").Edge(sub1.Node("a2"))
mf := MermaidFlowchart(di, MermaidLeftToRight)
if got, want := flatten(mf), `flowchart LR;n8-->n3;subgraph one;n2("a1");n3("a2");n2-->n3;end;subgraph three;n8("c1");n9("c2");n8-->n9;end;subgraph two;n5("b1");n6("b2");n5-->n6;end;`; got != want {
if got, want := flatten(mf), `flowchart LR;n8-->n3;subgraph THREE [three];n8("c1");n9("c2");n8-->n9;end;subgraph one [one];n2("a1");n3("a2");n2-->n3;end;subgraph two [two];n5("b1");n6("b2");n5-->n6;end;`; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
}

0 comments on commit c2eeec0

Please sign in to comment.