2016-07-09 23:14:11 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
// ContinuousSeries represents a line on a chart.
|
|
|
|
type ContinuousSeries struct {
|
2016-07-10 04:11:47 -04:00
|
|
|
Name string
|
|
|
|
Style Style
|
|
|
|
|
2016-07-31 19:54:09 -04:00
|
|
|
YAxis YAxisType
|
2016-07-09 23:14:11 -04:00
|
|
|
|
2017-01-13 19:03:45 -05:00
|
|
|
XValueFormatter ValueFormatter
|
|
|
|
YValueFormatter ValueFormatter
|
|
|
|
|
2016-07-09 23:14:11 -04:00
|
|
|
XValues []float64
|
|
|
|
YValues []float64
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetName returns the name of the time series.
|
|
|
|
func (cs ContinuousSeries) GetName() string {
|
|
|
|
return cs.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStyle returns the line style.
|
|
|
|
func (cs ContinuousSeries) GetStyle() Style {
|
|
|
|
return cs.Style
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len returns the number of elements in the series.
|
|
|
|
func (cs ContinuousSeries) Len() int {
|
|
|
|
return len(cs.XValues)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetValue gets a value at a given index.
|
|
|
|
func (cs ContinuousSeries) GetValue(index int) (float64, float64) {
|
|
|
|
return cs.XValues[index], cs.YValues[index]
|
|
|
|
}
|
|
|
|
|
2016-07-18 15:57:10 -04:00
|
|
|
// GetLastValue gets the last value.
|
|
|
|
func (cs ContinuousSeries) GetLastValue() (float64, float64) {
|
|
|
|
return cs.XValues[len(cs.XValues)-1], cs.YValues[len(cs.YValues)-1]
|
|
|
|
}
|
|
|
|
|
2016-07-10 13:43:04 -04:00
|
|
|
// GetValueFormatters returns value formatter defaults for the series.
|
|
|
|
func (cs ContinuousSeries) GetValueFormatters() (x, y ValueFormatter) {
|
2017-01-13 19:03:45 -05:00
|
|
|
if cs.XValueFormatter != nil {
|
|
|
|
x = cs.XValueFormatter
|
|
|
|
} else {
|
|
|
|
x = FloatValueFormatter
|
|
|
|
}
|
|
|
|
if cs.YValueFormatter != nil {
|
|
|
|
y = cs.YValueFormatter
|
|
|
|
} else {
|
|
|
|
y = FloatValueFormatter
|
|
|
|
}
|
2016-07-10 13:43:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetYAxis returns which YAxis the series draws on.
|
2016-07-31 19:54:09 -04:00
|
|
|
func (cs ContinuousSeries) GetYAxis() YAxisType {
|
2016-07-10 13:43:04 -04:00
|
|
|
return cs.YAxis
|
|
|
|
}
|
|
|
|
|
2016-07-09 23:14:11 -04:00
|
|
|
// Render renders the series.
|
2016-07-10 04:11:47 -04:00
|
|
|
func (cs ContinuousSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
|
2016-07-21 17:11:27 -04:00
|
|
|
style := cs.Style.InheritFrom(defaults)
|
2016-07-29 19:36:29 -04:00
|
|
|
Draw.LineSeries(r, canvasBox, xrange, yrange, style, cs)
|
2016-07-09 23:14:11 -04:00
|
|
|
}
|