plot
plot copied to clipboard
fixes-336: Extend the Ticker interface to allow passing a format function
Fixes #336 This allows for easy wrappers around the plot.DefaultTicks struct with custom format functions:
type myCustomFormatTicks struct{}
var _ plot.Ticker = myCustomFormatTicks{}
func (myCustomFormatTicks) Ticks(min, max float64, format func(v float64, prec int) string) (ticks []plot.Tick) {
return plot.DefaultTicks{}.Ticks(min, max, myFormatFloatTick)
}
func myFormatFloatTick(v float64, prec int) string {
return strconv.FormatFloat(floats.Round(v, prec), 'g', 8, 64)
}
p.Y.Tick.Marker = myCustomFormatTicks{}
@sbinet please take another look.
@kortschak @eaburns any feedback about this change?
@sbinet please take another look. I apologize for the delay... With this, to provide a format to the default ticks, all I have to do is:
...
p, err := plot.New()
if err != nil {
return err
}
p.X.Tick.Format = myAxisTickFormat
p.Y.Tick.Format = myAxisTickFormat
...
func myAxisTickFormat(v float64, prec int) string {
return strconv.FormatFloat(floats.Round(v, prec), 'f', 0, 64)
}
@sbinet PTAL