Skip to content

Commit

Permalink
Remove a couple calls to helpers.each (#6594)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored and etimberg committed Oct 25, 2019
1 parent f606c23 commit 4d7fefc
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,32 +417,35 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
buildOrUpdateControllers: function() {
var me = this;
var newControllers = [];
var datasets = me.data.datasets;
var i, ilen;

helpers.each(me.data.datasets, function(dataset, datasetIndex) {
var meta = me.getDatasetMeta(datasetIndex);
for (i = 0, ilen = datasets.length; i < ilen; i++) {
var dataset = datasets[i];
var meta = me.getDatasetMeta(i);
var type = dataset.type || me.config.type;

if (meta.type && meta.type !== type) {
me.destroyDatasetMeta(datasetIndex);
meta = me.getDatasetMeta(datasetIndex);
me.destroyDatasetMeta(i);
meta = me.getDatasetMeta(i);
}
meta.type = type;
meta.order = dataset.order || 0;
meta.index = datasetIndex;
meta.index = i;

if (meta.controller) {
meta.controller.updateIndex(datasetIndex);
meta.controller.updateIndex(i);
meta.controller.linkScales();
} else {
var ControllerClass = controllers[meta.type];
if (ControllerClass === undefined) {
throw new Error('"' + meta.type + '" is not a chart type.');
}

meta.controller = new ControllerClass(me, datasetIndex);
meta.controller = new ControllerClass(me, i);
newControllers.push(meta.controller);
}
}, me);
}

return newControllers;
},
Expand All @@ -468,6 +471,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {

update: function(config) {
var me = this;
var i, ilen;

if (!config || typeof config !== 'object') {
// backwards compatibility
Expand All @@ -494,9 +498,9 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
var newControllers = me.buildOrUpdateControllers();

// Make sure all dataset controllers have correct meta data counts
helpers.each(me.data.datasets, function(dataset, datasetIndex) {
me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
}, me);
for (i = 0, ilen = me.data.datasets.length; i < ilen; i++) {
me.getDatasetMeta(i).controller.buildOrUpdateElements();
}

me.updateLayout();

Expand Down

0 comments on commit 4d7fefc

Please sign in to comment.