]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix animation regression introduced by #5331 (#6108)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Mon, 4 Mar 2019 08:11:57 +0000 (10:11 +0200)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Mon, 4 Mar 2019 08:11:57 +0000 (09:11 +0100)
src/core/core.animations.js

index 54645ddd9968b194809458cbff622ca5a382fccf..df6100f5b1eeeca2c01e1e58e3cc33f4b91114a6 100644 (file)
@@ -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);