Skip to content

Commit 274cb4a

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

4 files changed

Lines changed: 199 additions & 25 deletions

File tree

src/component/axis/AngleAxisView.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,32 @@ 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();
144+
const radiusAxis = polar.getRadiusAxis();
143145
const RADIAN = Math.PI / 180;
144146
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;
147+
const showMinLine = axisLineModel.get('showMinLine') !== false;
148+
const showMaxLine = axisLineModel.get('showMaxLine') !== false;
150149
const shapeType = Math.abs(angleExtent[1] - angleExtent[0]) === 360 ? 'Circle' : 'Arc';
150+
const radiusDataExtent = radiusAxis.scale.getExtent();
151+
const minRadius = radiusAxis.dataToCoord(radiusDataExtent[0]);
152+
const maxRadius = radiusAxis.dataToCoord(radiusDataExtent[1]);
151153

152-
if (radiusExtent[r0Id] === 0) {
153-
shape = new graphic[shapeType]({
154+
if (!showMinLine && !showMaxLine) {
155+
return;
156+
}
157+
158+
const addBoundaryLine = (radius: number) => {
159+
if (!isFinite(radius)) {
160+
return;
161+
}
162+
const shape = new graphic[shapeType]({
154163
shape: {
155164
cx: polar.cx,
156165
cy: polar.cy,
157-
r: radiusExtent[rId],
166+
r: Math.max(radius, 0),
158167
startAngle: -angleExtent[0] * RADIAN,
159168
endAngle: -angleExtent[1] * RADIAN,
160169
clockwise: angleAxis.inverse
@@ -163,22 +172,21 @@ const angelAxisElementsBuilders: Record<typeof elementList[number], AngleAxisEle
163172
z2: 1,
164173
silent: true
165174
});
175+
shape.style.fill = null;
176+
group.add(shape);
177+
};
178+
179+
if (Math.abs(minRadius - maxRadius) < 1e-4) {
180+
addBoundaryLine(minRadius);
181+
return;
166182
}
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-
});
183+
184+
if (showMinLine) {
185+
addBoundaryLine(minRadius);
186+
}
187+
if (showMaxLine) {
188+
addBoundaryLine(maxRadius);
179189
}
180-
shape.style.fill = null;
181-
group.add(shape);
182190
},
183191

184192
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: 157 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)