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(polar): allow setting angleAxis.endAngle #19099

Merged
merged 7 commits into from Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 9 additions & 3 deletions src/component/axis/AngleAxisView.ts
Expand Up @@ -138,18 +138,24 @@ const angelAxisElementsBuilders: Record<typeof elementList[number], AngleAxisEle

axisLine(group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {
const lineStyleModel = angleAxisModel.getModel(['axisLine', 'lineStyle']);
const angleAxis = polar.getAngleAxis();
const RADIAN = Math.PI / 180;
const angleExtent = angleAxis.getExtent();

// extent id of the axis radius (r0 and r)
const rId = getRadiusIdx(polar);
const r0Id = rId ? 0 : 1;

let shape;

if (radiusExtent[r0Id] === 0) {
shape = new graphic.Circle({
shape = new graphic.Arc({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run the visual tests (npm run test:visual) and find there are some subtle diffs with polarLine.html, which is a case when startAngle is not the default value. I would suggest using graphic.Circle when Math.abs(angleExtent[1] - angleExtent[0]) === 360 (or is there any other situations?) and use graphic.Arc otherwise.

shape: {
cx: polar.cx,
cy: polar.cy,
r: radiusExtent[rId]
r: radiusExtent[rId],
startAngle: -angleExtent[0] * RADIAN,
endAngle: -angleExtent[1] * RADIAN,
clockwise: angleAxis.inverse
},
style: lineStyleModel.getLineStyle(),
z2: 1,
Expand Down
11 changes: 9 additions & 2 deletions src/component/axis/RadiusAxisView.ts
Expand Up @@ -105,19 +105,26 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
let lineColors = lineStyleModel.get('color');
let lineCount = 0;

const angleAxis = polar.getAngleAxis();
const RADIAN = Math.PI / 180;
const angleExtent = angleAxis.getExtent();

lineColors = lineColors instanceof Array ? lineColors : [lineColors];

const splitLines: graphic.Circle[][] = [];

for (let i = 0; i < ticksCoords.length; i++) {
const colorIndex = (lineCount++) % lineColors.length;
splitLines[colorIndex] = splitLines[colorIndex] || [];
splitLines[colorIndex].push(new graphic.Circle({
splitLines[colorIndex].push(new graphic.Arc({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar as above.

shape: {
cx: polar.cx,
cy: polar.cy,
// ensure circle radius >= 0
r: Math.max(ticksCoords[i].coord, 0)
r: Math.max(ticksCoords[i].coord, 0),
startAngle: -angleExtent[0] * RADIAN,
endAngle: -angleExtent[1] * RADIAN,
clockwise: angleAxis.inverse
}
}));
}
Expand Down
1 change: 1 addition & 0 deletions src/coord/polar/AxisModel.ts
Expand Up @@ -39,6 +39,7 @@ export type AngleAxisOption = AxisBaseOption & {
polarId?: string;

startAngle?: number;
endAngle?: number;
clockwise?: boolean;

axisLabel?: AxisBaseOption['axisLabel']
Expand Down
3 changes: 2 additions & 1 deletion src/coord/polar/polarCreator.ts
Expand Up @@ -124,7 +124,8 @@ function setAxis(axis: RadiusAxis | AngleAxis, axisModel: PolarAxisModel) {
if (isAngleAxisModel(axisModel)) {
axis.inverse = axis.inverse !== axisModel.get('clockwise');
const startAngle = axisModel.get('startAngle');
axis.setExtent(startAngle, startAngle + (axis.inverse ? -360 : 360));
const endAngle = axisModel.get('endAngle') ?? (startAngle + (axis.inverse ? -360 : 360));
axis.setExtent(startAngle, endAngle);
}

// Inject axis instance
Expand Down
85 changes: 85 additions & 0 deletions test/polar-end-angle.html

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