This library aims to provide a simple and expressive way to create D2 templates that can be easily integrated into any .NET application. Enabling easy generation of diagrams for documentation, reports, and more based off of data from your application.
Currently this library is in early development and not all D2 features are supported, see below for a high level list of supported features.
- Shapes
- Labels
- Containers / Children
- Styling
- Connections
- Labels
- Arrow Styling/Directions
- Styling
- Tooltips / Links
- Icons
- Standalone Text / Markdown / LateX
- Sequence Diagrams
- UML/Class Diagrams
- SQL Table Diagrams
D2.Net is available on NuGet.
dotnet add package D2.Net
Here is an example of creating a fairly complex template using D2.Net with most of the implemented features.
You can check Examples to see this and a more basic setup.
using D2;
var styledTemplate = Diagram.Create()
.CreateShape("D", type: ShapeType.Circle)
.CreateShape("E", "Styled Shape", ShapeType.Hexagon)
.CreateShape("F", "Styled Diamond Shape", ShapeType.Diamond)
.CreateDirectionalConnection("D", "E", "Styled Connection", new ArrowheadOptions(ArrowheadType.CrowsFootManyRequired, "Filled Triangle"))
.CreateBidirectionalConnection("E", "F", "Bidirectional Connection",
new ArrowheadOptions(ArrowheadType.CrowsFootManyRequired),
new ArrowheadOptions(ArrowheadType.CrowsFootManyRequired))
.CreateConnection("F", "D")
.CreateMarkdownShape("G", @" # I can do headers
- lists
- lists
And other normal markdown stuff")
.CreateLatexShape("H", @"\\lim_{h \\rightarrow 0 } \\frac{f(x+h)-f(x)}{h}")
.CreateBidirectionalConnection("G", "H");
Console.WriteLine(styledTemplate);
This will output the following D2 code:
D: {
shape: circle
}
E: Styled Shape {
shape: hexagon
}
F: Styled Diamond Shape {
shape: diamond
}
D -> E: Styled Connection {
target-arrowhead: Filled Triangle { shape: cf-many-required; style.filled: true }
}
E <-> F: Bidirectional Connection {
source-arrowhead: { shape: cf-many-required; style.filled: true }
target-arrowhead: { shape: cf-many-required; style.filled: true }
}
F -> D
G: |md
# I can do headers
- lists
- lists
And other normal markdown stuff|
H: |latex
\\lim_{h \\rightarrow 0 } \\frac{f(x+h)-f(x)}{h}|
G <-> H: Bidirectional Connection {
source-arrowhead: { shape: cf-many-required; style.filled: true }
target-arrowhead: { shape: cf-many-required; style.filled: true }
}
That is rendered to the following diagram, using the D2 Playground!