diff --git a/_examples/stock_analysis/main.go b/_examples/stock_analysis/main.go index 9e28889..a8bd5a9 100644 --- a/_examples/stock_analysis/main.go +++ b/_examples/stock_analysis/main.go @@ -14,7 +14,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) { priceSeries := chart.TimeSeries{ Name: "SPY", Style: chart.Style{ - Show: true, StrokeColor: chart.GetDefaultColor(0), }, XValues: xv, @@ -24,7 +23,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) { smaSeries := chart.SMASeries{ Name: "SPY - SMA", Style: chart.Style{ - Show: true, StrokeColor: drawing.ColorRed, StrokeDashArray: []float64{5.0, 5.0}, }, @@ -34,7 +32,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) { bbSeries := &chart.BollingerBandsSeries{ Name: "SPY - Bol. Bands", Style: chart.Style{ - Show: true, StrokeColor: drawing.ColorFromHex("efefef"), FillColor: drawing.ColorFromHex("efefef").WithAlpha(64), }, @@ -43,11 +40,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.StyleShow(), TickPosition: chart.TickPositionBetweenTicks, }, YAxis: chart.YAxis{ - Style: chart.StyleShow(), Range: &chart.ContinuousRange{ Max: 220.0, Min: 180.0, diff --git a/bounded_last_values_annotation_series.go b/bounded_last_values_annotation_series.go new file mode 100644 index 0000000..670ddf7 --- /dev/null +++ b/bounded_last_values_annotation_series.go @@ -0,0 +1,36 @@ +package chart + +import "fmt" + +// BoundedLastValuesAnnotationSeries returns a last value annotation series for a bounded values provider. +func BoundedLastValuesAnnotationSeries(innerSeries FullBoundedValuesProvider, vfs ...ValueFormatter) AnnotationSeries { + lvx, lvy1, lvy2 := innerSeries.GetBoundedLastValues() + + var vf ValueFormatter + if len(vfs) > 0 { + vf = vfs[0] + } else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped { + _, vf = typed.GetValueFormatters() + } else { + vf = FloatValueFormatter + } + + label1 := vf(lvy1) + label2 := vf(lvy2) + + var seriesName string + var seriesStyle Style + if typed, isTyped := innerSeries.(Series); isTyped { + seriesName = fmt.Sprintf("%s - Last Values", typed.GetName()) + seriesStyle = typed.GetStyle() + } + + return AnnotationSeries{ + Name: seriesName, + Style: seriesStyle, + Annotations: []Value2{ + {XValue: lvx, YValue: lvy1, Label: label1}, + {XValue: lvx, YValue: lvy2, Label: label2}, + }, + } +} diff --git a/value_formatter.go b/value_formatter.go index 19e0370..468f3bd 100644 --- a/value_formatter.go +++ b/value_formatter.go @@ -96,3 +96,10 @@ func FloatValueFormatterWithFormat(v interface{}, floatFormat string) string { } return "" } + +// KValueFormatter is a formatter for K values. +func KValueFormatter(k float64, vf ValueFormatter) ValueFormatter { + return func(v interface{}) string { + return fmt.Sprintf("%0.0fσ %s", k, vf(v)) + } +}