Skip to content

Commit

Permalink
Merge pull request #19099 from yassilah/feat-polar-endAngle
Browse files Browse the repository at this point in the history
feat(polar): allow setting `angleAxis.endAngle`
  • Loading branch information
Ovilia authored Sep 27, 2023
2 parents 80b251f + 691d9ee commit d08664f
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/component/axis/AngleAxisView.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.

0 comments on commit d08664f

Please sign in to comment.