-
Notifications
You must be signed in to change notification settings - Fork 1
/
link.go
72 lines (63 loc) · 1.37 KB
/
link.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
package design
import "fmt"
// Return adds a link between from and to indicating a return signal.
func (d *SequenceDiagram) Return(from, to, text string) *Link {
l := d.Link(from, to, text)
l.Class = "dashed-arrow"
return l
}
// Link adds a link between from and to indicating a func call or data
// flow.
func (d *SequenceDiagram) Link(from, to, text string) *Link {
fromIndex := -1
toIndex := -1
for i, column := range d.columns {
if column == from {
fromIndex = i
break
}
}
for i, column := range d.columns {
if column == to {
toIndex = i
break
}
}
lnk := &Link{
fromIndex: fromIndex,
toIndex: toIndex,
text: text,
}
d.links = append(d.links, lnk)
if fromIndex == -1 {
panic(fmt.Sprintf("Missing %q column", from))
}
if toIndex == -1 {
panic(fmt.Sprintf("Missing %q column", to))
}
return lnk
}
// Skip adds dotted distance on all columns
func (d *SequenceDiagram) Skip() {
d.links = append(d.links, skip)
}
func (d *SequenceDiagram) ClearLinks() {
d.links = make([]*Link, 0)
}
var skip *Link = &Link{}
// Link represents an arrow in a sequence diagram
type Link struct {
fromIndex, toIndex int
text string
Class string
TextClass string
}
func (l *Link) toSelf() bool {
return l.fromIndex == l.toIndex
}
func (l *Link) class() string {
if l.Class == "" {
return "arrow"
}
return l.Class
}