Skip to content

fixes-336: Extend the Ticker interface to allow passing a format function

Created by: DavidGamba

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{}

Merge request reports

Loading