Skip to content

Commit

Permalink
step 1,2,3 instead of 1,1,2,3. some chore and a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Mar 3, 2019
1 parent 6fd01b3 commit 069cb87
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core/core.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@ module.exports = {
*/
advance: function() {
var animations = this.animations;
var animation, chart, nextStep;
var animation, chart, steps, nextStep;
var i = 0;

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

nextStep = (animation.currentStep || 0) + 1;
animation.currentStep = Math.floor((Date.now() - animation.startTime) / animation.duration * animation.numSteps);
animation.currentStep = Math.min(Math.max(nextStep, 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 * steps) + 1;
animation.currentStep = Math.min(nextStep, steps);

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

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

0 comments on commit 069cb87

Please sign in to comment.