From cd24895cd1b5c5fc29b4c4548bd8a0d2c2727475 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomasz=20Mo=C5=84?= Date: Sun, 4 Sep 2016 10:22:27 +0300 Subject: [PATCH] Build labelDiffs cache once per update (#3211) Previously buildLabelDiffs() was called at the end of buildTicks() and hence labelDiffs cache was calculated twice (in getMinimumBoxSize() and then in fitBox()). --- src/scales/scale.time.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index aac6131ed..f88fea19a 100755 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -87,8 +87,17 @@ module.exports = function(Chart) { return null; }, getLabelDiff: function(datasetIndex, index) { - if (typeof this.labelDiffs[datasetIndex] != 'undefined') { - return this.labelDiffs[datasetIndex][index]; + var me = this; + if (datasetIndex === null || index === null) { + return null; + } + + if (me.labelDiffs === undefined) { + me.buildLabelDiffs(); + } + + if (typeof me.labelDiffs[datasetIndex] != 'undefined') { + return me.labelDiffs[datasetIndex][index]; } return null; @@ -344,8 +353,8 @@ module.exports = function(Chart) { me.ctx.restore(); - // Build diff table as first tick and tick units are already determined. - me.buildLabelDiffs(); + // Invalidate label diffs cache + me.labelDiffs = undefined; }, // Get tooltip label getLabelForIndex: function(index, datasetIndex) { -- 2.47.3