diff --git a/src/Chart.Core.js b/src/Chart.Core.js index 296844ea2..2b8aa78f8 100755 --- a/src/Chart.Core.js +++ b/src/Chart.Core.js @@ -932,15 +932,27 @@ 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(); @@ -1347,6 +1359,17 @@ } }); + 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(){