-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diagram.cs
98 lines (82 loc) · 3 KB
/
Diagram.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Text;
using D2.Enums;
using D2.Interfaces;
namespace D2
{
public class Diagram : IRenderable
{
private readonly List<IRenderable> _renderables = new List<IRenderable>();
public static Diagram Create() => new Diagram();
public Diagram Add(IRenderable renderable)
{
_renderables.Add(renderable);
return this;
}
public Diagram Add(IEnumerable<IRenderable> renderable)
{
_renderables.AddRange(renderable);
return this;
}
public Diagram Connect(Shape from, Shape to, string label = "", ArrowheadOptions? fromArrowhead = null, ArrowheadOptions? toArrowhead = null)
{
_renderables.Add(new Connection(from.Key, to.Key, label, fromArrowhead, toArrowhead));
return this;
}
public Diagram CreateShape(string key, string label, ShapeType type)
{
_renderables.Add(new Shape(key, label, type));
return this;
}
public Diagram CreateShape(string key, string label)
{
_renderables.Add(new Shape(key, label));
return this;
}
public Diagram CreateShape(string key, ShapeType type)
{
_renderables.Add(new Shape(key, type));
return this;
}
public Diagram CreateMarkdownShape(string key, string label)
{
_renderables.Add(new Markdown(key, label));
return this;
}
public Diagram CreateMarkdownShape(string key, string label, ShapeType type)
{
_renderables.Add(new Markdown(key, label, type));
return this;
}
public Diagram CreateLatexShape(string key, string label)
{
_renderables.Add(new LateX(key, label));
return this;
}
public Diagram CreateLatexShape(string key, string label, ShapeType type)
{
_renderables.Add(new LateX(key, label, type));
return this;
}
public Diagram CreateDirectionalConnection(string from, string to, string label = "", ArrowheadOptions? toArrowhead = null)
{
_renderables.Add(new Connection(from, to, label, null, toArrowhead));
return this;
}
public Diagram CreateBidirectionalConnection(string from, string to, string label = "", ArrowheadOptions? fromArrowhead = null, ArrowheadOptions? toArrowhead = null)
{
_renderables.Add(new Connection(from, to, label, ConnectionType.Bidirectional, fromArrowhead, toArrowhead));
return this;
}
public Diagram CreateConnection(string from, string to, string label = "")
{
_renderables.Add(new Connection(from, to, label, ConnectionType.From));
return this;
}
public override string ToString()
{
return string.Join(Environment.NewLine, _renderables);
}
}
}