From 81f5cf416a124f1f9e44b7fc99ec031cf47648ed Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Sun, 10 Nov 2019 04:57:54 +0200 Subject: [PATCH] Performance optimizations when animations are disabled (#6710) * Don't copy _model when animations are disabled * Review comments --- src/controllers/controller.bar.js | 2 +- src/controllers/controller.bubble.js | 2 +- src/controllers/controller.doughnut.js | 2 +- src/controllers/controller.line.js | 2 +- src/controllers/controller.polarArea.js | 2 +- src/controllers/controller.radar.js | 5 +++-- src/core/core.controller.js | 17 ++++++++++++++--- src/core/core.element.js | 7 ++++++- 8 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 12ca5a534..6d89e0708 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -256,7 +256,7 @@ module.exports = DatasetController.extend({ me._updateElementGeometry(rectangle, index, reset, options); - rectangle.pivot(); + rectangle.pivot(me.chart._animationsDisabled); }, /** diff --git a/src/controllers/controller.bubble.js b/src/controllers/controller.bubble.js index 48c0a2ee4..50a9b2d04 100644 --- a/src/controllers/controller.bubble.js +++ b/src/controllers/controller.bubble.js @@ -122,7 +122,7 @@ module.exports = DatasetController.extend({ y: y, }; - point.pivot(); + point.pivot(me.chart._animationsDisabled); }, /** diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 8df290ad4..4b29d4226 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -271,7 +271,7 @@ module.exports = DatasetController.extend({ model.endAngle = model.startAngle + model.circumference; } - arc.pivot(); + arc.pivot(chart._animationsDisabled); }, calculateTotal: function() { diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 59793279e..d73332e75 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -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); } }, diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index 2e172ff80..b4c5ba480 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -220,7 +220,7 @@ module.exports = DatasetController.extend({ } }); - arc.pivot(); + arc.pivot(chart._animationsDisabled); }, countVisibleElements: function() { diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index 1a0bee2fa..049c6cf8e 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -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); } }, diff --git a/src/core/core.controller.js b/src/core/core.controller.js index ad841ca6e..e3fce6965 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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); + } } } diff --git a/src/core/core.element.js b/src/core/core.element.js index 89bbc59d0..dc98270c8 100644 --- a/src/core/core.element.js +++ b/src/core/core.element.js @@ -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); } -- 2.47.2