From bf37db0287f65a0a91bad9cf18743ae94bd82a30 Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 29 Oct 2019 23:01:44 +0800 Subject: [PATCH] fix(axis): fix extra ticks added caused by rounding error. add test cases for splitArea --- src/coord/Axis.js | 8 +- test/axis-splitArea.html | 182 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 test/axis-splitArea.html diff --git a/src/coord/Axis.js b/src/coord/Axis.js index 2db0138ee..1af761a82 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 000000000..2ac8686a3 --- /dev/null +++ b/test/axis-splitArea.html @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + -- GitLab