* `helpers.removeEvent`
* `helpers.roundedRect`
* `helpers.scaleMerge`
+* `helpers.where`
* `Chart.Controller`
* `Chart.chart.chart`
* `Chart.types`
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++;
}
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);
}
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) {
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);
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);
});
}
};
- helpers.each(ANIMATION_START_EVENTS, function(type) {
+ ANIMATION_START_EVENTS.forEach(function(type) {
addListener(node, type, proxy);
});
var proxy = expando.renderProxy;
if (proxy) {
- helpers.each(ANIMATION_START_EVENTS, function(type) {
+ ANIMATION_START_EVENTS.forEach(function(type) {
removeListener(node, type, proxy);
});
},
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 {
}
});
- 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),
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;
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;
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;
}
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);
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;
}
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);