]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Build labelDiffs cache once per update (#3211)
authorTomasz Moń <desowin@gmail.com>
Sun, 4 Sep 2016 07:22:27 +0000 (10:22 +0300)
committerTomasz Moń <desowin@gmail.com>
Sun, 4 Sep 2016 07:22:27 +0000 (10:22 +0300)
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

index aac6131eddfbd8ce226611dd11c333ec26f2c643..f88fea19ac7e0f831935d95078bb938d28744841 100755 (executable)
@@ -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) {