Debian Codegraph @

percent_change_series.go

raw symbols SCIP
1 package chart
2
3 // Interface Assertions.
4 var (
5 _ Series = (*PercentChangeSeries)(nil)
6 _ FirstValuesProvider = (*PercentChangeSeries)(nil)
7 _ LastValuesProvider = (*PercentChangeSeries)(nil)
8 _ ValueFormatterProvider = (*PercentChangeSeries)(nil)
9 )
10
11 // PercentChangeSeriesSource is a series that
12 // can be used with a PercentChangeSeries
13 type PercentChangeSeriesSource interface {
14 Series
15 FirstValuesProvider
16 LastValuesProvider
17 ValuesProvider
18 ValueFormatterProvider
19 }
20
21 // PercentChangeSeries applies a
22 // percentage difference function to a given continuous series.
23 type PercentChangeSeries struct {
24 Name string
25 Style Style
26 YAxis YAxisType
27 InnerSeries PercentChangeSeriesSource
28 }
29
30 // GetName returns the name of the time series.
31 func (pcs PercentChangeSeries) GetName() string {
32 return pcs.Name
33 }
34
35 // GetStyle returns the line style.
36 func (pcs PercentChangeSeries) GetStyle() Style {
37 return pcs.Style
38 }
39
40 // Len implements part of Series.
41 func (pcs PercentChangeSeries) Len() int {
42 return pcs.InnerSeries.Len()
43 }
44
45 // GetFirstValues implements FirstValuesProvider.
46 func (pcs PercentChangeSeries) GetFirstValues() (x, y float64) {
47 return pcs.InnerSeries.GetFirstValues()
48 }
49
50 // GetValues gets x, y values at a given index.
51 func (pcs PercentChangeSeries) GetValues(index int) (x, y float64) {
52 _, fy := pcs.InnerSeries.GetFirstValues()
53 x0, y0 := pcs.InnerSeries.GetValues(index)
54 x = x0
55 y = PercentDifference(fy, y0)
56 return
57 }
58
59 // GetValueFormatters returns value formatter defaults for the series.
60 func (pcs PercentChangeSeries) GetValueFormatters() (x, y ValueFormatter) {
61 x, _ = pcs.InnerSeries.GetValueFormatters()
62 y = PercentValueFormatter
63 return
64 }
65
66 // GetYAxis returns which YAxis the series draws on.
67 func (pcs PercentChangeSeries) GetYAxis() YAxisType {
68 return pcs.YAxis
69 }
70
71 // GetLastValues gets the last values.
72 func (pcs PercentChangeSeries) GetLastValues() (x, y float64) {
73 _, fy := pcs.InnerSeries.GetFirstValues()
74 x0, y0 := pcs.InnerSeries.GetLastValues()
75 x = x0
76 y = PercentDifference(fy, y0)
77 return
78 }
79
80 // Render renders the series.
81 func (pcs PercentChangeSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
82 style := pcs.Style.InheritFrom(defaults)
83 Draw.LineSeries(r, canvasBox, xrange, yrange, style, pcs)
84 }
85
86 // Validate validates the series.
87 func (pcs PercentChangeSeries) Validate() error {
88 return pcs.InnerSeries.Validate()
89 }