go-chart/histogram_series.go

68 lines
1.7 KiB
Go
Raw Permalink Normal View History

2016-07-17 10:42:31 +02:00
package chart
2017-02-03 20:26:53 +01:00
import "fmt"
2016-07-17 10:42:31 +02:00
// HistogramSeries is a special type of series that draws as a histogram.
// Some peculiarities; it will always be lower bounded at 0 (at the very least).
// This may alter ranges a bit and generally you want to put a histogram series on it's own y-axis.
type HistogramSeries struct {
Name string
Style Style
2016-08-01 01:54:09 +02:00
YAxis YAxisType
InnerSeries ValuesProvider
2016-07-17 10:42:31 +02:00
}
// GetName implements Series.GetName.
func (hs HistogramSeries) GetName() string {
return hs.Name
}
// GetStyle implements Series.GetStyle.
func (hs HistogramSeries) GetStyle() Style {
return hs.Style
}
// GetYAxis returns which yaxis the series is mapped to.
2016-08-01 01:54:09 +02:00
func (hs HistogramSeries) GetYAxis() YAxisType {
2016-07-17 10:42:31 +02:00
return hs.YAxis
}
// Len implements BoundedValuesProvider.Len.
2016-07-17 10:42:31 +02:00
func (hs HistogramSeries) Len() int {
return hs.InnerSeries.Len()
}
// GetValues implements ValuesProvider.GetValues.
func (hs HistogramSeries) GetValues(index int) (x, y float64) {
return hs.InnerSeries.GetValues(index)
2016-07-17 10:42:31 +02:00
}
// GetBoundedValues implements BoundedValuesProvider.GetBoundedValue
func (hs HistogramSeries) GetBoundedValues(index int) (x, y1, y2 float64) {
vx, vy := hs.InnerSeries.GetValues(index)
2016-07-17 10:42:31 +02:00
x = vx
if vy > 0 {
y1 = vy
return
}
y2 = vy
return
}
// Render implements Series.Render.
func (hs HistogramSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
style := hs.Style.InheritFrom(defaults)
2016-07-30 01:36:29 +02:00
Draw.HistogramSeries(r, canvasBox, xrange, yrange, style, hs)
2016-07-17 10:42:31 +02:00
}
2017-02-03 20:26:53 +01:00
// Validate validates the series.
func (hs HistogramSeries) Validate() error {
if hs.InnerSeries == nil {
return fmt.Errorf("histogram series requires InnerSeries to be set")
}
return nil
}