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

feat(pie/sunburst): supports configuring any one border radius. #16298

Merged
merged 6 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 3 additions & 11 deletions src/chart/helper/pieHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,16 @@
*/

import Model from '../../model/Model';
import Sector from 'zrender/src/graphic/shape/Sector';
import { isArray } from 'zrender/src/core/util';
import { parsePercent } from 'zrender/src/contain/text';

export function getSectorCornerRadius(
model: Model<{ borderRadius?: string | number | (string | number)[] }>,
shape: Pick<Sector['shape'], 'r0' | 'r'>,
zeroIfNull?: boolean
) {
let cornerRadius = model.get('borderRadius');
const cornerRadius = model.get('borderRadius');
if (cornerRadius == null) {
return zeroIfNull ? {innerCornerRadius: 0, cornerRadius: 0} : null;
}
if (!isArray(cornerRadius)) {
cornerRadius = [cornerRadius, cornerRadius];
return zeroIfNull ? { cornerRadius: 0 } : null;
}
return {
innerCornerRadius: parsePercent(cornerRadius[0], shape.r0),
cornerRadius: parsePercent(cornerRadius[1], shape.r)
cornerRadius: cornerRadius as number | number[]
plainheart marked this conversation as resolved.
Show resolved Hide resolved
};
}
10 changes: 5 additions & 5 deletions src/chart/pie/PieView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import labelLayout from './labelLayout';
import { setLabelLineStyle, getLabelLineStatesModels } from '../../label/labelGuideHelper';
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
import { getSectorCornerRadius } from '../helper/pieHelper';
import {saveOldStyle} from '../../animation/basicTrasition';
import { saveOldStyle } from '../../animation/basicTrasition';
import { getBasicPieLayout } from './pieLayout';

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ class PiePiece extends graphic.Sector {
// cornerRadius & innerCornerRadius doesn't exist in the item layout. Use `0` if null value is specified.
// see `setItemLayout` in `pieLayout.ts`.
const sectorShape = extend(
getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true),
getSectorCornerRadius(itemModel.getModel('itemStyle'), true),
layout
);

Expand Down Expand Up @@ -141,15 +141,15 @@ class PiePiece extends graphic.Sector {
sector.ensureState('emphasis').shape = {
r: layout.r + (emphasisModel.get('scale')
? (emphasisModel.get('scaleSize') || 0) : 0),
...getSectorCornerRadius(emphasisModel.getModel('itemStyle'), layout)
...getSectorCornerRadius(emphasisModel.getModel('itemStyle'))
};
extend(sector.ensureState('select'), {
x: dx,
y: dy,
shape: getSectorCornerRadius(itemModel.getModel(['select', 'itemStyle']), layout)
shape: getSectorCornerRadius(itemModel.getModel(['select', 'itemStyle']))
});
extend(sector.ensureState('blur'), {
shape: getSectorCornerRadius(itemModel.getModel(['blur', 'itemStyle']), layout)
shape: getSectorCornerRadius(itemModel.getModel(['blur', 'itemStyle']))
});

const labelLine = sector.getTextGuideLine();
Expand Down
4 changes: 2 additions & 2 deletions src/chart/sunburst/SunburstPiece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ class SunburstPiece extends graphic.Sector {
normalStyle.decal = createOrUpdatePatternFromDecal(decal, api);
}

const cornerRadius = getSectorCornerRadius(itemModel.getModel('itemStyle'), sectorShape, true);
const cornerRadius = getSectorCornerRadius(itemModel.getModel('itemStyle'), true);
zrUtil.extend(sectorShape, cornerRadius);

zrUtil.each(SPECIAL_STATES, function (stateName) {
const state = sector.ensureState(stateName);
const itemStyleModel = itemModel.getModel([stateName, 'itemStyle']);
state.style = itemStyleModel.getItemStyle();
// border radius
const cornerRadius = getSectorCornerRadius(itemStyleModel, sectorShape);
const cornerRadius = getSectorCornerRadius(itemStyleModel);
if (cornerRadius) {
state.shape = cornerRadius;
}
Expand Down
19 changes: 19 additions & 0 deletions test/pie-cornerRadius.html

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