Skip to content

Commit f14a9e9

Browse files
authored
Merge pull request #67 from JansthcirlU:66-prep-release-400-due-to-breaking-changes
66-prep-release-400-due-to-breaking-changes
2 parents 841dfcd + 48b9d5e commit f14a9e9

File tree

4 files changed

+414
-13
lines changed

4 files changed

+414
-13
lines changed

README.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Node process = Node.Create("process", "Process Data");
3434
Node stop = Node.Create("stop", "Stop");
3535

3636
// Create links
37-
Link startToProcess = new(start, process, default);
38-
Link processToEnd = new(process, stop, default);
37+
Link startToProcess = Link.Create(start, process, default);
38+
Link processToEnd = Link.Create(process, stop, default);
3939

4040
// Add nodes and links to the flowchart
4141
flowchart
@@ -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
@@ -353,8 +418,8 @@ StyleClass linkStyleClass = new(
353418
StrokeWidth: StrokeWidth.Length(2, Unit.Px));
354419

355420
// Create some links
356-
Link ab = Link.Create(a, b, linkStyle: linkeStyleClass);
357-
Link bc = Link.Create(b, c, linkStyle: linkeStyleClass);
421+
Link ab = Link.Create(a, b, linkStyle: linkStyleClass);
422+
Link bc = Link.Create(b, c, linkStyle: linkStyleClass);
358423

359424
// Add the nodes and links to the flowchart
360425
flowchart

src/Mermaid.Flowcharts/FlowchartTitle.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Text;
2+
13
namespace Mermaid.Flowcharts;
24

35
public readonly struct FlowchartTitle : IMermaidPrintable
@@ -30,17 +32,19 @@ public static FlowchartTitle FromString(string text)
3032
throw new ArgumentException("Flowchart title must not be whitespace.", nameof(text));
3133
}
3234

33-
return new(
34-
$"""
35-
---
36-
title: {text}
37-
---
38-
""");
35+
return new(text);
3936
}
4037

4138
public override string ToString()
4239
=> ToMermaidString();
4340

4441
public string ToMermaidString(int indentations = 0, string indentationText = " ")
45-
=> $"{indentationText.Repeat(indentations)}{Text.Replace("\n", $"\n{indentationText.Repeat(indentations)}")}";
42+
{
43+
StringBuilder flowchartTitleBuilder = new();
44+
flowchartTitleBuilder
45+
.AppendLine($"{indentationText.Repeat(indentations)}---")
46+
.AppendLine($"{indentationText.Repeat(indentations)}title: {Text}")
47+
.Append($"{indentationText.Repeat(indentations)}---");
48+
return flowchartTitleBuilder.ToString();
49+
}
4650
}

src/Mermaid.Flowcharts/Mermaid.Flowcharts.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<PropertyGroup>
1111
<PackageId>Mermaid.NET.Flowcharts</PackageId>
12-
<Version>3.1.0</Version>
12+
<Version>4.0.0</Version>
1313
<Authors>Jan Ulrichts</Authors>
1414
<Company>Ulrichts</Company>
1515
<Product>Mermaid Flowchart Library</Product>
@@ -23,7 +23,7 @@
2323
<IncludeSymbols>true</IncludeSymbols>
2424
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2525
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
26-
<PackageReleaseNotes>https://github.com/JansthcirlU/Mermaid.NET.Flowcharts/releases/tag/3.1.0</PackageReleaseNotes>
26+
<PackageReleaseNotes>https://github.com/JansthcirlU/Mermaid.NET.Flowcharts/releases/tag/4.0.0</PackageReleaseNotes>
2727
</PropertyGroup>
2828

2929
<ItemGroup>

0 commit comments

Comments
 (0)