mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Performance optimizations when animations are disabled (#6710)
* Don't copy _model when animations are disabled * Review comments
This commit is contained in:
parent
46aff21a3d
commit
81f5cf416a
@ -256,7 +256,7 @@ module.exports = DatasetController.extend({
|
||||
|
||||
me._updateElementGeometry(rectangle, index, reset, options);
|
||||
|
||||
rectangle.pivot();
|
||||
rectangle.pivot(me.chart._animationsDisabled);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -122,7 +122,7 @@ module.exports = DatasetController.extend({
|
||||
y: y,
|
||||
};
|
||||
|
||||
point.pivot();
|
||||
point.pivot(me.chart._animationsDisabled);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -271,7 +271,7 @@ module.exports = DatasetController.extend({
|
||||
model.endAngle = model.startAngle + model.circumference;
|
||||
}
|
||||
|
||||
arc.pivot();
|
||||
arc.pivot(chart._animationsDisabled);
|
||||
},
|
||||
|
||||
calculateTotal: function() {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -220,7 +220,7 @@ module.exports = DatasetController.extend({
|
||||
}
|
||||
});
|
||||
|
||||
arc.pivot();
|
||||
arc.pivot(chart._animationsDisabled);
|
||||
},
|
||||
|
||||
countVisibleElements: function() {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user