diff --git a/charts.go b/charts.go index 7cabd7f..1657e6d 100644 --- a/charts.go +++ b/charts.go @@ -51,6 +51,7 @@ type ( Padding chart.Box } Options struct { + Padding chart.Box Width int Height int Theme string @@ -112,6 +113,9 @@ func New(opt Options) (Graph, error) { if height <= 0 { height = DefaultChartHeight } + bg := chart.Style{ + Padding: opt.Padding, + } if opt.Series[0].Type == SeriesPie { values := make(chart.Values, len(opt.Series)) for index, item := range opt.Series { @@ -121,13 +125,16 @@ func New(opt Options) (Graph, error) { } } g := &chart.PieChart{ + Background: bg, Title: opt.Title.Text, TitleStyle: opt.Title.Style, Width: width, Height: height, Values: values, - ColorPalette: &ThemeColorPalette{ - Theme: opt.Theme, + ColorPalette: &PieThemeColorPalette{ + ThemeColorPalette: ThemeColorPalette{ + Theme: opt.Theme, + }, }, } return g, nil @@ -158,7 +165,8 @@ func New(opt Options) (Graph, error) { } g := &chart.Chart{ - Log: opt.Log, + Log: opt.Log, + Background: bg, ColorPalette: &ThemeColorPalette{ Theme: opt.Theme, }, diff --git a/echarts.go b/echarts.go index d8625af..a7ce31b 100644 --- a/echarts.go +++ b/echarts.go @@ -160,8 +160,9 @@ func (ex *EChartsXAxis) UnmarshalJSON(data []byte) error { } type ECharsOptions struct { - Theme string `json:"theme"` - Title struct { + Theme string `json:"theme"` + Padding EChartsPadding `json:"padding"` + Title struct { Text string `json:"text"` // 暂不支持(go-chart默认title只能居中) TextAlign string `json:"textAlign"` @@ -238,8 +239,10 @@ func convertEChartsSeries(e *ECharsOptions) ([]Series, chart.TickPosition) { func (e *ECharsOptions) ToOptions() Options { o := Options{ - Theme: e.Theme, + Theme: e.Theme, + Padding: e.Padding.box, } + titleTextStyle := e.Title.TextStyle o.Title = Title{ Text: e.Title.Text, diff --git a/theme.go b/theme.go index efbdf4a..2c561ad 100644 --- a/theme.go +++ b/theme.go @@ -133,6 +133,14 @@ type ThemeColorPalette struct { Theme string } +type PieThemeColorPalette struct { + ThemeColorPalette +} + +func (tp PieThemeColorPalette) TextColor() drawing.Color { + return getTextColor("") +} + func (tp ThemeColorPalette) BackgroundColor() drawing.Color { return getBackgroundColor(tp.Theme) }