math,
rtl,
- findIndex: Array.prototype.findIndex ?
- function(array, callback, scope) {
- return array.findIndex(callback, scope);
- } :
- function(array, callback, scope) {
- scope = scope === undefined ? array : scope;
- for (var i = 0, ilen = array.length; i < ilen; ++i) {
- if (callback.call(scope, array[i], i, array)) {
- return i;
- }
- }
- return -1;
- },
- findNextWhere: function(arrayToSearch, filterCallback, startIndex) {
- // Default to start of the array
- if (coreHelpers.isNullOrUndef(startIndex)) {
- startIndex = -1;
- }
- for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
- var currentItem = arrayToSearch[i];
- if (filterCallback(currentItem)) {
- return currentItem;
- }
- }
- },
- findPreviousWhere: function(arrayToSearch, filterCallback, startIndex) {
- // Default to end of the array
- if (coreHelpers.isNullOrUndef(startIndex)) {
- startIndex = arrayToSearch.length;
- }
- for (var i = startIndex - 1; i >= 0; i--) {
- var currentItem = arrayToSearch[i];
- if (filterCallback(currentItem)) {
- return currentItem;
- }
- }
- },
// Implementation of the nice number algorithm used in determining where axis labels will go
niceNum: function(range, round) {
var exponent = Math.floor(math.log10(range));
helpers = window.Chart.helpers;
});
- it('should filter an array', function() {
- var data = [-10, 0, 6, 0, 7];
- var callback = function(item) {
- return item > 2;
- };
- expect(helpers.findNextWhere(data, callback)).toEqual(6);
- expect(helpers.findNextWhere(data, callback, 2)).toBe(7);
- expect(helpers.findNextWhere(data, callback, 4)).toBe(undefined);
- expect(helpers.findPreviousWhere(data, callback)).toBe(7);
- expect(helpers.findPreviousWhere(data, callback, 3)).toBe(6);
- expect(helpers.findPreviousWhere(data, callback, 0)).toBe(undefined);
- });
-
it('should generate integer ids', function() {
var uid = helpers.uid();
expect(uid).toEqual(jasmine.any(Number));