Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(polar): support borderRadius for polar bars #17980 #17995

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/chart/bar/BarSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ interface BarStatesMixin {
}

export interface BarItemStyleOption<TCbParams = never> extends ItemStyleOption<TCbParams> {
// 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<BarStateOption, BarStatesMixin>,
Expand Down
28 changes: 25 additions & 3 deletions src/chart/bar/BarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -243,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;
};
Expand Down Expand Up @@ -334,11 +340,14 @@ 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);
const shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
updateProps(bgEl, { shape }, animationModel, newIndex);
updateProps<RectProps | SectorProps>(bgEl, { shape }, animationModel, newIndex);
}

let el = oldData.getItemGraphicEl(oldIndex) as BarPossiblePath;
Expand Down Expand Up @@ -971,7 +980,8 @@ function createPolarPositionMapping(isRadial: boolean)

function updateStyle(
el: BarPossiblePath,
data: SeriesData, dataIndex: number,
data: SeriesData,
dataIndex: number,
itemModel: Model<BarDataItemOption>,
layout: RectLayout | SectorLayout,
seriesModel: BarSeriesModel,
Expand All @@ -981,7 +991,19 @@ 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 sectorShape = (el as Sector).shape;
const cornerRadius = getSectorCornerRadius(
itemModel.getModel('itemStyle'),
sectorShape,
true
);
extend(sectorShape, cornerRadius);
(el as Sector).setShape(sectorShape);
}

el.useStyle(style);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/chart/pie/PieView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/chart/sunburst/SunburstPiece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
192 changes: 192 additions & 0 deletions test/bar-polar-borderRadius.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.