go-chart/yaxis_test.go

86 lines
2.1 KiB
Go
Raw Normal View History

2016-07-13 01:04:30 -04:00
package chart
import (
"testing"
"github.com/wcharczuk/go-chart/v2/testutil"
2016-07-13 01:04:30 -04:00
)
func TestYAxisGetTicks(t *testing.T) {
// replaced new assertions helper
2016-07-13 01:04:30 -04:00
r, err := PNG(1024, 1024)
testutil.AssertNil(t, err)
2016-07-13 01:04:30 -04:00
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
2016-07-13 01:04:30 -04:00
ya := YAxis{}
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
2016-07-13 01:04:30 -04:00
styleDefaults := Style{
Font: f,
FontSize: 10.0,
}
vf := FloatValueFormatter
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
testutil.AssertLen(t, ticks, 32)
2016-07-13 01:04:30 -04:00
}
func TestYAxisGetTicksWithUserDefaults(t *testing.T) {
// replaced new assertions helper
2016-07-13 01:04:30 -04:00
r, err := PNG(1024, 1024)
testutil.AssertNil(t, err)
2016-07-13 01:04:30 -04:00
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
2016-07-13 01:04:30 -04:00
ya := YAxis{
2016-07-15 16:45:33 -04:00
Ticks: []Tick{{Value: 1.0, Label: "1.0"}},
2016-07-13 01:04:30 -04:00
}
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
2016-07-13 01:04:30 -04:00
styleDefaults := Style{
Font: f,
FontSize: 10.0,
}
vf := FloatValueFormatter
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
testutil.AssertLen(t, ticks, 1)
2016-07-13 01:04:30 -04:00
}
2016-07-28 19:40:29 -04:00
func TestYAxisMeasure(t *testing.T) {
// replaced new assertions helper
2016-07-28 19:40:29 -04:00
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
2016-07-28 19:40:29 -04:00
style := Style{
Font: f,
FontSize: 10.0,
}
r, err := PNG(100, 100)
testutil.AssertNil(t, err)
2016-07-28 19:40:29 -04:00
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}}
ya := YAxis{}
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks)
testutil.AssertEqual(t, 32, yab.Width())
testutil.AssertEqual(t, 110, yab.Height())
2016-07-28 19:40:29 -04:00
}
func TestYAxisSecondaryMeasure(t *testing.T) {
// replaced new assertions helper
2016-07-28 19:40:29 -04:00
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
2016-07-28 19:40:29 -04:00
style := Style{
Font: f,
FontSize: 10.0,
}
r, err := PNG(100, 100)
testutil.AssertNil(t, err)
2016-07-28 19:40:29 -04:00
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}}
ya := YAxis{AxisType: YAxisSecondary}
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks)
testutil.AssertEqual(t, 32, yab.Width())
testutil.AssertEqual(t, 110, yab.Height())
2016-07-28 19:40:29 -04:00
}