2016-07-13 07:04:30 +02:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-04-05 09:42:38 +02:00
|
|
|
"github.com/blend/go-sdk/assert"
|
2016-07-13 07:04:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestYAxisGetTicks(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
r, err := PNG(1024, 1024)
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
f, err := GetDefaultFont()
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
ya := YAxis{}
|
2016-07-21 23:11:27 +02:00
|
|
|
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
|
2016-07-13 07:04:30 +02:00
|
|
|
styleDefaults := Style{
|
|
|
|
Font: f,
|
|
|
|
FontSize: 10.0,
|
|
|
|
}
|
|
|
|
vf := FloatValueFormatter
|
|
|
|
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
|
2018-04-05 09:47:39 +02:00
|
|
|
assert.Len(32, ticks)
|
2016-07-13 07:04:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestYAxisGetTicksWithUserDefaults(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
r, err := PNG(1024, 1024)
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
f, err := GetDefaultFont()
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
ya := YAxis{
|
2016-07-15 22:45:33 +02:00
|
|
|
Ticks: []Tick{{Value: 1.0, Label: "1.0"}},
|
2016-07-13 07:04:30 +02:00
|
|
|
}
|
2016-07-21 23:11:27 +02:00
|
|
|
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
|
2016-07-13 07:04:30 +02:00
|
|
|
styleDefaults := Style{
|
|
|
|
Font: f,
|
|
|
|
FontSize: 10.0,
|
|
|
|
}
|
|
|
|
vf := FloatValueFormatter
|
|
|
|
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
|
2018-04-05 09:47:39 +02:00
|
|
|
assert.Len(1, ticks)
|
2016-07-13 07:04:30 +02:00
|
|
|
}
|
2016-07-29 01:40:29 +02:00
|
|
|
|
|
|
|
func TestYAxisMeasure(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
f, err := GetDefaultFont()
|
|
|
|
assert.Nil(err)
|
|
|
|
style := Style{
|
|
|
|
Font: f,
|
|
|
|
FontSize: 10.0,
|
|
|
|
}
|
|
|
|
r, err := PNG(100, 100)
|
|
|
|
assert.Nil(err)
|
|
|
|
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}}
|
|
|
|
ya := YAxis{}
|
2017-03-06 01:54:40 +01:00
|
|
|
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks)
|
2016-07-29 01:40:29 +02:00
|
|
|
assert.Equal(32, yab.Width())
|
|
|
|
assert.Equal(110, yab.Height())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYAxisSecondaryMeasure(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
f, err := GetDefaultFont()
|
|
|
|
assert.Nil(err)
|
|
|
|
style := Style{
|
|
|
|
Font: f,
|
|
|
|
FontSize: 10.0,
|
|
|
|
}
|
|
|
|
r, err := PNG(100, 100)
|
|
|
|
assert.Nil(err)
|
|
|
|
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}}
|
|
|
|
ya := YAxis{AxisType: YAxisSecondary}
|
2017-03-06 01:54:40 +01:00
|
|
|
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks)
|
2016-07-29 01:40:29 +02:00
|
|
|
assert.Equal(32, yab.Width())
|
|
|
|
assert.Equal(110, yab.Height())
|
|
|
|
}
|