add custom value formatters for continuous series.
This commit is contained in:
parent
e4cd38f602
commit
7776c351a8
2 changed files with 31 additions and 2 deletions
|
@ -7,6 +7,9 @@ type ContinuousSeries struct {
|
|||
|
||||
YAxis YAxisType
|
||||
|
||||
XValueFormatter ValueFormatter
|
||||
YValueFormatter ValueFormatter
|
||||
|
||||
XValues []float64
|
||||
YValues []float64
|
||||
}
|
||||
|
@ -38,8 +41,16 @@ func (cs ContinuousSeries) GetLastValue() (float64, float64) {
|
|||
|
||||
// GetValueFormatters returns value formatter defaults for the series.
|
||||
func (cs ContinuousSeries) GetValueFormatters() (x, y ValueFormatter) {
|
||||
if cs.XValueFormatter != nil {
|
||||
x = cs.XValueFormatter
|
||||
} else {
|
||||
x = FloatValueFormatter
|
||||
}
|
||||
if cs.YValueFormatter != nil {
|
||||
y = cs.YValueFormatter
|
||||
} else {
|
||||
y = FloatValueFormatter
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
assert "github.com/blendlabs/go-assert"
|
||||
|
@ -29,3 +30,20 @@ func TestContinuousSeries(t *testing.T) {
|
|||
assert.Equal(10.0, xn)
|
||||
assert.Equal(10.0, yn)
|
||||
}
|
||||
|
||||
func TestContinuousSeriesValueFormatter(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
cs := ContinuousSeries{
|
||||
XValueFormatter: func(v interface{}) string {
|
||||
return fmt.Sprintf("%f foo", v)
|
||||
},
|
||||
YValueFormatter: func(v interface{}) string {
|
||||
return fmt.Sprintf("%f bar", v)
|
||||
},
|
||||
}
|
||||
|
||||
xf, yf := cs.GetValueFormatters()
|
||||
assert.Equal("0.100000 foo", xf(0.1))
|
||||
assert.Equal("0.100000 bar", yf(0.1))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue