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

#5329 Animation duration is not consistent across browsers #5331

Merged
merged 4 commits into from
Jan 2, 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
21 changes: 5 additions & 16 deletions src/core/core.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ defaults._set('global', {
});

module.exports = {
frameDuration: 17,
animations: [],
dropFrames: 0,
request: null,

/**
Expand All @@ -30,6 +28,8 @@ module.exports = {
var i, ilen;

animation.chart = chart;
animation.startTime = Date.now();
animation.duration = duration;

if (!lazy) {
chart.animating = true;
Expand Down Expand Up @@ -79,19 +79,8 @@ module.exports = {
*/
startDigest: function() {
var me = this;
var startTime = Date.now();
var framesToDrop = 0;

if (me.dropFrames > 1) {
framesToDrop = Math.floor(me.dropFrames);
me.dropFrames = me.dropFrames % 1;
}

me.advance(1 + framesToDrop);

var endTime = Date.now();

me.dropFrames += (endTime - startTime) / me.frameDuration;
me.advance();

// Do we have more stuff to animate?
if (me.animations.length > 0) {
Expand All @@ -102,7 +91,7 @@ module.exports = {
/**
* @private
*/
advance: function(count) {
advance: function() {
var animations = this.animations;
var animation, chart;
var i = 0;
Expand All @@ -111,7 +100,7 @@ module.exports = {
animation = animations[i];
chart = animation.chart;

animation.currentStep = (animation.currentStep || 0) + count;
animation.currentStep = Math.floor((Date.now() - animation.startTime) / animation.duration * animation.numSteps);
animation.currentStep = Math.min(animation.currentStep, animation.numSteps);

helpers.callback(animation.render, [chart, animation], chart);
Expand Down
10 changes: 6 additions & 4 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,24 @@ module.exports = function(Chart) {
};
}

var duration = config.duration;
var animationOptions = me.options.animation;
var duration = typeof config.duration !== 'undefined'
? config.duration
: animationOptions && animationOptions.duration;
var lazy = config.lazy;

if (plugins.notify(me, 'beforeRender') === false) {
return;
}

var animationOptions = me.options.animation;
var onComplete = function(animation) {
plugins.notify(me, 'afterRender');
helpers.callback(animationOptions && animationOptions.onComplete, [animation], me);
};

if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
if (animationOptions && duration) {
var animation = new Animation({
numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
numSteps: duration / 16.66, // 60 fps
easing: config.easing || animationOptions.easing,

render: function(chart, animationObject) {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/core.controller.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ describe('Chart', function() {
expect(this.addAnimationSpy).toHaveBeenCalledWith(
this.chart,
jasmine.objectContaining({easing: 'linear'}),
undefined,
500,
undefined
);
});
Expand Down