-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathannotation.go
55 lines (48 loc) · 1.16 KB
/
annotation.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
package wardleyToGo
import (
"encoding/xml"
"image"
"image/color"
"strconv"
"github.com/owulveryck/wardleyToGo/internal/svg"
"github.com/owulveryck/wardleyToGo/internal/utils"
)
// An annotation is a set of placements of a certain label
type Annotation struct {
Identifier int
Placements []image.Point
Label string
}
func NewAnnotation(identifier int) *Annotation {
return &Annotation{
Identifier: identifier,
Placements: make([]image.Point, 0, 1),
}
}
func (a *Annotation) MarshalSVG(e *xml.Encoder, canvas image.Rectangle) error {
for _, coords := range a.Placements {
placement := utils.CalcCoords(coords, canvas)
//s.Gid(strconv.FormatInt(a.id, 10))
e.Encode(svg.Transform{
Translate: placement,
Components: []interface{}{
svg.Circle{
R: 15,
Fill: svg.White,
Stroke: svg.Color{color.RGBA{0x59, 0x59, 0x59, 0xff}},
StrokeWidth: "2",
},
svg.Text{
P: image.Point{0, 5},
Text: []byte(strconv.Itoa(a.Identifier)),
FontSize: "14px",
TextAnchor: svg.TextAnchorMiddle,
},
},
})
}
return nil
}
func (a *Annotation) String() string {
return a.Label
}