Skip to content

Commit

Permalink
Performance optimizations when animations are disabled (#6710)
Browse files Browse the repository at this point in the history
* Don't copy _model when animations are disabled

* Review comments
  • Loading branch information
kurkle authored and etimberg committed Nov 10, 2019
1 parent 46aff21 commit 81f5cf4
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/controllers/controller.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ module.exports = DatasetController.extend({

me._updateElementGeometry(rectangle, index, reset, options);

rectangle.pivot();
rectangle.pivot(me.chart._animationsDisabled);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module.exports = DatasetController.extend({
y: y,
};

point.pivot();
point.pivot(me.chart._animationsDisabled);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.doughnut.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ module.exports = DatasetController.extend({
model.endAngle = model.startAngle + model.circumference;
}

arc.pivot();
arc.pivot(chart._animationsDisabled);
},

calculateTotal: function() {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.polarArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ module.exports = DatasetController.extend({
}
});

arc.pivot();
arc.pivot(chart._animationsDisabled);
},

countVisibleElements: function() {
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/controller.radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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);
}
},

Expand Down
17 changes: 14 additions & 3 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -129,6 +137,7 @@ function updateConfig(chart) {
newOptions);

chart.options = chart.config.options = newOptions;
chart._animationsDisabled = isAnimationDisabled(newOptions);
chart.ensureScalesHaveIDs();
chart.buildOrUpdateScales();

Expand Down Expand Up @@ -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);
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/core/core.element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 81f5cf4

Please sign in to comment.