},
// Cancel the animation for a given chart instance
cancelAnimation: function(chartInstance) {
- var index = helpers.findNextWhere(this.animations, function(animationWrapper) {
+ var index = helpers.findIndex(this.animations, function(animationWrapper) {
return animationWrapper.chartInstance === chartInstance;
});
- if (index) {
+ if (index !== -1) {
this.animations.splice(index, 1);
chartInstance.animating = false;
}
this.dropFrames = this.dropFrames % 1;
}
- for (var i = 0; i < this.animations.length; i++) {
+ var i = 0;
+ while (i < this.animations.length) {
if (this.animations[i].animationObject.currentStep === null) {
this.animations[i].animationObject.currentStep = 0;
}
// executed the last frame. Remove the animation.
this.animations[i].chartInstance.animating = false;
+
this.animations.splice(i, 1);
- // Keep the index in place to offset the splice
- i--;
+ } else {
+ ++i;
}
}
return filtered;
};
+ helpers.findIndex = function(arrayToSearch, callback, thisArg) {
+ var index = -1;
+ if (Array.prototype.findIndex) {
+ index = arrayToSearch.findIndex(callback, thisArg);
+ } else {
+ for (var i = 0; i < arrayToSearch.length; ++i) {
+ thisArg = thisArg !== undefined ? thisArg : arrayToSearch;
+
+ if (callback.call(thisArg, arrayToSearch[i], i, arrayToSearch)) {
+ index = i;
+ break;
+ }
+ }
+ }
+
+ return index;
+ };
helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
// Default to start of the array
if (startIndex === undefined || startIndex === null) {