feat: support line chart render function

This commit is contained in:
vicanso 2022-06-12 11:55:37 +08:00
parent b394e1b49f
commit c4045cfbbe
11 changed files with 1012 additions and 46 deletions

View file

@ -22,7 +22,11 @@
package charts
import "github.com/wcharczuk/go-chart/v2/drawing"
import (
"github.com/golang/freetype/truetype"
"github.com/wcharczuk/go-chart/v2"
"github.com/wcharczuk/go-chart/v2/drawing"
)
const ThemeDark = "dark"
const ThemeLight = "light"
@ -36,6 +40,8 @@ type ColorPalette interface {
GetSeriesColor(int) Color
GetBackgroundColor() Color
GetTextColor() Color
GetFontSize() float64
GetFont() *truetype.Font
}
type themeColorPalette struct {
@ -45,10 +51,14 @@ type themeColorPalette struct {
backgroundColor Color
textColor Color
seriesColors []Color
fontSize float64
font *truetype.Font
}
var palettes = map[string]ColorPalette{}
const defaultFontSize = 12.0
func init() {
echartSeriesColors := []Color{
parseColor("#5470c6"),
@ -233,3 +243,18 @@ func (t *themeColorPalette) GetBackgroundColor() Color {
func (t *themeColorPalette) GetTextColor() Color {
return t.textColor
}
func (t *themeColorPalette) GetFontSize() float64 {
if t.fontSize != 0 {
return t.fontSize
}
return defaultFontSize
}
func (t *themeColorPalette) GetFont() *truetype.Font {
if t.font != nil {
return t.font
}
f, _ := chart.GetDefaultFont()
return f
}