From: Tomasz Moń Date: Sun, 4 Sep 2016 07:22:27 +0000 (+0300) Subject: Build labelDiffs cache once per update (#3211) X-Git-Tag: v2.3.0-rc.1~1^2~8^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd24895cd1b5c5fc29b4c4548bd8a0d2c2727475;p=thirdparty%2FChart.js.git 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()). --- 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) {