-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmark_line_test.go
57 lines (52 loc) · 2.7 KB
/
mark_line_test.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
package charts
import (
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
func TestMarkLine(t *testing.T) {
t.Parallel()
tests := []struct {
render func(*Painter) ([]byte, error)
result string
}{
{
render: func(p *Painter) ([]byte, error) {
markLine := newMarkLinePainter(p)
series := Series{
Data: []float64{1, 2, 3},
}
series.MarkLine = NewMarkLine(
SeriesMarkDataTypeMax,
SeriesMarkDataTypeAverage,
SeriesMarkDataTypeMin,
)
markLine.add(markLineRenderOption{
fillColor: ColorBlack,
fontColor: ColorBlack,
strokeColor: ColorBlack,
series: series,
axisRange: newRange(p, nil,
p.Height(), 6, 0.0, 5.0, 0.0, 0.0),
})
if _, err := markLine.Render(); err != nil {
return nil, err
}
return p.Bytes()
},
result: "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 600 400\"><circle cx=\"23\" cy=\"164\" r=\"3\" style=\"stroke-width:1;stroke:black;fill:black\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 29 164\nL 562 164\" style=\"stroke-width:1;stroke:black;fill:black\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 562 159\nL 578 164\nL 562 169\nL 567 164\nL 562 159\" style=\"stroke-width:1;stroke:black;fill:black\"/><text x=\"580\" y=\"168\" style=\"stroke:none;fill:black;font-size:12.8px;font-family:'Roboto Medium',sans-serif\">3</text><circle cx=\"23\" cy=\"236\" r=\"3\" style=\"stroke-width:1;stroke:black;fill:black\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 29 236\nL 562 236\" style=\"stroke-width:1;stroke:black;fill:black\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 562 231\nL 578 236\nL 562 241\nL 567 236\nL 562 231\" style=\"stroke-width:1;stroke:black;fill:black\"/><text x=\"580\" y=\"240\" style=\"stroke:none;fill:black;font-size:12.8px;font-family:'Roboto Medium',sans-serif\">2</text><circle cx=\"23\" cy=\"308\" r=\"3\" style=\"stroke-width:1;stroke:black;fill:black\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 29 308\nL 562 308\" style=\"stroke-width:1;stroke:black;fill:black\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 562 303\nL 578 308\nL 562 313\nL 567 308\nL 562 303\" style=\"stroke-width:1;stroke:black;fill:black\"/><text x=\"580\" y=\"312\" style=\"stroke:none;fill:black;font-size:12.8px;font-family:'Roboto Medium',sans-serif\">1</text></svg>",
},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
p := NewPainter(PainterOptions{
OutputFormat: ChartOutputSVG,
Width: 600,
Height: 400,
}, PainterThemeOption(GetTheme(ThemeLight)))
data, err := tt.render(p.Child(PainterPaddingOption(NewBoxEqual(20))))
require.NoError(t, err)
assertEqualSVG(t, tt.result, data)
})
}
}