-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode.go
102 lines (81 loc) · 1.94 KB
/
node.go
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
99
100
101
102
package gdag
type Node struct {
nodeType nodeType
index int // mermaidの識別子としても利用する
text string
note string
hour float64 // 見積時間
color string // done: #DarkGray
colorMermaid string // done: doneColor
// parent *Node // TODO: 現状、中間ノードのためにおいてる
downstream []*Node
startPoint bool // レンダリング処理の最初の node ということ
}
type nodeType string
const (
rectangle = nodeType("rectangle")
usecase = nodeType("usecase")
)
func DAG(text string) *Node {
return newNode(rectangle, text)
}
func Task(text string) *Node {
return newNode(usecase, text)
}
var nodeIdx int
func newNode(nodeType nodeType, text string) *Node {
nodeIdx++
return &Node{
nodeType: nodeType,
text: text,
index: nodeIdx,
}
}
const (
colorDone = "#DarkGray"
colorDoneMermaid = "doneColor"
)
func Done(nodes ...*Node) {
for _, n := range nodes {
n.color = colorDone
n.colorMermaid = colorDoneMermaid
}
}
func (upstream *Node) Con(current *Node) *Node {
for _, d := range upstream.downstream {
if current.index == d.index {
return d
}
}
upstream.downstream = append(upstream.downstream, current)
return current
}
type FanIO struct {
upstream *Node
}
func (upstream *Node) Fanout(nodes ...*Node) *FanIO {
upstream.downstream = append(upstream.downstream, nodes...)
return &FanIO{
upstream: upstream,
}
}
func (fio *FanIO) Fanin(current *Node) *Node {
for i := range fio.upstream.downstream {
fio.upstream.downstream[i].downstream = append(fio.upstream.downstream[i].downstream, current)
}
return current
}
func (current *Node) Note(note string) *Node {
current.note = note
return current
}
func (current *Node) Hour(hour float64) *Node {
current.hour = hour
return current
}
func (current *Node) isDone() bool {
return current.color == colorDone
}
func (current *Node) isDAG() bool {
return current.nodeType == rectangle
}