snapshot.
This commit is contained in:
parent
7bb82ae691
commit
e9a36274ac
23 changed files with 551 additions and 445 deletions
|
|
@ -1,17 +1,13 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/blendlabs/go-util"
|
||||
)
|
||||
import "time"
|
||||
|
||||
// TimeSeries is a line on a chart.
|
||||
type TimeSeries struct {
|
||||
Name string
|
||||
Style Style
|
||||
FinalValueLabel Style
|
||||
Name string
|
||||
Style Style
|
||||
|
||||
YAxis YAxisType
|
||||
|
||||
XValues []time.Time
|
||||
YValues []float64
|
||||
|
|
@ -32,6 +28,11 @@ func (ts TimeSeries) Len() int {
|
|||
return len(ts.XValues)
|
||||
}
|
||||
|
||||
// GetYAxis returns which YAxis the series draws on.
|
||||
func (ts TimeSeries) GetYAxis() YAxisType {
|
||||
return ts.YAxis
|
||||
}
|
||||
|
||||
// GetValue gets a value at a given index.
|
||||
func (ts TimeSeries) GetValue(index int) (x float64, y float64) {
|
||||
x = float64(ts.XValues[index].Unix())
|
||||
|
|
@ -39,28 +40,8 @@ func (ts TimeSeries) GetValue(index int) (x float64, y float64) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetXFormatter returns the x value formatter.
|
||||
func (ts TimeSeries) GetXFormatter() Formatter {
|
||||
return func(v interface{}) string {
|
||||
if typed, isTyped := v.(time.Time); isTyped {
|
||||
return typed.Format(DefaultDateFormat)
|
||||
}
|
||||
if typed, isTyped := v.(int64); isTyped {
|
||||
return time.Unix(typed, 0).Format(DefaultDateFormat)
|
||||
}
|
||||
if typed, isTyped := v.(float64); isTyped {
|
||||
return time.Unix(int64(typed), 0).Format(DefaultDateFormat)
|
||||
}
|
||||
return util.StringEmpty
|
||||
}
|
||||
}
|
||||
|
||||
// GetYFormatter returns the y value formatter.
|
||||
func (ts TimeSeries) GetYFormatter() Formatter {
|
||||
return func(v interface{}) string {
|
||||
if typed, isTyped := v.(float64); isTyped {
|
||||
return fmt.Sprintf("%0.2f", typed)
|
||||
}
|
||||
return util.StringEmpty
|
||||
}
|
||||
// Render renders the series.
|
||||
func (ts TimeSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
|
||||
style := ts.Style.WithDefaultsFrom(defaults)
|
||||
DrawLineSeries(r, canvasBox, xrange, yrange, style, ts)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue