Skip to content

Commit

Permalink
sane default handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Charczuk committed Apr 26, 2017
1 parent b244fd6 commit 39e9977
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions xaxis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions yaxis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39e9977

Please sign in to comment.