diff --git a/src/coord/Axis.ts b/src/coord/Axis.ts index 6226e96b26..3a27d895ab 100644 --- a/src/coord/Axis.ts +++ b/src/coord/Axis.ts @@ -17,8 +17,8 @@ * under the License. */ -import {each, map} from 'zrender/src/core/util'; -import {linearMap, getPixelPrecision, round} from '../util/number'; +import { each, map, isFunction } from 'zrender/src/core/util'; +import { linearMap, getPixelPrecision, round } from '../util/number'; import { createAxisTicks, createAxisLabels, @@ -28,6 +28,7 @@ import { createAxisLabelsComputingContext, } from './axisTickLabelBuilder'; import Scale, { ScaleGetTicksOpt } from '../scale/Scale'; +import { getOptionCategoryInterval } from './axisHelper'; import { DimensionName, ScaleDataValue, ScaleTick } from '../util/types'; import OrdinalScale from '../scale/Ordinal'; import Model from '../model/Model'; @@ -207,9 +208,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; @@ -315,6 +317,7 @@ function fixOnBandTicksCoords( axis: Axis, ticksCoords: AxisTickCoord[], alignWithLabel: boolean, + isCustomIntervalTick: boolean, clamp: boolean ) { const ticksLen = ticksCoords.length; @@ -326,7 +329,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: AxisTickCoord) { + 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]; ticksCoords[0].onBand = true; last = ticksCoords[1] = {coord: axisExtent[1], tickValue: ticksCoords[0].tickValue, onBand: true}; @@ -335,7 +353,7 @@ function fixOnBandTicksCoords( const crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue; const shift = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen; - each(ticksCoords, function (ticksItem) { + each(ticksCoords, function (ticksItem: AxisTickCoord) { ticksItem.coord -= shift / 2; ticksItem.onBand = true; }); diff --git a/test/axis-interval.html b/test/axis-interval.html index b84c3c8ba7..a0b0b5c665 100644 --- a/test/axis-interval.html +++ b/test/axis-interval.html @@ -56,7 +56,7 @@

[ Test time axis interval ]    should not overlap when data zoom.

-

Test xAxis.axisTick.interval

+

Test xAxis.axisTick.interval with boundaryGap **true**

@@ -64,6 +64,14 @@

Test xAxis.axisTick.interval

+

Test xAxis.axisTick.interval with boundaryGap **false**

+
+
+
+
+
+
+
@@ -362,6 +370,9 @@

Test xAxis.axisTick.interval

], function (echarts) { var testArr = [ + [true, true, true, true], + [false, false, false, false], + [true, false, false, false], [true, false, true, true], [true, false, true, false], [false, true, true, false], @@ -389,6 +400,7 @@

Test xAxis.axisTick.interval

bottom: 30 }, xAxis: { + boundaryGap: true, type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu'], axisTick: { @@ -427,7 +439,76 @@

Test xAxis.axisTick.interval

+