From bbed0ee750e90db0fbd0b8763a80bb309a9c4469 Mon Sep 17 00:00:00 2001 From: kurkle Date: Sun, 17 Nov 2019 01:23:16 +0200 Subject: [PATCH] Cache sorting order of dataset metas --- src/core/core.controller.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index a1325394a51..bb0c0cf189f 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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++) { @@ -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; }, @@ -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; },