tests for some things that came up as regressions when building out examples.
This commit is contained in:
parent
230dd16308
commit
6d48c49c07
12
chart.go
12
chart.go
|
@ -373,12 +373,20 @@ func (c Chart) getAnnotationAdjustedCanvasBox(r Renderer, canvasBox Box, xr, yr,
|
|||
return canvasBox.OuterConstrain(c.Box(), annotationSeriesBox)
|
||||
}
|
||||
|
||||
func (c Chart) getBackgroundStyle() Style {
|
||||
return c.Background.WithDefaultsFrom(c.styleDefaultsBackground())
|
||||
}
|
||||
|
||||
func (c Chart) drawBackground(r Renderer) {
|
||||
DrawBox(r, c.Box(), c.Background.WithDefaultsFrom(c.styleDefaultsBackground()))
|
||||
DrawBox(r, c.Box(), c.getBackgroundStyle())
|
||||
}
|
||||
|
||||
func (c Chart) getCanvasStyle() Style {
|
||||
return c.Canvas.WithDefaultsFrom(c.styleDefaultsCanvas())
|
||||
}
|
||||
|
||||
func (c Chart) drawCanvas(r Renderer, canvasBox Box) {
|
||||
DrawBox(r, canvasBox, c.Canvas.WithDefaultsFrom(c.styleDefaultsCanvas()))
|
||||
DrawBox(r, canvasBox, c.getCanvasStyle())
|
||||
}
|
||||
|
||||
func (c Chart) drawAxes(r Renderer, canvasBox Box, xrange, yrange, yrangeAlt Range, xticks, yticks, yticksAlt []Tick) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/blendlabs/go-assert"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
)
|
||||
|
||||
func TestChartGetDPI(t *testing.T) {
|
||||
|
@ -123,6 +124,96 @@ func TestChartGetRanges(t *testing.T) {
|
|||
assert.Equal(19.7, yra2.Max)
|
||||
}
|
||||
|
||||
func TestChartGetRangesUseTicks(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
// this test asserts that ticks should supercede manual ranges when generating the overall ranges.
|
||||
|
||||
c := Chart{
|
||||
YAxis: YAxis{
|
||||
Ticks: []Tick{
|
||||
{0.0, "Zero"},
|
||||
{1.0, "1.0"},
|
||||
{2.0, "2.0"},
|
||||
{3.0, "3.0"},
|
||||
{4.0, "4.0"},
|
||||
{5.0, "Five"},
|
||||
},
|
||||
Range: Range{
|
||||
Min: -5.0,
|
||||
Max: 5.0,
|
||||
},
|
||||
},
|
||||
Series: []Series{
|
||||
ContinuousSeries{
|
||||
XValues: []float64{-2.0, -1.0, 0, 1.0, 2.0},
|
||||
YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
xr, yr, yar := c.getRanges()
|
||||
assert.Equal(-2.0, xr.Min)
|
||||
assert.Equal(2.0, xr.Max)
|
||||
assert.Equal(0.0, yr.Min)
|
||||
assert.Equal(5.0, yr.Max)
|
||||
assert.True(yar.IsZero(), yar.String())
|
||||
}
|
||||
|
||||
func TestChartGetRangesUseUserRanges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
// this test asserts that ticks should supercede manual ranges when generating the overall ranges.
|
||||
|
||||
c := Chart{
|
||||
YAxis: YAxis{
|
||||
Range: Range{
|
||||
Min: -5.0,
|
||||
Max: 5.0,
|
||||
},
|
||||
},
|
||||
Series: []Series{
|
||||
ContinuousSeries{
|
||||
XValues: []float64{-2.0, -1.0, 0, 1.0, 2.0},
|
||||
YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
xr, yr, yar := c.getRanges()
|
||||
assert.Equal(-2.0, xr.Min)
|
||||
assert.Equal(2.0, xr.Max)
|
||||
assert.Equal(-5.0, yr.Min)
|
||||
assert.Equal(5.0, yr.Max)
|
||||
assert.True(yar.IsZero(), yar.String())
|
||||
}
|
||||
|
||||
func TestChartGetBackgroundStyle(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
c := Chart{
|
||||
Background: Style{
|
||||
FillColor: drawing.ColorBlack,
|
||||
},
|
||||
}
|
||||
|
||||
bs := c.getBackgroundStyle()
|
||||
assert.Equal(bs.FillColor.String(), drawing.ColorBlack.String())
|
||||
}
|
||||
|
||||
func TestChartGetCanvasStyle(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
c := Chart{
|
||||
Canvas: Style{
|
||||
FillColor: drawing.ColorBlack,
|
||||
},
|
||||
}
|
||||
|
||||
bs := c.getCanvasStyle()
|
||||
assert.Equal(bs.FillColor.String(), drawing.ColorBlack.String())
|
||||
}
|
||||
|
||||
func TestChartGetDefaultCanvasBox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
4
range.go
4
range.go
|
@ -14,7 +14,9 @@ type Range struct {
|
|||
|
||||
// IsZero returns if the range has been set or not.
|
||||
func (r Range) IsZero() bool {
|
||||
return r.Min == 0 && r.Max == 0 && r.Domain == 0
|
||||
return (r.Min == 0 || math.IsNaN(r.Min)) &&
|
||||
(r.Max == 0 || math.IsNaN(r.Max)) &&
|
||||
r.Domain == 0
|
||||
}
|
||||
|
||||
// Delta returns the difference between the min and max value.
|
||||
|
|
Loading…
Reference in New Issue
Block a user