snapshot.
This commit is contained in:
parent
7bb82ae691
commit
e9a36274ac
23 changed files with 551 additions and 445 deletions
|
|
@ -1,16 +1,11 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/blendlabs/go-util"
|
||||
)
|
||||
|
||||
// ContinuousSeries represents a line on a chart.
|
||||
type ContinuousSeries struct {
|
||||
Name string
|
||||
Style Style
|
||||
FinalValueLabel Style
|
||||
Name string
|
||||
Style Style
|
||||
|
||||
YAxis YAxisType
|
||||
|
||||
XValues []float64
|
||||
YValues []float64
|
||||
|
|
@ -36,35 +31,8 @@ func (cs ContinuousSeries) GetValue(index int) (float64, float64) {
|
|||
return cs.XValues[index], cs.YValues[index]
|
||||
}
|
||||
|
||||
// GetXFormatter returns the xs value formatter.
|
||||
func (cs ContinuousSeries) GetXFormatter() Formatter {
|
||||
return func(v interface{}) string {
|
||||
if typed, isTyped := v.(float64); isTyped {
|
||||
return fmt.Sprintf("%0.2f", typed)
|
||||
}
|
||||
return util.StringEmpty
|
||||
}
|
||||
}
|
||||
|
||||
// GetYFormatter returns the y value formatter.
|
||||
func (cs ContinuousSeries) GetYFormatter() Formatter {
|
||||
return cs.GetXFormatter()
|
||||
}
|
||||
|
||||
// Render renders the series.
|
||||
func (cs ContinuousSeries) Render(c *Chart, r Renderer, canvasBox Box, xrange, yrange Range) error {
|
||||
DrawLineSeries(c, r, canvasBox, xrange, yrange, cs)
|
||||
|
||||
if cs.FinalValueLabel.Show {
|
||||
asw := 0
|
||||
if c.Axes.Show {
|
||||
asw = int(c.Axes.GetStrokeWidth(DefaultAxisLineWidth))
|
||||
}
|
||||
|
||||
_, lv := cs.GetValue(cs.Len() - 1)
|
||||
ll := yrange.Format(lv)
|
||||
lx := canvasBox.Right + asw
|
||||
ly := yrange.Translate(lv) + canvasBox.Top
|
||||
DrawAnnotation(c, r, canvasBox, xrange, yrange, cs.FinalValueLabel, lx, ly, ll)
|
||||
}
|
||||
func (cs ContinuousSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
|
||||
style := cs.Style.WithDefaultsFrom(defaults)
|
||||
DrawLineSeries(r, canvasBox, xrange, yrange, style, cs)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue