Skip to content

Commit

Permalink
Cache dataset visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Nov 17, 2019
1 parent bbed0ee commit a8b976e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
meta.order = dataset.order || 0;
meta.index = i;
meta.label = '' + dataset.label;
meta.visible = me.isDatasetVisible(i);

if (meta.controller) {
meta.controller.updateIndex(i);
Expand Down Expand Up @@ -707,13 +708,15 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
* @private
*/
transition: function(easingValue) {
var me = this;
const me = this;
var i, ilen;

if (!me._animationsDisabled) {
for (i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
if (me.isDatasetVisible(i)) {
me.getDatasetMeta(i).controller.transition(easingValue);
const metas = me._getSortedDatasetMetas();
for (i = 0, ilen = metas.length; i < ilen; ++i) {
let meta = metas[i];
if (meta.visible) {
meta.controller.transition(easingValue);
}
}
}
Expand All @@ -736,8 +739,9 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
var i, ilen;

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

Expand Down Expand Up @@ -884,13 +888,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
},

getVisibleDatasetCount: function() {
var count = 0;
for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
if (this.isDatasetVisible(i)) {
count++;
}
}
return count;
return this._getSortedVisibleDatasetMetas().length;
},

isDatasetVisible: function(datasetIndex) {
Expand Down

0 comments on commit a8b976e

Please sign in to comment.