Performance optimizations when animations are disabled (#6710)

* Don't copy _model when animations are disabled

* Review comments
This commit is contained in:
Jukka Kurkela 2019-11-10 04:57:54 +02:00 committed by Evert Timberg
parent 46aff21a3d
commit 81f5cf416a
8 changed files with 28 additions and 11 deletions

View File

@ -256,7 +256,7 @@ module.exports = DatasetController.extend({
me._updateElementGeometry(rectangle, index, reset, options);
rectangle.pivot();
rectangle.pivot(me.chart._animationsDisabled);
},
/**

View File

@ -122,7 +122,7 @@ module.exports = DatasetController.extend({
y: y,
};
point.pivot();
point.pivot(me.chart._animationsDisabled);
},
/**

View File

@ -271,7 +271,7 @@ module.exports = DatasetController.extend({
model.endAngle = model.startAngle + model.circumference;
}
arc.pivot();
arc.pivot(chart._animationsDisabled);
},
calculateTotal: function() {

View File

@ -103,7 +103,7 @@ module.exports = DatasetController.extend({
// Now pivot the point for animation
for (i = 0, ilen = points.length; i < ilen; ++i) {
points[i].pivot();
points[i].pivot(me.chart._animationsDisabled);
}
},

View File

@ -220,7 +220,7 @@ module.exports = DatasetController.extend({
}
});
arc.pivot();
arc.pivot(chart._animationsDisabled);
},
countVisibleElements: function() {

View File

@ -75,6 +75,7 @@ module.exports = DatasetController.extend({
var line = meta.dataset;
var points = meta.data || [];
var config = me._config;
var animationsDisabled = me.chart._animationsDisabled;
var i, ilen;
// Compatibility: If the properties are defined with only the old name, use those values
@ -90,7 +91,7 @@ module.exports = DatasetController.extend({
// Model
line._model = me._resolveDatasetElementOptions();
line.pivot();
line.pivot(animationsDisabled);
// Update Points
for (i = 0, ilen = points.length; i < ilen; ++i) {
@ -102,7 +103,7 @@ module.exports = DatasetController.extend({
// Now pivot the point for animation
for (i = 0, ilen = points.length; i < ilen; ++i) {
points[i].pivot();
points[i].pivot(animationsDisabled);
}
},

View File

@ -116,6 +116,14 @@ function initConfig(config) {
return config;
}
function isAnimationDisabled(config) {
return !config.animation || !(
config.animation.duration ||
(config.hover && config.hover.animationDuration) ||
config.responsiveAnimationDuration
);
}
function updateConfig(chart) {
var newOptions = chart.options;
@ -129,6 +137,7 @@ function updateConfig(chart) {
newOptions);
chart.options = chart.config.options = newOptions;
chart._animationsDisabled = isAnimationDisabled(newOptions);
chart.ensureScalesHaveIDs();
chart.buildOrUpdateScales();
@ -692,9 +701,11 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
var me = this;
var i, ilen;
for (i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
if (me.isDatasetVisible(i)) {
me.getDatasetMeta(i).controller.transition(easingValue);
if (!me._animationsDisabled) {
for (i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
if (me.isDatasetVisible(i)) {
me.getDatasetMeta(i).controller.transition(easingValue);
}
}
}

View File

@ -63,8 +63,13 @@ class Element {
this.hidden = false;
}
pivot() {
pivot(animationsDisabled) {
var me = this;
if (animationsDisabled) {
me._view = me._model;
return me;
}
if (!me._view) {
me._view = helpers.extend({}, me._model);
}