Skip to content

Commit

Permalink
Merge pull request #18820 from linghaoSu/feat/pie-angleRange
Browse files Browse the repository at this point in the history
feat(pie): add endAngle for control pie range
  • Loading branch information
Ovilia authored Jul 4, 2023
2 parents 7866509 + 65d7442 commit b79777e
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/chart/pie/PieSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface PieSeriesOption extends

clockwise?: boolean
startAngle?: number
endAngle?: number | 'auto'
minAngle?: number
minShowLabelAngle?: number

Expand Down Expand Up @@ -217,6 +218,7 @@ class PieSeriesModel extends SeriesModel<PieSeriesOption> {
// 默认顺时针
clockwise: true,
startAngle: 90,
endAngle: 'auto',
// 最小角度改为0
minAngle: 0,

Expand Down
20 changes: 15 additions & 5 deletions src/chart/pie/pieLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import PieSeriesModel from './PieSeries';
import { SectorShape } from 'zrender/src/graphic/shape/Sector';
import { normalizeArcAngles } from 'zrender/src/core/PathProxy';

const PI2 = Math.PI * 2;
const RADIAN = Math.PI / 180;
Expand Down Expand Up @@ -91,7 +92,9 @@ export default function pieLayout(

const { cx, cy, r, r0 } = getBasicPieLayout(seriesModel, api);

const startAngle = -seriesModel.get('startAngle') * RADIAN;
let startAngle = -seriesModel.get('startAngle') * RADIAN;
let endAngle = seriesModel.get('endAngle');
endAngle = endAngle === 'auto' ? startAngle - PI2 : -endAngle * RADIAN;

const minAngle = seriesModel.get('minAngle') * RADIAN;

Expand All @@ -113,12 +116,19 @@ export default function pieLayout(
const extent = data.getDataExtent(valueDim);
extent[0] = 0;

const dir = clockwise ? 1 : -1;
const angles = [startAngle, endAngle];
normalizeArcAngles(angles, !clockwise);

[startAngle, endAngle] = angles;

const angleRange = Math.abs(endAngle - startAngle);

// In the case some sector angle is smaller than minAngle
let restAngle = PI2;
let restAngle = angleRange;
let valueSumLargerThanMinAngle = 0;

let currentAngle = startAngle;
const dir = clockwise ? 1 : -1;

data.setLayout({ viewRect, r });

Expand Down Expand Up @@ -146,7 +156,7 @@ export default function pieLayout(
? unitRadian : (value * unitRadian);
}
else {
angle = PI2 / validDataCount;
angle = angleRange / validDataCount;
}

if (angle < minAngle) {
Expand Down Expand Up @@ -180,7 +190,7 @@ export default function pieLayout(
// Average the angle if rest angle is not enough after all angles is
// Constrained by minAngle
if (restAngle <= 1e-3) {
const angle = PI2 / validDataCount;
const angle = angleRange / validDataCount;
data.each(valueDim, function (value: number, idx: number) {
if (!isNaN(value)) {
const layout = data.getItemLayout(idx);
Expand Down
90 changes: 90 additions & 0 deletions test/pie-endAngle.html

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

1 change: 1 addition & 0 deletions test/runTest/actions/__meta__.json

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

1 change: 1 addition & 0 deletions test/runTest/actions/pie-endAngle.json

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

0 comments on commit b79777e

Please sign in to comment.