]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Remove helpers.where and unnecessary calls to helpers.each (#6860)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Wed, 25 Dec 2019 13:21:42 +0000 (05:21 -0800)
committerEvert Timberg <evert.timberg+github@gmail.com>
Wed, 25 Dec 2019 13:21:42 +0000 (08:21 -0500)
* Remove unnecessary calls to helpers.each

* Remove where

docs/getting-started/v3-migration.md
src/controllers/controller.polarArea.js
src/core/core.datasetController.js
src/core/core.layouts.js
src/helpers/index.js
src/index.js
src/platforms/platform.dom.js
src/plugins/plugin.legend.js
src/scales/scale.radialLinear.js
test/specs/core.helpers.tests.js

index 9fa7610fac07d2bbaecd3db6fca5add8e8970525..b55ad538150eef26cf5056c34fd7e888e67a7f66 100644 (file)
@@ -66,6 +66,7 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released
 * `helpers.removeEvent`
 * `helpers.roundedRect`
 * `helpers.scaleMerge`
+* `helpers.where`
 * `Chart.Controller`
 * `Chart.chart.chart`
 * `Chart.types`
index c31663492d172557e386bf791d0e68110f0ea452..fd6bc877c86f1fc0115f1796cad0c434c577ae44 100644 (file)
@@ -221,7 +221,7 @@ module.exports = DatasetController.extend({
                var meta = this._cachedMeta;
                var count = 0;
 
-               helpers.each(meta.data, function(element, index) {
+               meta.data.forEach(function(element, index) {
                        if (!isNaN(dataset.data[index]) && !element.hidden) {
                                count++;
                        }
index 7ce9c0d66aa97ba112a09be8a9d0b07d17300e2f..2c5e35e9ed4708e9913dddcc5f380e33c8108c8c 100644 (file)
@@ -36,7 +36,7 @@ function listenArrayEvents(array, listener) {
                                var args = Array.prototype.slice.call(arguments);
                                var res = base.apply(this, args);
 
-                               helpers.each(array._chartjs.listeners, function(object) {
+                               array._chartjs.listeners.forEach(function(object) {
                                        if (typeof object[method] === 'function') {
                                                object[method].apply(object, args);
                                        }
index ac1b3eec9e9714810c3ad1a63f87286669fbf5cd..da0a79950eba282c72f9cfb2bbf34d19a50e4bdb 100644 (file)
@@ -8,11 +8,11 @@ var extend = helpers.extend;
 const STATIC_POSITIONS = ['left', 'top', 'right', 'bottom'];
 
 function filterByPosition(array, position) {
-       return helpers.where(array, v => v.pos === position);
+       return array.filter(v => v.pos === position);
 }
 
 function filterDynamicPositionByAxis(array, axis) {
-       return helpers.where(array, v => STATIC_POSITIONS.indexOf(v.pos) === -1 && v.box.axis === axis);
+       return array.filter(v => STATIC_POSITIONS.indexOf(v.pos) === -1 && v.box.axis === axis);
 }
 
 function sortByWeight(array, reverse) {
index 6bd61b40be5d7f78c2b32be76f82a5428a3c4332..51827b59c75e71ffdbcf2b3c77a1b2c0633048a4 100644 (file)
@@ -48,20 +48,6 @@ export default {
        math,
        rtl,
 
-       where: function(collection, filterCallback) {
-               if (coreHelpers.isArray(collection) && Array.prototype.filter) {
-                       return collection.filter(filterCallback);
-               }
-               var filtered = [];
-
-               coreHelpers.each(collection, function(item) {
-                       if (filterCallback(item)) {
-                               filtered.push(item);
-                       }
-               });
-
-               return filtered;
-       },
        findIndex: Array.prototype.findIndex ?
                function(array, callback, scope) {
                        return array.findIndex(callback, scope);
index c8a88d7d41aa4abe12b46fb975aaca1af05fe502..92ed94caa2650f8b794265038c7b5bceb72f4e48 100644 (file)
@@ -22,8 +22,9 @@ Chart.Ticks = require('./core/core.ticks');
 Chart.Tooltip = require('./core/core.tooltip');
 
 // Register built-in scales
-var scales = require('./scales');
-Chart.helpers.each(scales, function(scale, type) {
+const scales = require('./scales');
+Object.keys(scales).forEach(function(type) {
+       const scale = scales[type];
        Chart.scaleService.registerScaleType(type, scale, scale._defaults);
 });
 
index 7b0ed16245da4df21a0bdca2604a7c11b803d7f8..c4026342212ce5197d931f578ef7402a2e83e7b1 100644 (file)
@@ -216,7 +216,7 @@ function watchForRender(node, handler) {
                }
        };
 
-       helpers.each(ANIMATION_START_EVENTS, function(type) {
+       ANIMATION_START_EVENTS.forEach(function(type) {
                addListener(node, type, proxy);
        });
 
@@ -235,7 +235,7 @@ function unwatchForRender(node) {
        var proxy = expando.renderProxy;
 
        if (proxy) {
-               helpers.each(ANIMATION_START_EVENTS, function(type) {
+               ANIMATION_START_EVENTS.forEach(function(type) {
                        removeListener(node, type, proxy);
                });
 
@@ -382,14 +382,14 @@ module.exports = {
        },
 
        releaseContext: function(context) {
-               var canvas = context.canvas;
+               const canvas = context.canvas;
                if (!canvas[EXPANDO_KEY]) {
                        return;
                }
 
-               var initial = canvas[EXPANDO_KEY].initial;
+               const initial = canvas[EXPANDO_KEY].initial;
                ['height', 'width'].forEach(function(prop) {
-                       var value = initial[prop];
+                       const value = initial[prop];
                        if (helpers.isNullOrUndef(value)) {
                                canvas.removeAttribute(prop);
                        } else {
@@ -397,8 +397,9 @@ module.exports = {
                        }
                });
 
-               helpers.each(initial.style || {}, function(value, key) {
-                       canvas.style[key] = value;
+               const style = initial.style || {};
+               Object.keys(style).forEach(function(key) {
+                       canvas.style[key] = style[key];
                });
 
                // The canvas render size might have been changed (and thus the state stack discarded),
index 8bceb9f5312b36ed4691f2bcfa875f1e8cea6baa..5913809e3c6e89ca7e3b09e0bf5516f2930e8775 100644 (file)
@@ -274,7 +274,7 @@ class Legend extends Element {
                        ctx.textAlign = 'left';
                        ctx.textBaseline = 'middle';
 
-                       helpers.each(me.legendItems, function(legendItem, i) {
+                       me.legendItems.forEach(function(legendItem, i) {
                                var boxWidth = getBoxWidth(labelOpts, fontSize);
                                var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
 
@@ -304,7 +304,7 @@ class Legend extends Element {
                        var currentColWidth = 0;
                        var currentColHeight = 0;
 
-                       helpers.each(me.legendItems, function(legendItem, i) {
+                       me.legendItems.forEach(function(legendItem, i) {
                                var boxWidth = getBoxWidth(labelOpts, fontSize);
                                var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
 
@@ -471,7 +471,7 @@ class Legend extends Element {
                helpers.rtl.overrideTextDirection(me.ctx, opts.textDirection);
 
                var itemHeight = fontSize + labelOpts.padding;
-               helpers.each(me.legendItems, function(legendItem, i) {
+               me.legendItems.forEach(function(legendItem, i) {
                        var textWidth = ctx.measureText(legendItem.text).width;
                        var width = boxWidth + (fontSize / 2) + textWidth;
                        var x = cursor.x;
index b2c0b97573979830ff64ed0259a8e7584e894d9c..f6fa1c8e3803e1dc4c32a45d38b376ee7d5a5e39 100644 (file)
@@ -448,7 +448,7 @@ class RadialLinearScale extends LinearScaleBase {
                }
 
                if (gridLineOpts.display) {
-                       helpers.each(me.ticks, function(tick, index) {
+                       me.ticks.forEach(function(tick, index) {
                                if (index !== 0) {
                                        offset = me.getDistanceFromCenterForValue(me._tickValues[index]);
                                        drawRadiusLine(me, gridLineOpts, offset, index);
@@ -503,7 +503,7 @@ class RadialLinearScale extends LinearScaleBase {
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
 
-               helpers.each(me.ticks, function(tick, index) {
+               me.ticks.forEach(function(tick, index) {
                        if (index === 0 && !opts.reverse) {
                                return;
                        }
index eecdc69a9e3b46cc9b9b29bfbb89b9560949c8dd..4ae2d1c62c5cda0f0146fb26f6ed87f55cfea688 100644 (file)
@@ -11,7 +11,6 @@ describe('Core helper tests', function() {
                var callback = function(item) {
                        return item > 2;
                };
-               expect(helpers.where(data, callback)).toEqual([6, 7]);
                expect(helpers.findNextWhere(data, callback)).toEqual(6);
                expect(helpers.findNextWhere(data, callback, 2)).toBe(7);
                expect(helpers.findNextWhere(data, callback, 4)).toBe(undefined);