Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance optimizations when animations are disabled #6710

Merged
merged 2 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works, but would probably better belong in transition. My understanding is that the main point of pivot is to reset _start and that the point of transition is to set _view (we should probably document the functions)

pivot and transition both have a big of junk in them right now that are mainly cause by Tooltip not properly initializing these variables in the way that other elements do. I looked a little bit at trying to untangle some of it earlier, but didn't have the time. I don't think pivot should be initializing _view (why does it only do it once? what about subsequent updates) and I don't think transition should have to initialize _view and _start (_view should probably be initialized in a constructor and _start is already set in pivot, so we should make sure Tooltip calls pivot like everything else does)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to take a deeper look at improving the animation system, in the near future (when I have enough time). But it will be another PR, if I ever get it done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wouldn't try to make any of the other changes in this PR. But maybe we should at least pass the animationsDisabled flag to transition in this PR so that we don't drift further from the original intentions of the methods?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so how about breaking it a little then? :)
pivot should work the same, animations disabled or not.
transition is not called when animations are disabled (for dataset elements, for now)

return me;
}

if (!me._view) {
me._view = helpers.extend({}, me._model);
}
Expand Down