]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
New methods for array finding
authorNick Downie <nick@nickdownie.com>
Sun, 3 Aug 2014 18:19:54 +0000 (19:19 +0100)
committerNick Downie <nick@nickdownie.com>
Sun, 3 Aug 2014 18:19:54 +0000 (19:19 +0100)
src/Chart.Core.js

index 619028f205850d90e22608c1da32a7067584aefc..32ac8c65d48c8f0dbbbfdd1330afa9dd6715ad9e 100755 (executable)
                                return -1;
                        }
                },
+               where = helpers.where = function(collection, filterCallback){
+                       var filtered = [];
+
+                       helpers.each(collection, function(item){
+                               if (filterCallback(item)){
+                                       filtered.push(item);
+                               }
+                       });
+
+                       return filtered;
+               },
+               findNextWhere = helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex){
+                       // Default to start of the array
+                       if (!startIndex){
+                               startIndex = -1;
+                       }
+                       for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
+                               var currentItem = arrayToSearch[i];
+                               if (filterCallback(currentItem)){
+                                       return currentItem;
+                               }
+                       };
+               },
+               findPreviousWhere = helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex){
+                       // Default to end of the array
+                       if (!startIndex){
+                               startIndex = arrayToSearch.length;
+                       }
+                       for (var i = startIndex - 1; i >= 0; i--) {
+                               var currentItem = arrayToSearch[i];
+                               if (filterCallback(currentItem)){
+                                       return currentItem;
+                               }
+                       };
+               },
                inherits = helpers.inherits = function(extensions){
                        //Basic javascript inheritance based on the model created in Backbone.js
                        var parent = this;
                        var ctx = chart.ctx,
                                width = chart.canvas.width,
                                height = chart.canvas.height;
-                       //console.log(width + " x " + height);
+
                        if (window.devicePixelRatio) {
                                ctx.canvas.style.width = width + "px";
                                ctx.canvas.style.height = height + "px";