From c0a28857d32df6870ade91b5ec0d98fdc43230a0 Mon Sep 17 00:00:00 2001 From: Anurag1428 <129275842+Anurag1428@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:31:29 +0530 Subject: [PATCH] fix(bar): recreate polar bars when the base axis changes between radius and angle with roundCap. close #21878 --- src/chart/bar/BarView.ts | 7 +++++- test/ut/spec/series/bar.test.ts | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts index ba2be19ead..b6d2e94ae3 100644 --- a/src/chart/bar/BarView.ts +++ b/src/chart/bar/BarView.ts @@ -355,7 +355,12 @@ class BarView extends ChartView { } } - const roundCapChanged = el && (el.type === 'sector' && roundCap || el.type === 'sausage' && !roundCap); + const roundCapChanged = el && ( + coord.type === 'polar' + // Polar bars only use `sausage` when they are not radial. + ? (el.type === 'sausage') !== (!isHorizontalOrRadial && !!roundCap) + : (el.type === 'sector' && roundCap || el.type === 'sausage' && !roundCap) + ); if (roundCapChanged) { // roundCap changed, there is no way to use animation from a `sector` to a `sausage` shape, // so remove the old one and create a new shape diff --git a/test/ut/spec/series/bar.test.ts b/test/ut/spec/series/bar.test.ts index 73e703d2d9..2761ed614a 100644 --- a/test/ut/spec/series/bar.test.ts +++ b/test/ut/spec/series/bar.test.ts @@ -62,4 +62,44 @@ describe('bar', function () { } }); + it('should redraw polar bars as sectors when the category axis moves from radius to angle with roundCap', function () { + const chart = createChart({width: 400, height: 300}); + + try { + const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']; + const totals = [3.2, 2.1, 4.0, 2.8, 3.6]; + const makeOption = function (layout: 'rings' | 'rays') { + const dayAxis = { type: 'category', data: days }; + const valueAxis = { type: 'value', max: 5 }; + return { + animation: false, + polar: { radius: [20, '80%'] }, + angleAxis: layout === 'rays' ? dayAxis : valueAxis, + radiusAxis: layout === 'rays' ? valueAxis : dayAxis, + series: [{ type: 'bar', coordinateSystem: 'polar', roundCap: true, data: totals }] + }; + }; + const getTypes = function () { + const data = (chart as any).getModel().getSeriesByIndex(0).getData(); + const types: string[] = []; + data.each(function (idx: number) { + types.push(data.getItemGraphicEl(idx).type); + }); + return types; + }; + + chart.setOption(makeOption('rings') as any); + expect(getTypes()).toEqual(days.map(() => 'sausage')); + + chart.setOption(makeOption('rays') as any); + expect(getTypes()).toEqual(days.map(() => 'sector')); + + chart.setOption(makeOption('rings') as any); + expect(getTypes()).toEqual(days.map(() => 'sausage')); + } + finally { + chart.dispose(); + } + }); + });