From 96148357237a4698910b58e780f6a2fe095a4cfe Mon Sep 17 00:00:00 2001 From: vicanso Date: Tue, 21 May 2024 20:26:40 +0800 Subject: [PATCH] feat: support rounded rect for horizontal bar chart --- examples/horizontal_bar_chart/main.go | 3 +++ horizontal_bar_chart.go | 28 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/examples/horizontal_bar_chart/main.go b/examples/horizontal_bar_chart/main.go index f2cabe8..a7daa8c 100644 --- a/examples/horizontal_bar_chart/main.go +++ b/examples/horizontal_bar_chart/main.go @@ -65,6 +65,9 @@ func main() { "China", "World", }), + func(opt *charts.ChartOption) { + opt.SeriesList[0].RoundRadius = 5 + }, ) if err != nil { panic(err) diff --git a/horizontal_bar_chart.go b/horizontal_bar_chart.go index 2ab4c03..ca91242 100644 --- a/horizontal_bar_chart.go +++ b/horizontal_bar_chart.go @@ -136,14 +136,26 @@ func (h *horizontalBarChart) render(result *defaultRenderResult, seriesList Seri fillColor = item.Style.FillColor } right := w - seriesPainter.OverrideDrawingStyle(Style{ - FillColor: fillColor, - }).Rect(chart.Box{ - Top: y, - Left: 0, - Right: right, - Bottom: y + barHeight, - }) + if series.RoundRadius <= 0 { + seriesPainter.OverrideDrawingStyle(Style{ + FillColor: fillColor, + }).Rect(chart.Box{ + Top: y, + Left: 0, + Right: right, + Bottom: y + barHeight, + }) + } else { + seriesPainter.OverrideDrawingStyle(Style{ + FillColor: fillColor, + }).RoundedRect(chart.Box{ + Top: y, + Left: 0, + Right: right, + Bottom: y + barHeight, + }, series.RoundRadius) + } + // 如果label不需要展示,则返回 if labelPainter == nil { continue