From bd767e20f0fc8ba227e3c430ac529d107ab6fe32 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Wed, 30 Nov 2022 16:46:33 +0800 Subject: [PATCH 1/3] fix(polar): support borderRadius for polar bars #17980 --- src/chart/bar/BarSeries.ts | 4 +- src/chart/bar/BarView.ts | 23 +++- src/chart/helper/pieHelper.ts | 41 ------- src/chart/pie/PieView.ts | 2 +- src/chart/sunburst/SunburstPiece.ts | 2 +- test/bar-polar-borderRadius.html | 180 ++++++++++++++++++++++++++++ 6 files changed, 204 insertions(+), 48 deletions(-) delete mode 100644 src/chart/helper/pieHelper.ts create mode 100644 test/bar-polar-borderRadius.html diff --git a/src/chart/bar/BarSeries.ts b/src/chart/bar/BarSeries.ts index eb838c11ff..de03a19eaf 100644 --- a/src/chart/bar/BarSeries.ts +++ b/src/chart/bar/BarSeries.ts @@ -53,8 +53,8 @@ interface BarStatesMixin { } export interface BarItemStyleOption extends ItemStyleOption { - // Border radius is not supported for bar on polar - borderRadius?: number | number[] + // for polar bars, this is used for sector's cornerRadius + borderRadius?: (number | string)[] | number | string } export interface BarDataItemOption extends BarStateOption, StatesOptionMixin, diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts index 0de06c481f..346f3d9da5 100644 --- a/src/chart/bar/BarView.ts +++ b/src/chart/bar/BarView.ts @@ -21,6 +21,8 @@ import Path, {PathProps} from 'zrender/src/graphic/Path'; import Group from 'zrender/src/graphic/Group'; import {extend, each, map} from 'zrender/src/core/util'; import {BuiltinTextPosition} from 'zrender/src/core/types'; +import {SectorProps} from 'zrender/src/graphic/shape/Sector'; +import {RectProps} from 'zrender/src/graphic/shape/Rect'; import { Rect, Sector, @@ -66,6 +68,7 @@ import { warn } from '../../util/log'; import {createSectorCalculateTextPosition, SectorTextPosition, setSectorTextRotation} from '../../label/sectorLabel'; import { saveOldStyle } from '../../animation/basicTransition'; import Element from 'zrender/src/Element'; +import { getSectorCornerRadius } from '../helper/sectorHelper'; const mathMax = Math.max; const mathMin = Math.min; @@ -338,7 +341,7 @@ class BarView extends ChartView { } const bgLayout = getLayout[coord.type](data, newIndex); const shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord); - updateProps(bgEl, { shape }, animationModel, newIndex); + updateProps(bgEl, { shape }, animationModel, newIndex); } let el = oldData.getItemGraphicEl(oldIndex) as BarPossiblePath; @@ -971,7 +974,8 @@ function createPolarPositionMapping(isRadial: boolean) function updateStyle( el: BarPossiblePath, - data: SeriesData, dataIndex: number, + data: SeriesData, + dataIndex: number, itemModel: Model, layout: RectLayout | SectorLayout, seriesModel: BarSeriesModel, @@ -981,7 +985,20 @@ function updateStyle( const style = data.getItemVisual(dataIndex, 'style'); if (!isPolar) { - (el as Rect).setShape('r', itemModel.get(['itemStyle', 'borderRadius']) || 0); + const borderRadius = itemModel + .get(['itemStyle', 'borderRadius']) as number | number[] || 0; + (el as Rect).setShape('r', borderRadius); + } + else if (!seriesModel.get('roundCap')) { + const sector = el as Sector; + const sectorShape = (el as Sector).shape; + const cornerRadius = getSectorCornerRadius( + itemModel.getModel('itemStyle'), + sectorShape, + true + ); + extend(sectorShape, cornerRadius); + sector.setShape(sectorShape); } el.useStyle(style); diff --git a/src/chart/helper/pieHelper.ts b/src/chart/helper/pieHelper.ts deleted file mode 100644 index e55ded398b..0000000000 --- a/src/chart/helper/pieHelper.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - -import type Model from '../../model/Model'; -import type Sector from 'zrender/src/graphic/shape/Sector'; -import { isArray, map } from 'zrender/src/core/util'; -import { parsePercent } from 'zrender/src/contain/text'; - -export function getSectorCornerRadius( - model: Model<{ borderRadius?: string | number | (string | number)[] }>, - shape: Pick, - zeroIfNull?: boolean -) { - let cornerRadius = model.get('borderRadius'); - if (cornerRadius == null) { - return zeroIfNull ? { cornerRadius: 0 } : null; - } - if (!isArray(cornerRadius)) { - cornerRadius = [cornerRadius, cornerRadius, cornerRadius, cornerRadius]; - } - const dr = Math.abs(shape.r || 0 - shape.r0 || 0); - return { - cornerRadius: map(cornerRadius, cr => parsePercent(cr, dr)) - }; -} diff --git a/src/chart/pie/PieView.ts b/src/chart/pie/PieView.ts index 77f5c445e3..cb0e1d6357 100644 --- a/src/chart/pie/PieView.ts +++ b/src/chart/pie/PieView.ts @@ -31,7 +31,7 @@ import PieSeriesModel, {PieDataItemOption} from './PieSeries'; import labelLayout from './labelLayout'; import { setLabelLineStyle, getLabelLineStatesModels } from '../../label/labelGuideHelper'; import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle'; -import { getSectorCornerRadius } from '../helper/pieHelper'; +import { getSectorCornerRadius } from '../helper/sectorHelper'; import { saveOldStyle } from '../../animation/basicTransition'; import { getBasicPieLayout } from './pieLayout'; diff --git a/src/chart/sunburst/SunburstPiece.ts b/src/chart/sunburst/SunburstPiece.ts index 873a686f17..8c7be8c1a7 100644 --- a/src/chart/sunburst/SunburstPiece.ts +++ b/src/chart/sunburst/SunburstPiece.ts @@ -28,7 +28,7 @@ import { PathStyleProps } from 'zrender/src/graphic/Path'; import { ColorString } from '../../util/types'; import Model from '../../model/Model'; import { getECData } from '../../util/innerStore'; -import { getSectorCornerRadius } from '../helper/pieHelper'; +import { getSectorCornerRadius } from '../helper/sectorHelper'; import {createOrUpdatePatternFromDecal} from '../../util/decal'; import ExtensionAPI from '../../core/ExtensionAPI'; import { saveOldStyle } from '../../animation/basicTransition'; diff --git a/test/bar-polar-borderRadius.html b/test/bar-polar-borderRadius.html new file mode 100644 index 0000000000..9fbf9e973a --- /dev/null +++ b/test/bar-polar-borderRadius.html @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + From 566743232967d95ea3a7b0ac688076f402db9ee7 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Wed, 30 Nov 2022 16:50:55 +0800 Subject: [PATCH 2/3] fix(polar): forgot to commit a new file --- src/chart/helper/sectorHelper.ts | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/chart/helper/sectorHelper.ts diff --git a/src/chart/helper/sectorHelper.ts b/src/chart/helper/sectorHelper.ts new file mode 100644 index 0000000000..e55ded398b --- /dev/null +++ b/src/chart/helper/sectorHelper.ts @@ -0,0 +1,41 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +import type Model from '../../model/Model'; +import type Sector from 'zrender/src/graphic/shape/Sector'; +import { isArray, map } from 'zrender/src/core/util'; +import { parsePercent } from 'zrender/src/contain/text'; + +export function getSectorCornerRadius( + model: Model<{ borderRadius?: string | number | (string | number)[] }>, + shape: Pick, + zeroIfNull?: boolean +) { + let cornerRadius = model.get('borderRadius'); + if (cornerRadius == null) { + return zeroIfNull ? { cornerRadius: 0 } : null; + } + if (!isArray(cornerRadius)) { + cornerRadius = [cornerRadius, cornerRadius, cornerRadius, cornerRadius]; + } + const dr = Math.abs(shape.r || 0 - shape.r0 || 0); + return { + cornerRadius: map(cornerRadius, cr => parsePercent(cr, dr)) + }; +} From dca62c973b4d8e09ac722334ac01920d04e5bbe2 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Mon, 6 Mar 2023 15:38:27 +0800 Subject: [PATCH 3/3] feat: support bar background borderRadius --- src/chart/bar/BarView.ts | 9 +++++++-- test/bar-polar-borderRadius.html | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts index 346f3d9da5..63120dda72 100644 --- a/src/chart/bar/BarView.ts +++ b/src/chart/bar/BarView.ts @@ -246,6 +246,9 @@ class BarView extends ChartView { if (coord.type === 'cartesian2d') { (bgEl as Rect).setShape('r', barBorderRadius); } + else { + (bgEl as Sector).setShape('cornerRadius', barBorderRadius); + } bgEls[dataIndex] = bgEl; return bgEl; }; @@ -337,6 +340,9 @@ class BarView extends ChartView { if (coord.type === 'cartesian2d') { (bgEl as Rect).setShape('r', barBorderRadius); } + else { + (bgEl as Sector).setShape('cornerRadius', barBorderRadius); + } bgEls[newIndex] = bgEl; } const bgLayout = getLayout[coord.type](data, newIndex); @@ -990,7 +996,6 @@ function updateStyle( (el as Rect).setShape('r', borderRadius); } else if (!seriesModel.get('roundCap')) { - const sector = el as Sector; const sectorShape = (el as Sector).shape; const cornerRadius = getSectorCornerRadius( itemModel.getModel('itemStyle'), @@ -998,7 +1003,7 @@ function updateStyle( true ); extend(sectorShape, cornerRadius); - sector.setShape(sectorShape); + (el as Sector).setShape(sectorShape); } el.useStyle(style); diff --git a/test/bar-polar-borderRadius.html b/test/bar-polar-borderRadius.html index 9fbf9e973a..2bdc1b0146 100644 --- a/test/bar-polar-borderRadius.html +++ b/test/bar-polar-borderRadius.html @@ -67,6 +67,10 @@ series: [{ type: 'bar', data: [2, -1, 3], + showBackground: true, + backgroundStyle: { + borderRadius: [5, 10, 20, 30] + }, itemStyle: { borderRadius: [5, 10, 20, 30] }, @@ -109,6 +113,10 @@ series: [{ type: 'bar', data: [2, -1, 3], + showBackground: true, + backgroundStyle: { + borderRadius: [10, 20] + }, itemStyle: { borderRadius: [10, 20] }, @@ -156,6 +164,10 @@ borderRadius: [20, 5] } }, -1, 3], + showBackground: true, + backgroundStyle: { + borderRadius: [20, 5] + }, itemStyle: { borderRadius: 10 },