Support timeline
This commit is contained in:
parent
406d35c6a6
commit
a1f58d4315
9 changed files with 246 additions and 22 deletions
55
mark_line.go
55
mark_line.go
|
|
@ -24,6 +24,7 @@ package charts
|
|||
|
||||
import (
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/wcharczuk/go-chart/v2"
|
||||
)
|
||||
|
||||
// NewMarkLine returns a series mark line
|
||||
|
|
@ -63,6 +64,7 @@ type markLineRenderOption struct {
|
|||
Font *truetype.Font
|
||||
Series Series
|
||||
Range axisRange
|
||||
Points []Point
|
||||
}
|
||||
|
||||
func (m *markLinePainter) Render() (Box, error) {
|
||||
|
|
@ -93,14 +95,23 @@ func (m *markLinePainter) Render() (Box, error) {
|
|||
fontColor = *markLine.FontColor
|
||||
}
|
||||
|
||||
painter.OverrideDrawingStyle(Style{
|
||||
FillColor: fillColor,
|
||||
StrokeColor: strokeColor,
|
||||
StrokeWidth: 1,
|
||||
StrokeDashArray: []float64{
|
||||
strokeWidth := float64(1)
|
||||
if markLine.StrokeWidth != 0 {
|
||||
strokeWidth = markLine.StrokeWidth
|
||||
}
|
||||
|
||||
var strokeDashArray []float64
|
||||
if !markLine.IgnoreStrokeDashed {
|
||||
strokeDashArray = []float64{
|
||||
4,
|
||||
2,
|
||||
},
|
||||
}
|
||||
}
|
||||
painter.OverrideDrawingStyle(Style{
|
||||
FillColor: fillColor,
|
||||
StrokeColor: strokeColor,
|
||||
StrokeWidth: strokeWidth,
|
||||
StrokeDashArray: strokeDashArray,
|
||||
}).OverrideTextStyle(Style{
|
||||
Font: font,
|
||||
FontColor: fontColor,
|
||||
|
|
@ -121,8 +132,36 @@ func (m *markLinePainter) Render() (Box, error) {
|
|||
width := painter.Width()
|
||||
text := commafWithDigits(value)
|
||||
textBox := painter.MeasureText(text)
|
||||
painter.MarkLine(0, y, width-2)
|
||||
painter.Text(text, width, y+textBox.Height()>>1-2)
|
||||
endOffset := 2
|
||||
if markLine.IgnoreArrow {
|
||||
endOffset = 0
|
||||
}
|
||||
xPoint := 0
|
||||
if markLine.XAxisIndex > 0 {
|
||||
xPoint = opt.Points[markLine.XAxisIndex].X
|
||||
}
|
||||
xAxiesEndIndex := width
|
||||
if markLine.XAxisEndIndex > 0 {
|
||||
xAxiesEndIndex = opt.Points[markLine.XAxisEndIndex].X
|
||||
}
|
||||
painter.MarkLine(xPoint, y, xAxiesEndIndex-endOffset-xPoint, markLine.IgnoreArrow)
|
||||
if !markLine.HideValue {
|
||||
painter.Text(text, width, y+textBox.Height()>>1-2)
|
||||
}
|
||||
|
||||
if markLine.AboveColor != nil {
|
||||
painter.OverrideDrawingStyle(Style{
|
||||
FillColor: *markLine.AboveColor,
|
||||
})
|
||||
painter.Rect(chart.NewBox(y, 0, width, 0))
|
||||
}
|
||||
|
||||
if markLine.BelowColor != nil {
|
||||
painter.OverrideDrawingStyle(Style{
|
||||
FillColor: *markLine.BelowColor,
|
||||
})
|
||||
painter.Rect(chart.NewBox(opt.Range.size, 0, width, y))
|
||||
}
|
||||
}
|
||||
}
|
||||
return BoxZero, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue