From 98329ea120c1e3ce7d3a800fd61b0e10da34a107 Mon Sep 17 00:00:00 2001 From: Mark Ruys Date: Tue, 6 Sep 2016 21:43:44 +0200 Subject: [PATCH] Fix number of horizontal ticks when defined by callback function. --- src/core/core.scale.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index ca2546b26a3..c6e3a420ea5 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -523,6 +523,13 @@ module.exports = function(Chart) { var itemsToDraw = []; + var countTicks = 0; + for (var i = 0; i < me.ticks.length; i++) { + if (me.ticks[i] !== undefined && me.ticks[i] !== null) { + ++countTicks; + } + } + if (isHorizontal) { skipRatio = false; @@ -532,14 +539,14 @@ module.exports = function(Chart) { longestRotatedLabel /= 2; } - if ((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length > (me.width - (me.paddingLeft + me.paddingRight))) { - skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length) / (me.width - (me.paddingLeft + me.paddingRight))); + if ((longestRotatedLabel + optionTicks.autoSkipPadding) * countTicks > (me.width - (me.paddingLeft + me.paddingRight))) { + skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * countTicks) / (me.width - (me.paddingLeft + me.paddingRight))); } // if they defined a max number of optionTicks, // increase skipRatio until that number is met - if (maxTicks && me.ticks.length > maxTicks) { - while (!skipRatio || me.ticks.length / (skipRatio || 1) > maxTicks) { + if (maxTicks && countTicks > maxTicks) { + while (!skipRatio || countTicks / (skipRatio || 1) > maxTicks) { if (!skipRatio) { skipRatio = 1; }