Skip to content

Commit

Permalink
feat(axis): provide splitLine.showMinLine and splitLine.showMaxLine
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetzhDing committed Sep 30, 2022
1 parent 81321a6 commit 8be4e47
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/component/axis/CartesianAxisView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import CartesianAxisModel from '../../coord/cartesian/AxisModel';
import GridModel from '../../coord/cartesian/GridModel';
import { Payload } from '../../util/types';
import { isIntervalOrLogScale } from '../../scale/helper';
import IntervalScale from '../../scale/Interval';

const axisBuilderAttrs = [
'axisLine', 'axisTickLabel', 'axisName'
Expand Down Expand Up @@ -135,6 +136,30 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
tickModel: splitLineModel
});

const axisScale = axis.scale as IntervalScale;
if (ticksCoords.length > 2 && axisScale.getInterval) {
const interval = axisScale.getInterval() || null;

const showMinLine = splitLineModel.get('showMinLine');
if (showMinLine === false
|| (showMinLine === 'auto'
&& ticksCoords[1].tickValue - ticksCoords[0].tickValue < interval
)
) {
ticksCoords.shift();
}

const showMaxLine = splitLineModel.get('showMaxLine');
if (showMaxLine === false
|| (showMaxLine === 'auto'
&& ticksCoords[ticksCoords.length - 1].tickValue
- ticksCoords[ticksCoords.length - 2].tickValue < interval
)
) {
ticksCoords.pop();
}
}

const p1 = [];
const p2 = [];

Expand Down
4 changes: 4 additions & 0 deletions src/coord/axisCommonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ interface MinorTickOption {

interface SplitLineOption {
show?: boolean,
// true | false | 'auto'(true when nick tick)
showMinLine?: boolean | 'auto',
// true | false | 'auto'(true when nick tick)
showMaxLine?: boolean | 'auto',
interval?: 'auto' | number | ((index:number, value: string) => boolean)
// colors will display in turn
lineStyle?: LineStyleOption<ZRColor | ZRColor[]>
Expand Down
4 changes: 3 additions & 1 deletion src/coord/axisDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ const defaultOption: AxisBaseOption = {
color: ['#E0E6F1'],
width: 1,
type: 'solid'
}
},
showMinLine: true,
showMaxLine: true
},
splitArea: {
show: false,
Expand Down
72 changes: 69 additions & 3 deletions test/axis-interval.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8be4e47

Please sign in to comment.