From e530adccb66738e41d8eb9c7d042e38d3221f869 Mon Sep 17 00:00:00 2001 From: vicanso Date: Thu, 28 Jul 2022 20:49:00 +0800 Subject: [PATCH] feat: support stroke width of line chart --- chart_option.go | 2 ++ charts.go | 9 +++++---- examples/line_chart/main.go | 1 + line_chart.go | 8 +++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/chart_option.go b/chart_option.go index 71e9dfc..58001bd 100644 --- a/chart_option.go +++ b/chart_option.go @@ -64,6 +64,8 @@ type ChartOption struct { BackgroundColor Color // The flag for show symbol of line, set this to *false will hide symbol SymbolShow *bool + // The stroke width of line chart + LineStrokeWidth float64 // The child charts Children []ChartOption } diff --git a/charts.go b/charts.go index 92a7e54..d65f3c9 100644 --- a/charts.go +++ b/charts.go @@ -377,10 +377,11 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) { if len(lineSeriesList) != 0 { handler.Add(func() error { _, err := NewLineChart(p, LineChartOption{ - Theme: opt.theme, - Font: opt.font, - XAxis: opt.XAxis, - SymbolShow: opt.SymbolShow, + Theme: opt.theme, + Font: opt.font, + XAxis: opt.XAxis, + SymbolShow: opt.SymbolShow, + StrokeWidth: opt.LineStrokeWidth, }).render(renderResult, lineSeriesList) return err }) diff --git a/examples/line_chart/main.go b/examples/line_chart/main.go index 5edf65b..36eabee 100644 --- a/examples/line_chart/main.go +++ b/examples/line_chart/main.go @@ -96,6 +96,7 @@ func main() { Bottom: 10, } opt.SymbolShow = charts.FalseFlag() + opt.LineStrokeWidth = 1 }, ) diff --git a/line_chart.go b/line_chart.go index dee122f..3942d70 100644 --- a/line_chart.go +++ b/line_chart.go @@ -62,6 +62,8 @@ type LineChartOption struct { Legend LegendOption // The flag for show symbol of line, set this to *false will hide symbol SymbolShow *bool + // The stroke width of line + StrokeWidth float64 // background is filled backgroundIsFilled bool } @@ -95,12 +97,16 @@ func (l *lineChart) render(result *defaultRenderResult, seriesList SeriesList) ( markPointPainter, markLinePainter, } + strokeWidth := opt.StrokeWidth + if strokeWidth == 0 { + strokeWidth = defaultStrokeWidth + } for index := range seriesList { series := seriesList[index] seriesColor := opt.Theme.GetSeriesColor(series.index) drawingStyle := Style{ StrokeColor: seriesColor, - StrokeWidth: defaultStrokeWidth, + StrokeWidth: strokeWidth, } seriesPainter.SetDrawingStyle(drawingStyle)