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 2 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
23 changes: 20 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 @@ -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<RectProps | SectorProps>(bgEl, { shape }, animationModel, newIndex);
}

let el = oldData.getItemGraphicEl(oldIndex) as BarPossiblePath;
Expand Down Expand Up @@ -971,7 +974,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 +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;
Ovilia marked this conversation as resolved.
Show resolved Hide resolved
const sectorShape = (el as Sector).shape;
const cornerRadius = getSectorCornerRadius(
itemModel.getModel('itemStyle'),
sectorShape,
true
);
extend(sectorShape, cornerRadius);
sector.setShape(sectorShape);
Ovilia marked this conversation as resolved.
Show resolved Hide resolved
}

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
180 changes: 180 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.