From d449bbc83aa5ea94ad2912d593500e561d0d94bb Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 30 Jan 2020 16:23:40 -0800 Subject: [PATCH] Remove unused helpers (#7039) --- docs/getting-started/v3-migration.md | 3 +++ src/helpers/index.js | 37 ---------------------------- test/specs/core.helpers.tests.js | 13 ---------- 3 files changed, 3 insertions(+), 50 deletions(-) diff --git a/docs/getting-started/v3-migration.md b/docs/getting-started/v3-migration.md index 76d8a53d0..a7e8345a0 100644 --- a/docs/getting-started/v3-migration.md +++ b/docs/getting-started/v3-migration.md @@ -91,6 +91,9 @@ Animation system was completely rewritten in Chart.js v3. Each property can now * `helpers.addEvent` * `helpers.aliasPixel` * `helpers.configMerge` +* `helpers.findIndex` +* `helpers.findNextWhere` +* `helpers.findPreviousWhere` * `helpers.indexOf` * `helpers.lineTo` * `helpers.longestText` was moved to the `helpers.canvas` namespace and made private diff --git a/src/helpers/index.js b/src/helpers/index.js index df5d4fbd0..8e28efcdc 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -36,43 +36,6 @@ export default { 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)); diff --git a/test/specs/core.helpers.tests.js b/test/specs/core.helpers.tests.js index 308438e04..d7fc8e30d 100644 --- a/test/specs/core.helpers.tests.js +++ b/test/specs/core.helpers.tests.js @@ -6,19 +6,6 @@ describe('Core helper tests', function() { 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)); -- 2.47.2