Skip to content

Commit df55e08

Browse files
authored
Update README.md
1 parent 17d4cc5 commit df55e08

File tree

1 file changed

+55
-26
lines changed

1 file changed

+55
-26
lines changed

README.md

+55-26
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ Currently this library is in early development and not all D2 features are suppo
2929
- [x] Shapes
3030
- [x] Labels
3131
- [x] Containers / Children
32-
- [ ] Styling
32+
- [x] Styling
3333
- [x] Connections
3434
- [x] Labels
3535
- [x] Arrow Styling/Directions
3636
- [ ] Styling
3737
- [ ] Tooltips / Links
38-
- [ ] Icons
39-
- [ ] Standalone Text / Markdown / LateX
38+
- [x] Icons
39+
- [x] Standalone Text / Markdown / LateX
4040
- [ ] Sequence Diagrams
4141
- [ ] UML/Class Diagrams
4242
- [ ] SQL Table Diagrams
@@ -51,38 +51,67 @@ dotnet add package D2.Net
5151

5252
## Usage
5353

54-
Here is an example of creating a basic template using D2.Net.
54+
Here is an example of creating a fairly complex template using D2.Net with most of the implemented features.
55+
56+
You can check Examples to see this and a more basic setup.
5557

5658
```csharp
5759
using D2;
5860

59-
var A = new Shape("A", "Starting Point");
60-
var B = new Shape("B", "Ending Point");
61-
var C = new Shape("C", "Middle Point", ShapeType.Hexagon);
62-
63-
var basicTemplate = Diagram.Create()
64-
.Add(A)
65-
.Add(B)
66-
.Add(C)
67-
.Add(new Connection(A, C))
68-
.Add(new Connection(C, B, "Hello World!"));
69-
70-
// Each component overrides ToString() to return the D2 code for that instance
71-
Console.WriteLine(basicTemplate);
72-
// or you can use the Render() method
73-
Console.WriteLine(basicTemplate.Render());
74-
61+
var styledTemplate = Diagram.Create()
62+
.CreateShape("D", type: ShapeType.Circle)
63+
.CreateShape("E", "Styled Shape", ShapeType.Hexagon)
64+
.CreateShape("F", "Styled Diamond Shape", ShapeType.Diamond)
65+
.CreateDirectionalConnection("D", "E", "Styled Connection", new ArrowheadOptions(ArrowheadType.CrowsFootManyRequired, "Filled Triangle"))
66+
.CreateBidirectionalConnection("E", "F", "Bidirectional Connection",
67+
new ArrowheadOptions(ArrowheadType.CrowsFootManyRequired),
68+
new ArrowheadOptions(ArrowheadType.CrowsFootManyRequired))
69+
.CreateConnection("F", "D")
70+
.CreateMarkdownShape("G", @" # I can do headers
71+
72+
- lists
73+
- lists
74+
75+
And other normal markdown stuff")
76+
.CreateLatexShape("H", @"\\lim_{h \\rightarrow 0 } \\frac{f(x+h)-f(x)}{h}")
77+
.CreateBidirectionalConnection("G", "H");
78+
79+
Console.WriteLine(styledTemplate);
7580
```
7681
This will output the following D2 code:
7782

7883
```d2
79-
A: Starting Point
80-
B: Ending Point
81-
C: Middle Point {
84+
D: {
85+
shape: circle
86+
}
87+
E: Styled Shape {
8288
shape: hexagon
8389
}
84-
A -> C
85-
C -> B: Hello World!
90+
F: Styled Diamond Shape {
91+
shape: diamond
92+
}
93+
D -> E: Styled Connection {
94+
target-arrowhead: Filled Triangle { shape: cf-many-required; style.filled: true }
95+
}
96+
E <-> F: Bidirectional Connection {
97+
source-arrowhead: { shape: cf-many-required; style.filled: true }
98+
target-arrowhead: { shape: cf-many-required; style.filled: true }
99+
}
100+
F -> D
101+
G: |md
102+
# I can do headers
103+
104+
- lists
105+
- lists
106+
107+
And other normal markdown stuff|
108+
H: |latex
109+
\\lim_{h \\rightarrow 0 } \\frac{f(x+h)-f(x)}{h}|
110+
G <-> H: Bidirectional Connection {
111+
source-arrowhead: { shape: cf-many-required; style.filled: true }
112+
target-arrowhead: { shape: cf-many-required; style.filled: true }
113+
}
114+
86115
```
87116
That is rendered to the following diagram, using the [D2 Playground](https://play.d2lang.com/?script=crRSCC5JLCrJzEtXCMjPzCvhcrJScM1LQfCdrRR8M1NSclIhfIVqLgUFBYXijMSCVCuFjNSKxPT8PK5aLkcFXTsFZy5nEOVkpeCRmpOTrxCeX5STosgFCAAA__8%3D&)!
88-
![Basic Template](./assets/d2-readme.png)
117+
![Basic Template](./assets/d2-readme.png)

0 commit comments

Comments
 (0)