feat: support detect color dark or light

This commit is contained in:
vicanso 2022-11-16 20:46:19 +08:00
parent a42d0727df
commit 55eca7b0b9
6 changed files with 59 additions and 9 deletions

View file

@ -24,7 +24,6 @@ package charts
import (
"github.com/golang/freetype/truetype"
"github.com/wcharczuk/go-chart/v2/drawing"
)
// NewMarkPoint returns a series mark point
@ -78,16 +77,15 @@ func (m *markPointPainter) Render() (Box, error) {
symbolSize = 30
}
textStyle := Style{
FontColor: drawing.Color{
R: 238,
G: 238,
B: 238,
A: 255,
},
FontSize: labelFontSize,
StrokeWidth: 1,
Font: opt.Font,
}
if isLightColor(opt.FillColor) {
textStyle.FontColor = defaultLightFontColor
} else {
textStyle.FontColor = defaultDarkFontColor
}
painter.OverrideDrawingStyle(Style{
FillColor: opt.FillColor,
}).OverrideTextStyle(textStyle)