Skip to content

Commit

Permalink
feat: support rounded rect for horizontal bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed May 21, 2024
1 parent 9b7634c commit 9614835
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions examples/horizontal_bar_chart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func main() {
"China",
"World",
}),
func(opt *charts.ChartOption) {
opt.SeriesList[0].RoundRadius = 5
},
)
if err != nil {
panic(err)
Expand Down
28 changes: 20 additions & 8 deletions horizontal_bar_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9614835

Please sign in to comment.