| 1 |
package chart |
| 2 |
|
| 3 |
import "fmt" |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
type HistogramSeries struct { |
| 9 |
Name string |
| 10 |
Style Style |
| 11 |
YAxis YAxisType |
| 12 |
InnerSeries ValuesProvider |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
func (hs HistogramSeries) GetName() string { |
| 17 |
return hs.Name |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
func (hs HistogramSeries) GetStyle() Style { |
| 22 |
return hs.Style |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
func (hs HistogramSeries) GetYAxis() YAxisType { |
| 27 |
return hs.YAxis |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
func (hs HistogramSeries) Len() int { |
| 32 |
return hs.InnerSeries.Len() |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
func (hs HistogramSeries) GetValues(index int) (x, y float64) { |
| 37 |
return hs.InnerSeries.GetValues(index) |
| 38 |
} |
| 39 |
|
| 40 |
|
| 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 |
|
| 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 |
|
| 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 |
} |