Support custom annotation
This commit is contained in:
parent
d25a827706
commit
406d35c6a6
3 changed files with 49 additions and 12 deletions
24
mark_line.go
24
mark_line.go
|
|
@ -78,10 +78,24 @@ func (m *markLinePainter) Render() (Box, error) {
|
|||
}
|
||||
summary := s.Summary()
|
||||
for _, markLine := range s.MarkLine.Data {
|
||||
// 由于mark line会修改style,因此每次重新设置
|
||||
fillColor := opt.FillColor
|
||||
if markLine.FillColor != nil {
|
||||
fillColor = *markLine.FillColor
|
||||
}
|
||||
|
||||
strokeColor := opt.StrokeColor
|
||||
if markLine.StrokeColor != nil {
|
||||
strokeColor = *markLine.StrokeColor
|
||||
}
|
||||
|
||||
fontColor := opt.FontColor
|
||||
if markLine.FontColor != nil {
|
||||
fontColor = *markLine.FontColor
|
||||
}
|
||||
|
||||
painter.OverrideDrawingStyle(Style{
|
||||
FillColor: opt.FillColor,
|
||||
StrokeColor: opt.StrokeColor,
|
||||
FillColor: fillColor,
|
||||
StrokeColor: strokeColor,
|
||||
StrokeWidth: 1,
|
||||
StrokeDashArray: []float64{
|
||||
4,
|
||||
|
|
@ -89,7 +103,7 @@ func (m *markLinePainter) Render() (Box, error) {
|
|||
},
|
||||
}).OverrideTextStyle(Style{
|
||||
Font: font,
|
||||
FontColor: opt.FontColor,
|
||||
FontColor: fontColor,
|
||||
FontSize: labelFontSize,
|
||||
})
|
||||
value := float64(0)
|
||||
|
|
@ -98,6 +112,8 @@ func (m *markLinePainter) Render() (Box, error) {
|
|||
value = summary.MaxValue
|
||||
case SeriesMarkDataTypeMin:
|
||||
value = summary.MinValue
|
||||
case SeriesMarkDataTypeCustom:
|
||||
value = markLine.CustomYVal
|
||||
default:
|
||||
value = summary.AverageValue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,15 +81,25 @@ func (m *markPointPainter) Render() (Box, error) {
|
|||
StrokeWidth: 1,
|
||||
Font: opt.Font,
|
||||
}
|
||||
if isLightColor(opt.FillColor) {
|
||||
textStyle.FontColor = defaultLightFontColor
|
||||
} else {
|
||||
textStyle.FontColor = defaultDarkFontColor
|
||||
}
|
||||
painter.OverrideDrawingStyle(Style{
|
||||
FillColor: opt.FillColor,
|
||||
}).OverrideTextStyle(textStyle)
|
||||
for _, markPointData := range s.MarkPoint.Data {
|
||||
fillColor := opt.FillColor
|
||||
if markPointData.FillColor != nil {
|
||||
fillColor = *markPointData.FillColor
|
||||
}
|
||||
|
||||
if markPointData.FontColor != nil {
|
||||
textStyle.FontColor = *markPointData.FontColor
|
||||
} else {
|
||||
if isLightColor(fillColor) {
|
||||
textStyle.FontColor = defaultLightFontColor
|
||||
} else {
|
||||
textStyle.FontColor = defaultDarkFontColor
|
||||
}
|
||||
}
|
||||
|
||||
painter.OverrideDrawingStyle(Style{
|
||||
FillColor: fillColor,
|
||||
}).OverrideTextStyle(textStyle)
|
||||
textStyle.FontSize = labelFontSize
|
||||
painter.OverrideTextStyle(textStyle)
|
||||
p := points[summary.MinIndex]
|
||||
|
|
@ -98,6 +108,9 @@ func (m *markPointPainter) Render() (Box, error) {
|
|||
case SeriesMarkDataTypeMax:
|
||||
p = points[summary.MaxIndex]
|
||||
value = summary.MaxValue
|
||||
case SeriesMarkDataTypeCustom:
|
||||
p = points[markPointData.XAxisIndex]
|
||||
value = markPointData.CustomYVal
|
||||
}
|
||||
|
||||
painter.Pin(p.X, p.Y-symbolSize>>1, symbolSize)
|
||||
|
|
|
|||
|
|
@ -91,12 +91,20 @@ const (
|
|||
SeriesMarkDataTypeMax = "max"
|
||||
SeriesMarkDataTypeMin = "min"
|
||||
SeriesMarkDataTypeAverage = "average"
|
||||
SeriesMarkDataTypeCustom = "custom"
|
||||
)
|
||||
|
||||
type SeriesMarkData struct {
|
||||
// The mark data type, it can be "max", "min", "average".
|
||||
// The "average" is only for mark line
|
||||
Type string
|
||||
|
||||
// Custom options.
|
||||
XAxisIndex int
|
||||
CustomYVal float64
|
||||
FillColor *Color
|
||||
StrokeColor *Color
|
||||
FontColor *Color
|
||||
}
|
||||
type SeriesMarkPoint struct {
|
||||
// The width of symbol, default value is 30
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue