test: add test for legend, series and theme
This commit is contained in:
parent
a128a2513c
commit
c289ba7cde
11 changed files with 828 additions and 43 deletions
61
theme.go
61
theme.go
|
|
@ -23,6 +23,8 @@
|
|||
package charts
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/wcharczuk/go-chart/v2"
|
||||
|
|
@ -44,6 +46,20 @@ var AxisColorDark = drawing.Color{
|
|||
A: 255,
|
||||
}
|
||||
|
||||
var GridColorDark = drawing.Color{
|
||||
R: 72,
|
||||
G: 71,
|
||||
B: 83,
|
||||
A: 255,
|
||||
}
|
||||
|
||||
var GridColorLight = drawing.Color{
|
||||
R: 224,
|
||||
G: 230,
|
||||
B: 241,
|
||||
A: 255,
|
||||
}
|
||||
|
||||
var BackgroundColorDark = drawing.Color{
|
||||
R: 16,
|
||||
G: 12,
|
||||
|
|
@ -67,19 +83,9 @@ func getAxisColor(theme string) drawing.Color {
|
|||
|
||||
func getGridColor(theme string) drawing.Color {
|
||||
if theme == ThemeDark {
|
||||
return drawing.Color{
|
||||
R: 72,
|
||||
G: 71,
|
||||
B: 83,
|
||||
A: 255,
|
||||
}
|
||||
}
|
||||
return drawing.Color{
|
||||
R: 224,
|
||||
G: 230,
|
||||
B: 241,
|
||||
A: 255,
|
||||
return GridColorDark
|
||||
}
|
||||
return GridColorLight
|
||||
}
|
||||
|
||||
var SeriesColorsLight = []drawing.Color{
|
||||
|
|
@ -180,12 +186,37 @@ func getSeriesColor(theme string, index int) drawing.Color {
|
|||
}
|
||||
|
||||
func parseColor(color string) drawing.Color {
|
||||
c := drawing.Color{}
|
||||
if color == "" {
|
||||
return drawing.Color{}
|
||||
return c
|
||||
}
|
||||
if strings.HasPrefix(color, "#") {
|
||||
return drawing.ColorFromHex(color[1:])
|
||||
}
|
||||
// TODO rgba
|
||||
return drawing.Color{}
|
||||
reg := regexp.MustCompile(`\((\S+)\)`)
|
||||
result := reg.FindAllStringSubmatch(color, 1)
|
||||
if len(result) == 0 || len(result[0]) != 2 {
|
||||
return c
|
||||
}
|
||||
arr := strings.Split(result[0][1], ",")
|
||||
if len(arr) < 3 {
|
||||
return c
|
||||
}
|
||||
// 设置默认为255
|
||||
c.A = 255
|
||||
for index, v := range arr {
|
||||
value, _ := strconv.Atoi(strings.TrimSpace(v))
|
||||
ui8 := uint8(value)
|
||||
switch index {
|
||||
case 0:
|
||||
c.R = ui8
|
||||
case 1:
|
||||
c.G = ui8
|
||||
case 2:
|
||||
c.B = ui8
|
||||
default:
|
||||
c.A = ui8
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue