Debian Codegraph @

histogram_series.go

raw symbols SCIP
1 package chart
2
3 import "fmt"
4
5 // HistogramSeries is a special type of series that draws as a histogram.
6 // Some peculiarities; it will always be lower bounded at 0 (at the very least).
7 // This may alter ranges a bit and generally you want to put a histogram series on it's own y-axis.
8 type HistogramSeries struct {
9 Name string
10 Style Style
11 YAxis YAxisType
12 InnerSeries ValuesProvider
13 }
14
15 // GetName implements Series.GetName.
16 func (hs HistogramSeries) GetName() string {
17 return hs.Name
18 }
19
20 // GetStyle implements Series.GetStyle.
21 func (hs HistogramSeries) GetStyle() Style {
22 return hs.Style
23 }
24
25 // GetYAxis returns which yaxis the series is mapped to.
26 func (hs HistogramSeries) GetYAxis() YAxisType {
27 return hs.YAxis
28 }
29
30 // Len implements BoundedValuesProvider.Len.
31 func (hs HistogramSeries) Len() int {
32 return hs.InnerSeries.Len()
33 }
34
35 // GetValues implements ValuesProvider.GetValues.
36 func (hs HistogramSeries) GetValues(index int) (x, y float64) {
37 return hs.InnerSeries.GetValues(index)
38 }
39
40 // GetBoundedValues implements BoundedValuesProvider.GetBoundedValue
41 func (hs HistogramSeries) GetBoundedValues(index int) (x, y1, y2 float64) {
42 vx, vy := hs.InnerSeries.GetValues(index)
43
44 x = vx
45
46 if vy > 0 {
47 y1 = vy
48 return
49 }
50
51 y2 = vy
52 return
53 }
54
55 // Render implements Series.Render.
56 func (hs HistogramSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
57 style := hs.Style.InheritFrom(defaults)
58 Draw.HistogramSeries(r, canvasBox, xrange, yrange, style, hs)
59 }
60
61 // Validate validates the series.
62 func (hs HistogramSeries) Validate() error {
63 if hs.InnerSeries == nil {
64 return fmt.Errorf("histogram series requires InnerSeries to be set")
65 }
66 return nil
67 }