sane default handling

This commit is contained in:
Will Charczuk 2017-04-25 23:35:07 -07:00
parent b244fd675c
commit 39e9977724
4 changed files with 20 additions and 4 deletions

View file

@ -354,13 +354,13 @@ func (c Chart) getValueFormatters() (x, y, ya ValueFormatter) {
}
}
if c.XAxis.ValueFormatter != nil {
x = c.XAxis.ValueFormatter
x = c.XAxis.GetValueFormatter()
}
if c.YAxis.ValueFormatter != nil {
y = c.YAxis.ValueFormatter
y = c.YAxis.GetValueFormatter()
}
if c.YAxisSecondary.ValueFormatter != nil {
ya = c.YAxisSecondary.ValueFormatter
ya = c.YAxisSecondary.GetValueFormatter()
}
return
}

View file

@ -47,7 +47,7 @@ func (t Ticks) String() string {
// GenerateContinuousTicks generates a set of ticks.
func GenerateContinuousTicks(r Renderer, ra Range, isVertical bool, style Style, vf ValueFormatter) []Tick {
if vf == nil {
panic("vf is nil; did you remember to set a default value formatter?")
vf = FloatValueFormatter
}
var ticks []Tick

View file

@ -30,6 +30,14 @@ func (xa XAxis) GetStyle() Style {
return xa.Style
}
// GetValueFormatter returns the value formatter for the axis.
func (xa XAxis) GetValueFormatter() ValueFormatter {
if xa.ValueFormatter != nil {
return xa.ValueFormatter
}
return FloatValueFormatter
}
// GetTickPosition returns the tick position option for the axis.
func (xa XAxis) GetTickPosition(defaults ...TickPosition) TickPosition {
if xa.TickPosition == TickPositionUnset {

View file

@ -41,6 +41,14 @@ func (ya YAxis) GetStyle() Style {
return ya.Style
}
// GetValueFormatter returns the value formatter for the axis.
func (ya YAxis) GetValueFormatter() ValueFormatter {
if ya.ValueFormatter != nil {
return ya.ValueFormatter
}
return FloatValueFormatter
}
// GetTickStyle returns the tick style.
func (ya YAxis) GetTickStyle() Style {
return ya.TickStyle