From 099886834fae186ca3e732a7ff8acfcdf8387823 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Sun, 8 Jan 2017 17:29:50 +0000 Subject: [PATCH] allow for custom number format function in barchart --- barchart.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/barchart.go b/barchart.go index 6560c8b..feb4bbd 100644 --- a/barchart.go +++ b/barchart.go @@ -25,6 +25,7 @@ type BarChart struct { BarColor Attribute TextColor Attribute NumColor Attribute + NumFmt func(int) string Data []int DataLabels []string BarWidth int @@ -43,6 +44,7 @@ func NewBarChart() *BarChart { bc.BarColor = ThemeAttr("barchart.bar.bg") bc.NumColor = ThemeAttr("barchart.num.fg") bc.TextColor = ThemeAttr("barchart.text.fg") + bc.NumFmt = func(n int) string { return fmt.Sprint(n) } bc.BarGap = 1 bc.BarWidth = 3 bc.CellChar = ' ' @@ -57,7 +59,7 @@ func (bc *BarChart) layout() { for i := 0; i < bc.numBar && i < len(bc.DataLabels) && i < len(bc.Data); i++ { bc.labels[i] = trimStr2Runes(bc.DataLabels[i], bc.BarWidth) n := bc.Data[i] - s := fmt.Sprint(n) + s := bc.NumFmt(n) bc.dataNum[i] = trimStr2Runes(s, bc.BarWidth) }