Skip to content

Commit

Permalink
Fix animation regression introduced by #5331 (#6108)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle authored and simonbrunel committed Mar 4, 2019
1 parent 35273ee commit 344628b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/core.animations.js
Expand Up @@ -93,20 +93,24 @@ module.exports = {
*/
advance: function() {
var animations = this.animations;
var animation, chart;
var animation, chart, numSteps, nextStep;
var i = 0;

// 1 animation per chart, so we are looping charts here
while (i < animations.length) {
animation = animations[i];
chart = animation.chart;
numSteps = animation.numSteps;

animation.currentStep = Math.floor((Date.now() - animation.startTime) / animation.duration * animation.numSteps);
animation.currentStep = Math.min(animation.currentStep, animation.numSteps);
// Make sure that currentStep starts at 1
// https://github.com/chartjs/Chart.js/issues/6104
nextStep = Math.floor((Date.now() - animation.startTime) / animation.duration * numSteps) + 1;
animation.currentStep = Math.min(nextStep, numSteps);

helpers.callback(animation.render, [chart, animation], chart);
helpers.callback(animation.onAnimationProgress, [animation], chart);

if (animation.currentStep >= animation.numSteps) {
if (animation.currentStep >= numSteps) {
helpers.callback(animation.onAnimationComplete, [animation], chart);
chart.animating = false;
animations.splice(i, 1);
Expand Down

0 comments on commit 344628b

Please sign in to comment.