From 560aef66d5e9691d7a9179ebe98615348a872ac9 Mon Sep 17 00:00:00 2001 From: Xabier Larrakoetxea Date: Thu, 25 Apr 2019 06:17:01 +0200 Subject: [PATCH] Add linechart y-axis value formatter option API Signed-off-by: Xabier Larrakoetxea --- widgets/linechart/options.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/widgets/linechart/options.go b/widgets/linechart/options.go index 53e25d3..150f28b 100644 --- a/widgets/linechart/options.go +++ b/widgets/linechart/options.go @@ -40,6 +40,7 @@ type options struct { xAxisUnscaled bool yAxisMode axes.YScaleMode yAxisCustomScale *customScale + yAxisValueFormatter ValueFormatter zoomHightlightColor cell.Color zoomStepPercent int } @@ -194,3 +195,18 @@ func ZoomStepPercent(perc int) Option { opts.zoomStepPercent = perc }) } + +// YAxisFormattedValues sets a value formatter for the Y axis values. +// If a formatter is set, it will format the values with the desired +// ValueFormatter and will use the retuning string from the formatter +// instead of the numeric value to represent this value on the Y axis. +func YAxisFormattedValues(vfmt ValueFormatter) Option { + return option(func(opts *options) { + opts.yAxisValueFormatter = vfmt + }) +} + +// ValueFormatter will be used to format values onto string based +// representation. +// The received float64 value could be a math.NaN value. +type ValueFormatter func(value float64) string