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()).
This commit is contained in:
Tomasz Moń
2016-09-04 10:22:27 +03:00
parent 020ac35852
commit cd24895cd1

View File

@@ -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) {