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()
|
summary := s.Summary()
|
||||||
for _, markLine := range s.MarkLine.Data {
|
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{
|
painter.OverrideDrawingStyle(Style{
|
||||||
FillColor: opt.FillColor,
|
FillColor: fillColor,
|
||||||
StrokeColor: opt.StrokeColor,
|
StrokeColor: strokeColor,
|
||||||
StrokeWidth: 1,
|
StrokeWidth: 1,
|
||||||
StrokeDashArray: []float64{
|
StrokeDashArray: []float64{
|
||||||
4,
|
4,
|
||||||
|
|
@ -89,7 +103,7 @@ func (m *markLinePainter) Render() (Box, error) {
|
||||||
},
|
},
|
||||||
}).OverrideTextStyle(Style{
|
}).OverrideTextStyle(Style{
|
||||||
Font: font,
|
Font: font,
|
||||||
FontColor: opt.FontColor,
|
FontColor: fontColor,
|
||||||
FontSize: labelFontSize,
|
FontSize: labelFontSize,
|
||||||
})
|
})
|
||||||
value := float64(0)
|
value := float64(0)
|
||||||
|
|
@ -98,6 +112,8 @@ func (m *markLinePainter) Render() (Box, error) {
|
||||||
value = summary.MaxValue
|
value = summary.MaxValue
|
||||||
case SeriesMarkDataTypeMin:
|
case SeriesMarkDataTypeMin:
|
||||||
value = summary.MinValue
|
value = summary.MinValue
|
||||||
|
case SeriesMarkDataTypeCustom:
|
||||||
|
value = markLine.CustomYVal
|
||||||
default:
|
default:
|
||||||
value = summary.AverageValue
|
value = summary.AverageValue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,25 @@ func (m *markPointPainter) Render() (Box, error) {
|
||||||
StrokeWidth: 1,
|
StrokeWidth: 1,
|
||||||
Font: opt.Font,
|
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 {
|
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
|
textStyle.FontSize = labelFontSize
|
||||||
painter.OverrideTextStyle(textStyle)
|
painter.OverrideTextStyle(textStyle)
|
||||||
p := points[summary.MinIndex]
|
p := points[summary.MinIndex]
|
||||||
|
|
@ -98,6 +108,9 @@ func (m *markPointPainter) Render() (Box, error) {
|
||||||
case SeriesMarkDataTypeMax:
|
case SeriesMarkDataTypeMax:
|
||||||
p = points[summary.MaxIndex]
|
p = points[summary.MaxIndex]
|
||||||
value = summary.MaxValue
|
value = summary.MaxValue
|
||||||
|
case SeriesMarkDataTypeCustom:
|
||||||
|
p = points[markPointData.XAxisIndex]
|
||||||
|
value = markPointData.CustomYVal
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.Pin(p.X, p.Y-symbolSize>>1, symbolSize)
|
painter.Pin(p.X, p.Y-symbolSize>>1, symbolSize)
|
||||||
|
|
|
||||||
|
|
@ -91,12 +91,20 @@ const (
|
||||||
SeriesMarkDataTypeMax = "max"
|
SeriesMarkDataTypeMax = "max"
|
||||||
SeriesMarkDataTypeMin = "min"
|
SeriesMarkDataTypeMin = "min"
|
||||||
SeriesMarkDataTypeAverage = "average"
|
SeriesMarkDataTypeAverage = "average"
|
||||||
|
SeriesMarkDataTypeCustom = "custom"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SeriesMarkData struct {
|
type SeriesMarkData struct {
|
||||||
// The mark data type, it can be "max", "min", "average".
|
// The mark data type, it can be "max", "min", "average".
|
||||||
// The "average" is only for mark line
|
// The "average" is only for mark line
|
||||||
Type string
|
Type string
|
||||||
|
|
||||||
|
// Custom options.
|
||||||
|
XAxisIndex int
|
||||||
|
CustomYVal float64
|
||||||
|
FillColor *Color
|
||||||
|
StrokeColor *Color
|
||||||
|
FontColor *Color
|
||||||
}
|
}
|
||||||
type SeriesMarkPoint struct {
|
type SeriesMarkPoint struct {
|
||||||
// The width of symbol, default value is 30
|
// The width of symbol, default value is 30
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue