From 39e9977724d661e7287ab3958e075319625f84f4 Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Tue, 25 Apr 2017 23:35:07 -0700 Subject: [PATCH] sane default handling --- chart.go | 6 +++--- tick.go | 2 +- xaxis.go | 8 ++++++++ yaxis.go | 8 ++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/chart.go b/chart.go index f4f0098..70e5a57 100644 --- a/chart.go +++ b/chart.go @@ -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 } diff --git a/tick.go b/tick.go index 1b678ee..2764fcf 100644 --- a/tick.go +++ b/tick.go @@ -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 diff --git a/xaxis.go b/xaxis.go index c090d22..dd6e0fd 100644 --- a/xaxis.go +++ b/xaxis.go @@ -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 { diff --git a/yaxis.go b/yaxis.go index dce43db..3904729 100644 --- a/yaxis.go +++ b/yaxis.go @@ -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