Debian Codegraph @

first_value_annotation.go

raw symbols SCIP
1 package chart
2
3 import "fmt"
4
5 // FirstValueAnnotation returns an annotation series of just the first value of a value provider as an annotation.
6 func FirstValueAnnotation(innerSeries ValuesProvider, vfs ...ValueFormatter) AnnotationSeries {
7 var vf ValueFormatter
8 if len(vfs) > 0 {
9 vf = vfs[0]
10 } else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped {
11 _, vf = typed.GetValueFormatters()
12 } else {
13 vf = FloatValueFormatter
14 }
15
16 var firstValue Value2
17 if typed, isTyped := innerSeries.(FirstValuesProvider); isTyped {
18 firstValue.XValue, firstValue.YValue = typed.GetFirstValues()
19 firstValue.Label = vf(firstValue.YValue)
20 } else {
21 firstValue.XValue, firstValue.YValue = innerSeries.GetValues(0)
22 firstValue.Label = vf(firstValue.YValue)
23 }
24
25 var seriesName string
26 var seriesStyle Style
27 if typed, isTyped := innerSeries.(Series); isTyped {
28 seriesName = fmt.Sprintf("%s - First Value", typed.GetName())
29 seriesStyle = typed.GetStyle()
30 }
31
32 return AnnotationSeries{
33 Name: seriesName,
34 Style: seriesStyle,
35 Annotations: []Value2{firstValue},
36 }
37 }