Skip to content

Commit 4c0e6f9

Browse files
committed
add link attribute for mermaid
1 parent c2eeec0 commit 4c0e6f9

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ fmt.Println(dot.MermaidGraph(g, dot.MermaidTopToBottom))
125125
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;
126126
```
127127

128+
### mermaid specific attributes
129+
130+
|attr|type|description|
131+
|----|----|-----------|
132+
|link|Edge|examples are {-->,-.->,--x,o--o}|
133+
|shape|Node|examples are {MermaidShapeRound,MermaidShapeCircle,MermaidShapeTrapezoid}
134+
|style|Node|example is fill:#90EE90|
135+
128136
## extensions
129137

130138
See also package `dot/dotx` for types that can help in constructing complex graphs.

mermaid.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ const (
1515
)
1616

1717
var (
18-
MermaidShapeRound = shape{"(", ")"}
19-
MermaidShapeStadium = shape{"([", "])"}
20-
MermaidShapeSubroutine = shape{"[[", "]]"}
21-
MermaidShapeCylinder = shape{"[(", ")]"}
22-
MermaidShapeCirle = shape{"((", "))"} // Deprecated: use MermaidShapeCircle instead
23-
MermaidShapeCircle = shape{"((", "))"}
24-
MermaidShapeAsymmetric = shape{">", "]"}
25-
MermaidShapeRhombus = shape{"{", "}"}
26-
MermaidShapeTrapezoid = shape{"[/", "\\]"}
27-
MermaidShapeTrapezoidAlt = shape{"[\\", "/]"}
18+
MermaidShapeRound = shape{"(", ")"}
19+
MermaidShapeStadium = shape{"([", "])"}
20+
MermaidShapeSubroutine = shape{"[[", "]]"}
21+
MermaidShapeCylinder = shape{"[(", ")]"}
22+
MermaidShapeCirle = shape{"((", "))"} // Deprecated: use MermaidShapeCircle instead
23+
MermaidShapeCircle = shape{"((", "))"}
24+
MermaidShapeAsymmetric = shape{">", "]"}
25+
MermaidShapeRhombus = shape{"{", "}"}
26+
MermaidShapeTrapezoid = shape{"[/", "\\]"}
27+
MermaidShapeTrapezoidAlt = shape{"[\\", "/]"}
28+
MermaidShapeHexagon = shape{"[{{", "}}]"}
29+
MermaidShapeParallelogram = shape{"[/", "/]"}
30+
MermaidShapeParallelogramAlt = shape{"[\\", "\\]"}
31+
// TODO more shapes see https://mermaid.js.org/syntax/flowchart.html#node-shapes
2832
)
2933

3034
type shape struct {
@@ -96,10 +100,15 @@ func diagramGraph(g *Graph, sb *strings.Builder) {
96100
for _, each := range g.sortedEdgesFromKeys() {
97101
all := g.edgesFrom[each]
98102
for _, each := range all {
103+
// The edge can override the link style
104+
link := denoteEdge
105+
if l := each.GetAttr("link"); l != nil {
106+
link = l.(string)
107+
}
99108
if label := each.GetAttr("label"); label != nil {
100-
fmt.Fprintf(sb, "\tn%d%s|%s|n%d;\n", each.from.seq, denoteEdge, escape(label.(string)), each.to.seq)
109+
fmt.Fprintf(sb, "\tn%d%s|%s|n%d;\n", each.from.seq, link, escape(label.(string)), each.to.seq)
101110
} else {
102-
fmt.Fprintf(sb, "\tn%d%sn%d;\n", each.from.seq, denoteEdge, each.to.seq)
111+
fmt.Fprintf(sb, "\tn%d%sn%d;\n", each.from.seq, link, each.to.seq)
103112
}
104113
}
105114
}

0 commit comments

Comments
 (0)