Skip to content

Commit 8e968f4

Browse files
authored
Merge pull request #20114 from adaelixir/feature-#20110
feature(axis): add showMin/MaxLine to splitline in coordinate axis
2 parents 65f6255 + a4d803f commit 8e968f4

File tree

5 files changed

+101
-5
lines changed

5 files changed

+101
-5
lines changed

src/component/axis/CartesianAxisView.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
123123
const splitLineModel = axisModel.getModel('splitLine');
124124
const lineStyleModel = splitLineModel.getModel('lineStyle');
125125
let lineColors = lineStyleModel.get('color');
126+
const showMinLine = splitLineModel.get('showMinLine') !== false;
127+
const showMaxLine = splitLineModel.get('showMaxLine') !== false;
126128

127129
lineColors = zrUtil.isArray(lineColors) ? lineColors : [lineColors];
128130

@@ -142,6 +144,12 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
142144
for (let i = 0; i < ticksCoords.length; i++) {
143145
const tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
144146

147+
if ((i === 0 && !showMinLine) || (i === ticksCoords.length - 1 && !showMaxLine)) {
148+
continue;
149+
}
150+
151+
const tickValue = ticksCoords[i].tickValue;
152+
145153
if (isHorizontal) {
146154
p1[0] = tickCoord;
147155
p1[1] = gridRect.y;
@@ -156,9 +164,8 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
156164
}
157165

158166
const colorIndex = (lineCount++) % lineColors.length;
159-
const tickValue = ticksCoords[i].tickValue;
160167
const line = new graphic.Line({
161-
anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
168+
anid: tickValue != null ? 'line_' + tickValue : null,
162169
autoBatch: true,
163170
shape: {
164171
x1: p1[0],

src/coord/Axis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function fixOnBandTicksCoords(
302302
let diffSize;
303303
if (ticksLen === 1) {
304304
ticksCoords[0].coord = axisExtent[0];
305-
last = ticksCoords[1] = {coord: axisExtent[1]};
305+
last = ticksCoords[1] = {coord: axisExtent[1], tickValue: ticksCoords[0].tickValue};
306306
}
307307
else {
308308
const crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
@@ -315,7 +315,7 @@ function fixOnBandTicksCoords(
315315
const dataExtent = axis.scale.getExtent();
316316
diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
317317

318-
last = {coord: ticksCoords[ticksLen - 1].coord + shift * diffSize};
318+
last = {coord: ticksCoords[ticksLen - 1].coord + shift * diffSize, tickValue: dataExtent[1] + 1};
319319

320320
ticksCoords.push(last);
321321
}

src/coord/axisCommonTypes.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ interface MinorTickOption {
258258

259259
interface SplitLineOption {
260260
show?: boolean,
261-
interval?: 'auto' | number | ((index:number, value: string) => boolean)
261+
interval?: 'auto' | number | ((index:number, value: string) => boolean),
262+
// true | false
263+
showMinLine?: boolean,
264+
// true | false
265+
showMaxLine?: boolean,
262266
// colors will display in turn
263267
lineStyle?: LineStyleOption<ZRColor | ZRColor[]>
264268
}

src/coord/axisDefault.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ const defaultOption: AxisBaseOption = {
9393
},
9494
splitLine: {
9595
show: true,
96+
showMinLine: true,
97+
showMaxLine: true,
9698
lineStyle: {
9799
color: ['#E0E6F1'],
98100
width: 1,

test/axis-splitLine.html

Lines changed: 83 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)