diff --git a/src/coord/Axis.js b/src/coord/Axis.js index 2db0138eea8afe70086a8b8d459485be857cd9d2..1af761a828efec176050f70bde7f6bc061b0b7e4 100644 --- a/src/coord/Axis.js +++ b/src/coord/Axis.js @@ -18,7 +18,7 @@ */ import {each, map} from 'zrender/src/core/util'; -import {linearMap, getPixelPrecision} from '../util/number'; +import {linearMap, getPixelPrecision, round} from '../util/number'; import { createAxisTicks, createAxisLabels, @@ -307,7 +307,6 @@ function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWith last = ticksCoords[1] = {coord: axisExtent[0]}; } else { - var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue; var shift = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen; @@ -330,6 +329,7 @@ function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWith var inverse = axisExtent[0] > axisExtent[1]; + // Handling clamp. if (littleThan(ticksCoords[0].coord, axisExtent[0])) { clamp ? (ticksCoords[0].coord = axisExtent[0]) : ticksCoords.shift(); } @@ -344,6 +344,10 @@ function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWith } function littleThan(a, b) { + // Avoid rounding error cause calculated tick coord different with extent. + // It may cause an extra unecessary tick added. + a = round(a); + b = round(b); return inverse ? a > b : a < b; } } diff --git a/test/axis-splitArea.html b/test/axis-splitArea.html new file mode 100644 index 0000000000000000000000000000000000000000..2ac8686a32f317416f410253fbad600f69894026 --- /dev/null +++ b/test/axis-splitArea.html @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + +