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 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
13 changes: 10 additions & 3 deletions src/component/axis/AngleAxisView.ts
Expand Up @@ -138,18 +138,25 @@ 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;
const shapeType = Math.abs(angleExtent[1] - angleExtent[0]) === 360 ? 'Circle' : 'Arc';

if (radiusExtent[r0Id] === 0) {
shape = new graphic.Circle({
shape = new graphic[shapeType]({
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
12 changes: 10 additions & 2 deletions src/component/axis/RadiusAxisView.ts
Expand Up @@ -105,19 +105,27 @@ 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();
const shapeType = Math.abs(angleExtent[1] - angleExtent[0]) === 360 ? 'Circle' : 'Arc';

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[shapeType]({
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.