]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Chart animations will now use the animation service provided in Chart.animationService.
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 11 Apr 2015 23:02:50 +0000 (19:02 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 11 Apr 2015 23:02:50 +0000 (19:02 -0400)
src/Chart.Core.js

index 296844ea2ecc5f863ce894bd66d900ddb2ecc810..2b8aa78f872ae8ad128fbb0165d12f1b00841635 100755 (executable)
                        if (reflow){
                                this.reflow();
                        }
+                       
                        if (this.options.animation && !reflow){
-                               helpers.animationLoop(
-                                       this.draw,
-                                       this.options.animationSteps,
-                                       this.options.animationEasing,
-                                       this.options.onAnimationProgress,
-                                       this.options.onAnimationComplete,
-                                       this
-                               );
+                               var animation = new Chart.Animation();
+                               animation.numSteps = this.options.animationSteps;
+                               animation.minSteps = 10; // TODO: add an option for this
+                               animation.easing = this.options.animationEasing;
+                               
+                               // render function
+                               animation.render = function(chartInstance, animationObject) {
+                                       var easingFunction = helpers.easingEffects[animationObject.easing];
+                                       var stepDecimal = animationObject.currentStep / animationObject.numSteps;
+                                       var easeDecimal = easingFunction(stepDecimal);
+                                       
+                                       chartInstance.draw(chartInstance, easeDecimal, stepDecimal, currentStep);
+                               };
+                               
+                               // user events
+                               animation.onAnimationProgress = this.options.onAnimationProgress;
+                               animation.onAnimationComplete = this.options.onAnimationComplete;
+                               
+                               Chart.animationService.addAnimation(this, animation);
                        }
                        else{
                                this.draw();
                }
        });
 
+       Chart.Animation = Chart.Element.extend({
+               currentStep: null, // the current animation step
+               numSteps: 60, // default number of steps
+               minSteps: 10, // TODO: create an option for this
+               easing: "", // the easing to use for this animation
+               render: null, // render function used by the animation service
+               
+               onAnimationProgress: null, // user specified callback to fire on each step of the animation 
+               onAnimationComplete: null, // user specified callback to fire when the animation finishes
+       });
+       
        Chart.Tooltip = Chart.Element.extend({
                draw : function(){