2016-07-10 10:11:47 +02:00
|
|
|
package chart
|
|
|
|
|
|
|
|
// Annotation is a label on the chart.
|
|
|
|
type Annotation struct {
|
|
|
|
X, Y float64
|
|
|
|
Label string
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnnotationSeries is a series of labels on the chart.
|
|
|
|
type AnnotationSeries struct {
|
|
|
|
Name string
|
|
|
|
Style Style
|
|
|
|
YAxis YAxisType
|
|
|
|
Annotations []Annotation
|
|
|
|
}
|
|
|
|
|
2016-07-10 19:43:04 +02:00
|
|
|
// GetName returns the name of the time series.
|
|
|
|
func (as AnnotationSeries) GetName() string {
|
|
|
|
return as.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStyle returns the line style.
|
|
|
|
func (as AnnotationSeries) GetStyle() Style {
|
|
|
|
return as.Style
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetYAxis returns which YAxis the series draws on.
|
|
|
|
func (as AnnotationSeries) GetYAxis() YAxisType {
|
|
|
|
return as.YAxis
|
|
|
|
}
|
|
|
|
|
2016-07-10 10:11:47 +02:00
|
|
|
// Render draws the series.
|
2016-07-10 19:43:04 +02:00
|
|
|
func (as AnnotationSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
|
2016-07-10 10:11:47 +02:00
|
|
|
if as.Style.Show {
|
2016-07-10 19:43:04 +02:00
|
|
|
style := as.Style.WithDefaultsFrom(Style{
|
|
|
|
FillColor: DefaultAnnotationFillColor,
|
|
|
|
FontSize: DefaultAnnotationFontSize,
|
|
|
|
StrokeColor: defaults.StrokeColor,
|
|
|
|
StrokeWidth: defaults.StrokeWidth,
|
|
|
|
Padding: DefaultAnnotationPadding,
|
|
|
|
})
|
2016-07-10 10:11:47 +02:00
|
|
|
for _, a := range as.Annotations {
|
2016-07-10 19:43:04 +02:00
|
|
|
lx := canvasBox.Right - xrange.Translate(a.X)
|
2016-07-10 10:11:47 +02:00
|
|
|
ly := yrange.Translate(a.Y) + canvasBox.Top
|
2016-07-10 19:43:04 +02:00
|
|
|
DrawAnnotation(r, canvasBox, xrange, yrange, style, lx, ly, a.Label)
|
2016-07-10 10:11:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|