Skip to content

Commit 48b9d5e

Browse files
committed
Added more info about adding links.
1 parent 7410a0c commit 48b9d5e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,71 @@ flowchart TD
6565
6666
```
6767

68+
You can also use `Node.CreateNew(...)` to automatically generate a GUID node ID, but being explicit about identifiers may make your diagrams more readable.
69+
You can also use the generic `Node.Create<TNodeText>` overload to specify the type of node text to be used.
70+
By default, using the non-generic overload uses Unicode (`MermaidUnicodeText`) but another option is Markdown (`MarkdownText`).
71+
72+
### Scope of adding links
73+
74+
You may only add links on a flowchart or a subgraph (more about them later) when both link nodes exist within the scope of the flowchart or the subgraph.
75+
If one of the nodes cannot be found inside the flowchart or subgraph or its nested descendants, then adding the link will fail.
76+
77+
#### Some examples
78+
79+
Adding a link with a newly defined node is technically allowed in Mermaid itself, but using `Mermaid.Net.Flowcharts` you must first add both nodes explicitly.
80+
81+
```cs
82+
Flowchart flowchart = new();
83+
Node a = Node.Create("a", "A");
84+
Node b = Node.Create("b", "B");
85+
Link ab = Link.Create(a, b);
86+
87+
flowchart
88+
.AddNode(a) // Add both a and b!
89+
.AddNode(b)
90+
.AddLink(ab);
91+
```
92+
93+
The correct output looks like this:
94+
95+
```diff
96+
flowchart TD
97+
a["A"]
98+
+ b["B"]
99+
a ---> b
100+
```
101+
102+
When defining links that connects a node to nested node, the link must be defined outside to ensure correctness.
103+
When a node from outside a subgraph is linked inside a subgraph, the node is incorrectly duplicated and treated as a node inside the subgraph.
104+
105+
```cs
106+
Flowchart flowchart = new();
107+
Node a = Node.Create("a", "A");
108+
Subgraph sg = Subgraph.Create("sg", "Subgraph");
109+
Node b = Node.Create("b", "B");
110+
Link ab = Link.Create(a, b);
111+
112+
flowchart
113+
.AddNode(a) // Add both a and sg!
114+
.AddNode(sg.AddNode(b)) // Add b to the subgraph!
115+
.AddLink(ab);
116+
```
117+
118+
The correct output looks like this:
119+
120+
```diff
121+
flowchart TD
122+
a["A"]
123+
124+
subgraph sg ["Subgraph"]
125+
b["B"]
126+
127+
- a ---> b
128+
end
129+
130+
+ a ---> b
131+
```
132+
68133
## Advanced features
69134

70135
### Node shapes

0 commit comments

Comments
 (0)