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): xAxis axisTick custom interval funciton work error with boundaryGap false #20436

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
25 changes: 21 additions & 4 deletions src/coord/Axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
* under the License.
*/

import {each, map} from 'zrender/src/core/util';
import {each, map, isFunction} from 'zrender/src/core/util';
import {linearMap, getPixelPrecision, round} from '../util/number';
import {
createAxisTicks,
createAxisLabels,
calculateCategoryInterval
} from './axisTickLabelBuilder';
import { getOptionCategoryInterval } from './axisHelper';
import Scale from '../scale/Scale';
import { DimensionName, ScaleDataValue, ScaleTick } from '../util/types';
import OrdinalScale from '../scale/Ordinal';
Expand Down Expand Up @@ -188,9 +189,10 @@ class Axis {
}, this);

const alignWithLabel = tickModel.get('alignWithLabel');
const isCustomIntervalTick = isFunction(getOptionCategoryInterval(tickModel as AxisBaseModel));

fixOnBandTicksCoords(
this, ticksCoords, alignWithLabel, opt.clamp
this, ticksCoords, alignWithLabel, isCustomIntervalTick, opt.clamp
);

return ticksCoords;
Expand Down Expand Up @@ -289,7 +291,7 @@ function fixExtentWithBands(extent: [number, number], nTick: number): void {
// to displayed labels. (So we should not use `getBandWidth` in this
// case).
function fixOnBandTicksCoords(
axis: Axis, ticksCoords: TickCoord[], alignWithLabel: boolean, clamp: boolean
axis: Axis, ticksCoords: TickCoord[], alignWithLabel: boolean, isCustomIntervalTick: boolean, clamp: boolean
) {
const ticksLen = ticksCoords.length;

Expand All @@ -300,7 +302,22 @@ function fixOnBandTicksCoords(
const axisExtent = axis.getExtent();
let last;
let diffSize;
if (ticksLen === 1) {
if (isCustomIntervalTick) {
const dataExtent = axis.scale.getExtent();
const shift = (axisExtent[1] - axisExtent[0]) / (dataExtent[1] - dataExtent[0] + 1);
each(ticksCoords, function (ticksItem) {
ticksItem.coord -= shift / 2;
});
last = {
coord: axisExtent[1],
tickValue: dataExtent[1] + 1
};
// if have tick add last tick
if (ticksCoords.length) {
ticksCoords.push(last);
}
}
else if (ticksLen === 1) {
ticksCoords[0].coord = axisExtent[0];
last = ticksCoords[1] = {coord: axisExtent[1], tickValue: ticksCoords[0].tickValue};
}
Expand Down
85 changes: 83 additions & 2 deletions test/axis-interval.html

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