From: Tanner Linsley Date: Sun, 12 Apr 2015 00:34:06 +0000 (-0600) Subject: Frame Dropper X-Git-Tag: v2.0-alpha~37^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0c208be581f5ef25653092dec951d0c07fc1a0a;p=thirdparty%2FChart.js.git Frame Dropper --- diff --git a/src/Chart.Core.js b/src/Chart.Core.js index 36f58723c..6635e1bd8 100755 --- a/src/Chart.Core.js +++ b/src/Chart.Core.js @@ -2075,7 +2075,9 @@ }); Chart.animationService = { + frameDuration: 17, animations: [], + dropFrames: 0, addAnimation: function(chart, animationObject) { for (var index = 0; index < this.animations.length; ++ index){ if (this.animations[index].chart === chart){ @@ -2099,6 +2101,14 @@ }, 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]; @@ -2106,7 +2116,7 @@ if (currentAnimation.animationObject.currentStep === null){ currentAnimation.animationObject.currentStep = 0; } else { - currentAnimation.animationObject.currentStep++; + currentAnimation.animationObject.currentStep += 1 + framesToDrop; } currentAnimation.animationObject.render(currentAnimation.animationObject); @@ -2119,6 +2129,14 @@ } } + 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);