Skip to content

Commit

Permalink
Cache sorting order of dataset metas
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Nov 16, 2019
1 parent 4b4b4b7 commit bbed0ee
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
var me = this;
var newControllers = [];
var datasets = me.data.datasets;
var sorted = me._sortedMetasets = [];
var i, ilen;

for (i = 0, ilen = datasets.length; i < ilen; i++) {
Expand Down Expand Up @@ -446,8 +447,11 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
meta.controller = new ControllerClass(me, i);
newControllers.push(meta.controller);
}
sorted.push(meta);
}

sorted.sort(compare2Level('order', 'index'));

return newControllers;
},

Expand Down Expand Up @@ -727,18 +731,16 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
*/
_getSortedDatasetMetas: function(filterVisible) {
var me = this;
var datasets = me.data.datasets || [];
var metasets = me._sortedMetasets;
var result = [];
var i, ilen;

for (i = 0, ilen = datasets.length; i < ilen; ++i) {
for (i = 0, ilen = metasets.length; i < ilen; ++i) {
if (!filterVisible || me.isDatasetVisible(i)) {
result.push(me.getDatasetMeta(i));
result.push(metasets[i]);
}
}

result.sort(compare2Level('order', 'index'));

return result;
},

Expand Down

0 comments on commit bbed0ee

Please sign in to comment.