Skip to content

Commit 04467c4

Browse files
feat(axis): Add support for showMinLine/showMaxLine to polar angle axis
1 parent c1b6b59 commit 04467c4

4 files changed

Lines changed: 258 additions & 25 deletions

File tree

src/component/axis/AngleAxisView.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,30 @@ interface AngleAxisElementBuilder {
138138
const angelAxisElementsBuilders: Record<typeof elementList[number], AngleAxisElementBuilder> = {
139139

140140
axisLine(group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {
141+
const axisLineModel = angleAxisModel.getModel('axisLine');
141142
const lineStyleModel = angleAxisModel.getModel(['axisLine', 'lineStyle']);
142143
const angleAxis = polar.getAngleAxis();
143144
const RADIAN = Math.PI / 180;
144145
const angleExtent = angleAxis.getExtent();
145-
146-
// extent id of the axis radius (r0 and r)
147-
const rId = getRadiusIdx(polar);
148-
const r0Id = rId ? 0 : 1;
149-
let shape;
146+
const showMinLine = axisLineModel.get('showMinLine') !== false;
147+
const showMaxLine = axisLineModel.get('showMaxLine') !== false;
150148
const shapeType = Math.abs(angleExtent[1] - angleExtent[0]) === 360 ? 'Circle' : 'Arc';
149+
const minRadius = radiusExtent[0];
150+
const maxRadius = radiusExtent[1];
151151

152-
if (radiusExtent[r0Id] === 0) {
153-
shape = new graphic[shapeType]({
152+
if (!showMinLine && !showMaxLine) {
153+
return;
154+
}
155+
156+
const addBoundaryLine = (radius: number) => {
157+
if (!isFinite(radius)) {
158+
return;
159+
}
160+
const shape = new graphic[shapeType]({
154161
shape: {
155162
cx: polar.cx,
156163
cy: polar.cy,
157-
r: radiusExtent[rId],
164+
r: Math.max(radius, 0),
158165
startAngle: -angleExtent[0] * RADIAN,
159166
endAngle: -angleExtent[1] * RADIAN,
160167
clockwise: angleAxis.inverse
@@ -163,22 +170,21 @@ const angelAxisElementsBuilders: Record<typeof elementList[number], AngleAxisEle
163170
z2: 1,
164171
silent: true
165172
});
173+
shape.style.fill = null;
174+
group.add(shape);
175+
};
176+
177+
if (Math.abs(minRadius - maxRadius) < 1e-4) {
178+
addBoundaryLine(minRadius);
179+
return;
166180
}
167-
else {
168-
shape = new graphic.Ring({
169-
shape: {
170-
cx: polar.cx,
171-
cy: polar.cy,
172-
r: radiusExtent[rId],
173-
r0: radiusExtent[r0Id]
174-
},
175-
style: lineStyleModel.getLineStyle(),
176-
z2: 1,
177-
silent: true
178-
});
181+
182+
if (showMinLine) {
183+
addBoundaryLine(minRadius);
184+
}
185+
if (showMaxLine) {
186+
addBoundaryLine(maxRadius);
179187
}
180-
shape.style.fill = null;
181-
group.add(shape);
182188
},
183189

184190
axisTick(group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {

src/component/polar/install.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ const angleAxisExtraOption: AngleAxisOption = {
4444

4545
splitNumber: 12,
4646

47+
axisLine: {
48+
showMinLine: true,
49+
showMaxLine: true
50+
},
51+
4752
axisLabel: {
4853
rotate: 0
4954
}
@@ -77,4 +82,4 @@ export function install(registers: EChartsExtensionInstallRegisters) {
7782
registers.registerComponentView(RadiusAxisView);
7883

7984
registers.registerLayout(curry(barLayoutPolar, 'bar'));
80-
}
85+
}

src/coord/polar/AxisModel.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export type AngleAxisOption = AxisBaseOption & {
4242
endAngle?: number;
4343
clockwise?: boolean;
4444

45-
axisLabel?: AxisBaseOption['axisLabel']
45+
axisLabel?: AxisBaseOption['axisLabel'];
46+
axisLine?: NonNullable<AxisBaseOption['axisLine']> & {
47+
showMinLine?: boolean;
48+
showMaxLine?: boolean;
49+
}
4650
};
4751

4852
export type RadiusAxisOption = AxisBaseOption & {
@@ -86,4 +90,4 @@ export class RadiusAxisModel extends PolarAxisModel<RadiusAxisOption> {
8690
static type = 'radiusAxis';
8791
type = RadiusAxisModel.type;
8892
axis: RadiusAxis;
89-
}
93+
}

test/axis-axisLine.html

Lines changed: 218 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)