Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Axis): axisTick.interval work correct #18037

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/coord/Axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,13 @@ function fixOnBandTicksCoords(
return;
}

const intervalIsAutoMode = axis.getTickModel().get('interval') === 'auto';

const axisExtent = axis.getExtent();
let last;
let diffSize;
if (ticksLen === 1) {
ticksCoords[0].coord = axisExtent[0];
last = ticksCoords[1] = {coord: axisExtent[0]};
ticksCoords[0].coord -= axis.getBandWidth() / 2;
}
else {
const crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
Expand All @@ -312,14 +313,22 @@ function fixOnBandTicksCoords(
ticksItem.coord -= shift / 2;
});

const dataExtent = axis.scale.getExtent();
diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
// auto mode: need push a normal tick
// function mode: last tick depend on function return value
// number mode: last tick depend on number
if (intervalIsAutoMode) {
const dataExtent = axis.scale.getExtent();
diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;

last = {coord: ticksCoords[ticksLen - 1].coord + shift * diffSize};
last = {coord: ticksCoords[ticksLen - 1].coord + shift * diffSize};

ticksCoords.push(last);
ticksCoords.push(last);
}
}

// TODO: use array.at(-1) when lib target es2022
last = ticksCoords[ticksCoords.length - 1];

const inverse = axisExtent[0] > axisExtent[1];

// Handling clamp.
Expand Down
18 changes: 17 additions & 1 deletion src/coord/axisTickLabelBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ function makeLabelsByNumericCategoryInterval(axis: Axis, categoryInterval: numbe
const labelModel = axis.getLabelModel();
const result: (MakeLabelsResultObj | number)[] = [];

// onBand mode, need one more tick
// |---1---|---2---|---3---|---4---| need 5 tick
if (axis.onBand && ordinalExtent[1]) {
ordinalExtent[1]++;
}

// TODO: axisType: ordinalTime, pick the tick from each month/day/year/...

const step = Math.max((categoryInterval || 0) + 1, 1);
Expand Down Expand Up @@ -411,7 +417,17 @@ function makeLabelsByCustomizedCategoryInterval(axis: Axis, categoryInterval: Ca
const labelFormatter = makeLabelFormatter(axis);
const result: (MakeLabelsResultObj | number)[] = [];

zrUtil.each(ordinalScale.getTicks(), function (tick) {
const originTicks = ordinalScale.getTicks();
// onBand mode, need one more tick
if (axis.onBand && originTicks.length) {
// TODO: use array.at(-1) when lib target es2022
const lastTicks = originTicks[originTicks.length - 1];
originTicks.push({
...lastTicks,
value: lastTicks.value + 1
});
}
zrUtil.each(originTicks, function (tick) {
const rawLabel = ordinalScale.getLabel(tick);
const tickValue = tick.value;
if (categoryInterval(tick.value, rawLabel)) {
Expand Down
Loading
Loading