-
Notifications
You must be signed in to change notification settings - Fork 2
/
umlgraph.go
63 lines (47 loc) · 1.1 KB
/
umlgraph.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
package pipeline
import (
"fmt"
"strings"
)
// UMLGraph represents a graph that can render itself into UML
type UMLGraph struct {
sb strings.Builder
}
// NewUMLGraph createsn UML Activity graph diagram that represents one
func NewUMLGraph() *UMLGraph {
return &UMLGraph{}
}
func (p *UMLGraph) AddDecision(statement string, yes GraphDrawer, no GraphDrawer) {
p.sb.WriteString(fmt.Sprintf("if (%s) then (yes)\n", statement))
yes(p)
p.sb.WriteString("else (no)\n")
no(p)
p.sb.WriteString("endif\n")
}
func (p *UMLGraph) AddConcurrency(forks ...GraphDrawer) {
if len(forks) == 0 {
return
}
p.sb.WriteString("fork\n")
for i, fork := range forks {
fork(p)
if len(forks) != (i + 1) {
p.sb.WriteString("fork again\n")
}
}
p.sb.WriteString("end fork\n")
}
func (p *UMLGraph) AddActivity(label string) {
p.sb.WriteString(fmt.Sprintf(":%s;\n", label))
}
func (p *UMLGraph) String() string {
var sb strings.Builder
// New
sb.WriteString("@startuml\n")
sb.WriteString("start\n")
sb.WriteString(p.sb.String())
// End
sb.WriteString("stop\n")
sb.WriteString("@enduml\n")
return sb.String()
}