2016-07-11 00:00:03 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
"testing"
|
|
|
|
|
2020-11-22 19:45:10 -05:00
|
|
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
|
|
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
2016-07-11 00:00:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAnnotationSeriesMeasure(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-11 00:00:03 -04:00
|
|
|
|
|
|
|
as := AnnotationSeries{
|
2016-07-28 17:30:00 -04:00
|
|
|
Annotations: []Value2{
|
|
|
|
{XValue: 1.0, YValue: 1.0, Label: "1.0"},
|
|
|
|
{XValue: 2.0, YValue: 2.0, Label: "2.0"},
|
|
|
|
{XValue: 3.0, YValue: 3.0, Label: "3.0"},
|
|
|
|
{XValue: 4.0, YValue: 4.0, Label: "4.0"},
|
2016-07-11 00:00:03 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := PNG(110, 110)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNil(t, err)
|
2016-07-11 00:00:03 -04:00
|
|
|
|
|
|
|
f, err := GetDefaultFont()
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNil(t, err)
|
2016-07-11 00:00:03 -04:00
|
|
|
|
2016-07-21 17:11:27 -04:00
|
|
|
xrange := &ContinuousRange{
|
2016-07-11 00:00:03 -04:00
|
|
|
Min: 1.0,
|
|
|
|
Max: 4.0,
|
|
|
|
Domain: 100,
|
|
|
|
}
|
2016-07-21 17:11:27 -04:00
|
|
|
yrange := &ContinuousRange{
|
2016-07-11 00:00:03 -04:00
|
|
|
Min: 1.0,
|
|
|
|
Max: 4.0,
|
|
|
|
Domain: 100,
|
|
|
|
}
|
|
|
|
|
|
|
|
cb := Box{
|
|
|
|
Top: 5,
|
|
|
|
Left: 5,
|
|
|
|
Right: 105,
|
|
|
|
Bottom: 105,
|
|
|
|
}
|
|
|
|
sd := Style{
|
|
|
|
FontSize: 10.0,
|
|
|
|
Font: f,
|
|
|
|
}
|
|
|
|
|
|
|
|
box := as.Measure(r, cb, xrange, yrange, sd)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertFalse(t, box.IsZero())
|
|
|
|
testutil.AssertEqual(t, -5.0, box.Top)
|
|
|
|
testutil.AssertEqual(t, 5.0, box.Left)
|
|
|
|
testutil.AssertEqual(t, 146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px.
|
|
|
|
testutil.AssertEqual(t, 115.0, box.Bottom)
|
2016-07-11 00:00:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnotationSeriesRender(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-11 00:00:03 -04:00
|
|
|
|
|
|
|
as := AnnotationSeries{
|
|
|
|
Style: Style{
|
|
|
|
FillColor: drawing.ColorWhite,
|
|
|
|
StrokeColor: drawing.ColorBlack,
|
|
|
|
},
|
2016-07-28 17:30:00 -04:00
|
|
|
Annotations: []Value2{
|
|
|
|
{XValue: 1.0, YValue: 1.0, Label: "1.0"},
|
|
|
|
{XValue: 2.0, YValue: 2.0, Label: "2.0"},
|
|
|
|
{XValue: 3.0, YValue: 3.0, Label: "3.0"},
|
|
|
|
{XValue: 4.0, YValue: 4.0, Label: "4.0"},
|
2016-07-11 00:00:03 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := PNG(110, 110)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNil(t, err)
|
2016-07-11 00:00:03 -04:00
|
|
|
|
|
|
|
f, err := GetDefaultFont()
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNil(t, err)
|
2016-07-11 00:00:03 -04:00
|
|
|
|
2016-07-21 17:11:27 -04:00
|
|
|
xrange := &ContinuousRange{
|
2016-07-11 00:00:03 -04:00
|
|
|
Min: 1.0,
|
|
|
|
Max: 4.0,
|
|
|
|
Domain: 100,
|
|
|
|
}
|
2016-07-21 17:11:27 -04:00
|
|
|
yrange := &ContinuousRange{
|
2016-07-11 00:00:03 -04:00
|
|
|
Min: 1.0,
|
|
|
|
Max: 4.0,
|
|
|
|
Domain: 100,
|
|
|
|
}
|
|
|
|
|
|
|
|
cb := Box{
|
|
|
|
Top: 5,
|
|
|
|
Left: 5,
|
|
|
|
Right: 105,
|
|
|
|
Bottom: 105,
|
|
|
|
}
|
|
|
|
sd := Style{
|
|
|
|
FontSize: 10.0,
|
|
|
|
Font: f,
|
|
|
|
}
|
|
|
|
|
|
|
|
as.Render(r, cb, xrange, yrange, sd)
|
|
|
|
|
|
|
|
rr, isRaster := r.(*rasterRenderer)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertTrue(t, isRaster)
|
|
|
|
testutil.AssertNotNil(t, rr)
|
2016-07-11 00:00:03 -04:00
|
|
|
|
2016-07-12 02:32:31 -04:00
|
|
|
c := rr.i.At(38, 70)
|
2016-07-11 00:00:03 -04:00
|
|
|
converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertTrue(t, isRGBA)
|
|
|
|
testutil.AssertEqual(t, 0, converted.R)
|
|
|
|
testutil.AssertEqual(t, 0, converted.G)
|
|
|
|
testutil.AssertEqual(t, 0, converted.B)
|
2016-07-11 00:00:03 -04:00
|
|
|
}
|