go-chart/series.go
Will Charczuk e09aa43a1e updates.
2016-07-06 21:12:19 -07:00

93 lines
2.0 KiB
Go

package chart
import "time"
// Series is a entity data set.
type Series interface {
GetName() string
GetStyle() Style
Len() int
GetValue(index int) (interface{}, float64)
GetXRange(domain int) Range
GetYRange(domain int) Range
}
// TimeSeries is a line on a chart.
type TimeSeries struct {
Name string
Style Style
XValues []time.Time
YValues []float64
}
// GetName returns the name of the time series.
func (ts TimeSeries) GetName() string {
return ts.Name
}
// GetStyle returns the line style.
func (ts TimeSeries) GetStyle() Style {
return ts.Style
}
// Len returns the number of elements in the series.
func (ts TimeSeries) Len() int {
return len(ts.XValues)
}
// GetXRange returns the x range.
func (ts TimeSeries) GetXRange(domain int) Range {
return NewRangeOfTime(domain, ts.XValues...)
}
// GetYRange returns the x range.
func (ts TimeSeries) GetYRange(domain int) Range {
return NewRangeOfFloat64(domain, ts.YValues...)
}
// GetValue gets a value at a given index.
func (ts TimeSeries) GetValue(index int) (interface{}, float64) {
return ts.XValues[index], ts.YValues[index]
}
// ContinousSeries represents a line on a chart.
type ContinousSeries struct {
Name string
Style Style
XValues []float64
YValues []float64
}
// GetName returns the name of the time series.
func (cs ContinousSeries) GetName() string {
return cs.Name
}
// GetStyle returns the line style.
func (cs ContinousSeries) GetStyle() Style {
return cs.Style
}
// Len returns the number of elements in the series.
func (cs ContinousSeries) Len() int {
return len(cs.XValues)
}
// GetValue gets a value at a given index.
func (cs ContinousSeries) GetValue(index int) (interface{}, float64) {
return cs.XValues[index], cs.YValues[index]
}
// GetXRange returns the x range.
func (cs ContinousSeries) GetXRange(domain int) Range {
return NewRangeOfFloat64(domain, cs.XValues...)
}
// GetYRange returns the x range.
func (cs ContinousSeries) GetYRange(domain int) Range {
return NewRangeOfFloat64(domain, cs.YValues...)
}