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): add endAngle for control pie range #18820

Merged
merged 5 commits into from Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/chart/pie/PieSeries.ts
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
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);
Ovilia marked this conversation as resolved.
Show resolved Hide resolved

// 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.