Debian Codegraph @

annotation_series_test.go

raw symbols SCIP
1 package chart
2
3 import (
4 "image/color"
5 "testing"
6
7 "github.com/wcharczuk/go-chart/v2/drawing"
8 "github.com/wcharczuk/go-chart/v2/testutil"
9 )
10
11 func TestAnnotationSeriesMeasure(t *testing.T) {
12 // replaced new assertions helper
13
14 as := AnnotationSeries{
15 Annotations: []Value2{
16 {XValue: 1.0, YValue: 1.0, Label: "1.0"},
17 {XValue: 2.0, YValue: 2.0, Label: "2.0"},
18 {XValue: 3.0, YValue: 3.0, Label: "3.0"},
19 {XValue: 4.0, YValue: 4.0, Label: "4.0"},
20 },
21 }
22
23 r, err := PNG(110, 110)
24 testutil.AssertNil(t, err)
25
26 f, err := GetDefaultFont()
27 testutil.AssertNil(t, err)
28
29 xrange := &ContinuousRange{
30 Min: 1.0,
31 Max: 4.0,
32 Domain: 100,
33 }
34 yrange := &ContinuousRange{
35 Min: 1.0,
36 Max: 4.0,
37 Domain: 100,
38 }
39
40 cb := Box{
41 Top: 5,
42 Left: 5,
43 Right: 105,
44 Bottom: 105,
45 }
46 sd := Style{
47 FontSize: 10.0,
48 Font: f,
49 }
50
51 box := as.Measure(r, cb, xrange, yrange, sd)
52 testutil.AssertFalse(t, box.IsZero())
53 testutil.AssertEqual(t, -5.0, box.Top)
54 testutil.AssertEqual(t, 5.0, box.Left)
55 testutil.AssertEqual(t, 146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px.
56 testutil.AssertEqual(t, 115.0, box.Bottom)
57 }
58
59 func TestAnnotationSeriesRender(t *testing.T) {
60 // replaced new assertions helper
61
62 as := AnnotationSeries{
63 Style: Style{
64 FillColor: drawing.ColorWhite,
65 StrokeColor: drawing.ColorBlack,
66 },
67 Annotations: []Value2{
68 {XValue: 1.0, YValue: 1.0, Label: "1.0"},
69 {XValue: 2.0, YValue: 2.0, Label: "2.0"},
70 {XValue: 3.0, YValue: 3.0, Label: "3.0"},
71 {XValue: 4.0, YValue: 4.0, Label: "4.0"},
72 },
73 }
74
75 r, err := PNG(110, 110)
76 testutil.AssertNil(t, err)
77
78 f, err := GetDefaultFont()
79 testutil.AssertNil(t, err)
80
81 xrange := &ContinuousRange{
82 Min: 1.0,
83 Max: 4.0,
84 Domain: 100,
85 }
86 yrange := &ContinuousRange{
87 Min: 1.0,
88 Max: 4.0,
89 Domain: 100,
90 }
91
92 cb := Box{
93 Top: 5,
94 Left: 5,
95 Right: 105,
96 Bottom: 105,
97 }
98 sd := Style{
99 FontSize: 10.0,
100 Font: f,
101 }
102
103 as.Render(r, cb, xrange, yrange, sd)
104
105 rr, isRaster := r.(*rasterRenderer)
106 testutil.AssertTrue(t, isRaster)
107 testutil.AssertNotNil(t, rr)
108
109 c := rr.i.At(38, 70)
110 converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA)
111 testutil.AssertTrue(t, isRGBA)
112 testutil.AssertEqual(t, 0, converted.R)
113 testutil.AssertEqual(t, 0, converted.G)
114 testutil.AssertEqual(t, 0, converted.B)
115 }