go-chart/annotation_series_test.go

120 lines
2.2 KiB
Go
Raw Permalink Normal View History

2016-07-11 06:00:03 +02:00
package chart
import (
"image/color"
"testing"
"github.com/blendlabs/go-assert"
"github.com/wcharczuk/go-chart/drawing"
)
func TestAnnotationSeriesMeasure(t *testing.T) {
assert := assert.New(t)
as := AnnotationSeries{
Style: Style{
Show: true,
},
2016-07-28 23:30:00 +02: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 06:00:03 +02:00
},
}
r, err := PNG(110, 110)
assert.Nil(err)
f, err := GetDefaultFont()
assert.Nil(err)
xrange := &ContinuousRange{
2016-07-11 06:00:03 +02:00
Min: 1.0,
Max: 4.0,
Domain: 100,
}
yrange := &ContinuousRange{
2016-07-11 06:00:03 +02: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)
assert.False(box.IsZero())
2016-07-15 06:16:49 +02:00
assert.Equal(-5.0, box.Top)
2016-07-11 06:00:03 +02:00
assert.Equal(5.0, box.Left)
2017-02-23 02:48:32 +01:00
assert.Equal(146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px.
2016-07-11 06:00:03 +02:00
assert.Equal(115.0, box.Bottom)
}
func TestAnnotationSeriesRender(t *testing.T) {
assert := assert.New(t)
as := AnnotationSeries{
Style: Style{
Show: true,
FillColor: drawing.ColorWhite,
StrokeColor: drawing.ColorBlack,
},
2016-07-28 23:30:00 +02: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 06:00:03 +02:00
},
}
r, err := PNG(110, 110)
assert.Nil(err)
f, err := GetDefaultFont()
assert.Nil(err)
xrange := &ContinuousRange{
2016-07-11 06:00:03 +02:00
Min: 1.0,
Max: 4.0,
Domain: 100,
}
yrange := &ContinuousRange{
2016-07-11 06:00:03 +02: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)
assert.True(isRaster)
assert.NotNil(rr)
2016-07-12 08:32:31 +02:00
c := rr.i.At(38, 70)
2016-07-11 06:00:03 +02:00
converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA)
assert.True(isRGBA)
2016-07-12 08:32:31 +02:00
assert.Equal(0, converted.R)
assert.Equal(0, converted.G)
assert.Equal(0, converted.B)
2016-07-11 06:00:03 +02:00
}