Explicitly prevent empty ranges
This commit is contained in:
parent
b719c1c512
commit
231ff42904
2 changed files with 35 additions and 0 deletions
4
tick.go
4
tick.go
|
@ -133,6 +133,10 @@ func GeneratePrettyContinuousTicks(r Renderer, ra Range, isVertical bool, style
|
||||||
|
|
||||||
rangeMin, rangeMax := ra.GetMin(), ra.GetMax()
|
rangeMin, rangeMax := ra.GetMin(), ra.GetMax()
|
||||||
|
|
||||||
|
if rangeMin >= rangeMax || ra.GetDomain() == 0 {
|
||||||
|
return []Tick{}
|
||||||
|
}
|
||||||
|
|
||||||
renderedLabelExample := vf(rangeMin)
|
renderedLabelExample := vf(rangeMin)
|
||||||
style.GetTextOptions().WriteToRenderer(r)
|
style.GetTextOptions().WriteToRenderer(r)
|
||||||
renderedLabelSizePx := r.MeasureText(renderedLabelExample)
|
renderedLabelSizePx := r.MeasureText(renderedLabelExample)
|
||||||
|
|
31
tick_test.go
31
tick_test.go
|
@ -95,6 +95,37 @@ func TestGenerateContinuousPrettyTicks(t *testing.T) {
|
||||||
{Label: "60.00", Value: 60}})
|
{Label: "60.00", Value: 60}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenerateContinuousPrettyTicksForEmptyRange(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
f, err := GetDefaultFont()
|
||||||
|
assert.Nil(err)
|
||||||
|
|
||||||
|
r, err := PNG(1024, 1024)
|
||||||
|
assert.Nil(err)
|
||||||
|
r.SetFont(f)
|
||||||
|
|
||||||
|
ra := &ContinuousRange{
|
||||||
|
Min: 1.0,
|
||||||
|
Max: 1.0,
|
||||||
|
Domain: 256,
|
||||||
|
}
|
||||||
|
|
||||||
|
vf := FloatValueFormatter
|
||||||
|
|
||||||
|
ticks := GeneratePrettyContinuousTicks(r, ra, false, Style{}, vf)
|
||||||
|
assert.Empty(ticks)
|
||||||
|
|
||||||
|
ra = &ContinuousRange{
|
||||||
|
Min: 1.0,
|
||||||
|
Max: 2.0,
|
||||||
|
Domain: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
ticks = GeneratePrettyContinuousTicks(r, ra, false, Style{}, vf)
|
||||||
|
assert.Empty(ticks)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGeneratePrettyTicksForVerySmallRange(t *testing.T) {
|
func TestGeneratePrettyTicksForVerySmallRange(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue