2016-08-07 00:53:14 +02:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
// LastValueAnnotation returns an annotation series of just the last value of a value provider.
|
2017-05-13 02:12:23 +02:00
|
|
|
func LastValueAnnotation(innerSeries ValuesProvider, vfs ...ValueFormatter) AnnotationSeries {
|
2016-08-07 00:53:14 +02:00
|
|
|
var vf ValueFormatter
|
|
|
|
if len(vfs) > 0 {
|
|
|
|
vf = vfs[0]
|
|
|
|
} else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped {
|
|
|
|
_, vf = typed.GetValueFormatters()
|
|
|
|
} else {
|
|
|
|
vf = FloatValueFormatter
|
|
|
|
}
|
|
|
|
|
|
|
|
var lastValue Value2
|
2017-05-13 02:12:23 +02:00
|
|
|
if typed, isTyped := innerSeries.(LastValuesProvider); isTyped {
|
|
|
|
lastValue.XValue, lastValue.YValue = typed.GetLastValues()
|
2016-08-07 00:53:14 +02:00
|
|
|
lastValue.Label = vf(lastValue.YValue)
|
|
|
|
} else {
|
2017-05-13 02:12:23 +02:00
|
|
|
lastValue.XValue, lastValue.YValue = innerSeries.GetValues(innerSeries.Len() - 1)
|
2016-08-07 00:53:14 +02:00
|
|
|
lastValue.Label = vf(lastValue.YValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
var seriesName string
|
|
|
|
var seriesStyle Style
|
|
|
|
if typed, isTyped := innerSeries.(Series); isTyped {
|
|
|
|
seriesName = fmt.Sprintf("%s - Last Value", typed.GetName())
|
|
|
|
seriesStyle = typed.GetStyle()
|
|
|
|
}
|
|
|
|
|
|
|
|
return AnnotationSeries{
|
|
|
|
Name: seriesName,
|
|
|
|
Style: seriesStyle,
|
|
|
|
Annotations: []Value2{lastValue},
|
|
|
|
}
|
|
|
|
}
|