From: Tanner Linsley Date: Sun, 12 Apr 2015 00:37:01 +0000 (-0600) Subject: Merge remote-tracking branch 'origin/animation-refactory' into animation-refactory X-Git-Tag: v2.0-alpha~37^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99bf85e91335a3656c7739a7aba7a008c79db6ed;p=thirdparty%2FChart.js.git Merge remote-tracking branch 'origin/animation-refactory' into animation-refactory Conflicts: src/Chart.Core.js --- 99bf85e91335a3656c7739a7aba7a008c79db6ed diff --cc src/Chart.Core.js index 6635e1bd8,565ceeeb1..2c1229d15 --- a/src/Chart.Core.js +++ b/src/Chart.Core.js @@@ -2075,12 -2075,10 +2075,12 @@@ }); Chart.animationService = { + frameDuration: 17, animations: [], + dropFrames: 0, - addAnimation: function(chart, animationObject) { + addAnimation: function(chartInstance, animationObject) { for (var index = 0; index < this.animations.length; ++ index){ - if (this.animations[index].chart === chart){ + if (this.animations[index].chartInstance === chartInstance){ // replacing an in progress animation this.animations[index].lastTimeRun = null; this.animations[index].animationObject = animationObject; @@@ -2095,20 -2093,27 +2095,35 @@@ }); // If there are no animations queued, manually kickstart a digest, for lack of a better word - if(!this.animations.length){ - helpers.requestAnimFrame(this.startDigest); + if (this.animations.length) { + helpers.requestAnimFrame.call(window, this.digestWrapper); } }, + // Cancel the animation for a given chart instance + cancelAnimation: function(chartInstance) { + var index = helpers.findNextWhere(this.animations, function(animationWrapper) { + return animationWrapper.chartInstance === chartInstance; + }); + + if (index != -1) + { + this.animations.splice(index, 1); + } + }, + // calls startDigest with the proper context + digestWrapper: function() { + Chart.animationService.startDigest.call(Chart.animationService); + }, startDigest: function() { + var startTime = Date.now(); + var framesToDrop = 0; + + if(this.dropFrames > 1){ + framesToDrop = Math.floor(this.dropFrames); + this.dropFrames -= framesToDrop; + } + for (var i = 0; i < this.animations.length; i++) { var currentAnimation = this.animations[i]; @@@ -2116,10 -2121,10 +2131,10 @@@ if (currentAnimation.animationObject.currentStep === null){ currentAnimation.animationObject.currentStep = 0; } else { - currentAnimation.animationObject.currentStep++; + currentAnimation.animationObject.currentStep += 1 + framesToDrop; } - currentAnimation.animationObject.render(currentAnimation.animationObject); + currentAnimation.animationObject.render(currentAnimation.chartInstance, currentAnimation.animationObject); if (currentAnimation.animationObject.currentStep == currentAnimation.animationObject.numSteps){ // executed the last frame. Remove the animation. @@@ -2129,17 -2134,9 +2144,17 @@@ } } + var endTime = Date.now(); + var delay = endTime - startTime - this.frameDuration; + var frameDelay = delay / this.frameDuration; + + if(frameDelay > 1){ + this.dropFrames += frameDelay; + } + // Do we have more stuff to animate? if (this.animations.length > 0){ - requestAnimationFrame(this.startDigest); + helpers.requestAnimFrame.call(window, this.digestWrapper); } } };