Skip to content

Commit

Permalink
Merge pull request #13378 from plainheart/feat-pie-corner-radius
Browse files Browse the repository at this point in the history
[5.0] [Feature] pie series supports cornerRadius & innerCornerRadius.
  • Loading branch information
pissang authored Oct 6, 2020
2 parents a97faf2 + 0d43d31 commit a088d80
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/chart/pie/PieSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ export interface PieSeriesOption extends
minAngle?: number
minShowLabelAngle?: number

// can be 10
// which means that both innerCornerRadius and outerCornerRadius are 10
// can also be an array [20, 10]
// which means that innerCornerRadius is 20
// and outerCornerRadius is 10
// can also be a string or string array, such as ['20%', '50%']
// which means that innerCornerRadius is 20% of the innerRadius
// and outerCornerRadius is half of outerRadius.
cornerRadius?: (number | string)[] | number | string

selectedOffset?: number

avoidLabelOverlap?: boolean
Expand Down Expand Up @@ -186,6 +196,7 @@ class PieSeriesModel extends SeriesModel<PieSeriesOption> {
// 默认全局居中
center: ['50%', '50%'],
radius: [0, '75%'],
cornerRadius: 0,
// 默认顺时针
clockwise: true,
startAngle: 90,
Expand Down
16 changes: 13 additions & 3 deletions src/chart/pie/pieLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ export default function (

let center = seriesModel.get('center');
let radius = seriesModel.get('radius');
let cornerRadius = seriesModel.get('cornerRadius');

if (!zrUtil.isArray(radius)) {
radius = [0, radius];
}
if (!zrUtil.isArray(center)) {
center = [center, center];
}
if (!zrUtil.isArray(cornerRadius)) {
cornerRadius = [cornerRadius, cornerRadius];
}

const width = parsePercent(viewRect.width, api.getWidth());
const height = parsePercent(viewRect.height, api.getHeight());
Expand All @@ -63,6 +67,8 @@ export default function (
const cy = parsePercent(center[1], height) + viewRect.y;
const r0 = parsePercent(radius[0], size / 2);
const r = parsePercent(radius[1], size / 2);
const innerCornerRadius = parsePercent(cornerRadius[0], r0);
const outerCornerRadius = parsePercent(cornerRadius[1], r);

const startAngle = -seriesModel.get('startAngle') * RADIAN;

Expand Down Expand Up @@ -108,7 +114,9 @@ export default function (
r0: r0,
r: roseType
? NaN
: r
: r,
cornerRadius: outerCornerRadius,
innerCornerRadius: innerCornerRadius
});
return;
}
Expand Down Expand Up @@ -141,7 +149,9 @@ export default function (
r0: r0,
r: roseType
? linearMap(value, extent, [r0, r])
: r
: r,
cornerRadius: outerCornerRadius,
innerCornerRadius: innerCornerRadius
});

currentAngle = endAngle;
Expand Down Expand Up @@ -179,4 +189,4 @@ export default function (
}
}
});
}
}
303 changes: 303 additions & 0 deletions test/pie-cornerRadius.html

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

0 comments on commit a088d80

Please sign in to comment.