Skip to content

Commit 9907691

Browse files
committed
make trace match logic in updateFilter more like updateSelection
1 parent dc425aa commit 9907691

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

inst/htmlwidgets/plotly.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ TraceManager.prototype.updateFilter = function(group, keys) {
488488

489489
} else {
490490

491+
var traces = [];
491492
for (var i = 0; i < this.origData.length; i++) {
492493
var trace = this.origData[i];
493494
if (!trace.key || trace.set !== group) {
@@ -496,18 +497,17 @@ TraceManager.prototype.updateFilter = function(group, keys) {
496497
var matchFunc = getMatchFunc(trace);
497498
var matches = matchFunc(trace.key, keys);
498499

499-
if (matches.length == 0) {
500-
this.gd.data[i] = undefined;
501-
}
502-
if (!trace._isSimpleKey) {
503-
// subsetArrayAttrs doesn't mutate trace (it makes a modified clone)
504-
this.gd.data[i] = subsetArrayAttrs(trace, matches);
500+
if (matches.length > 0) {
501+
if (!trace._isSimpleKey) {
502+
// subsetArrayAttrs doesn't mutate trace (it makes a modified clone)
503+
trace = subsetArrayAttrs(trace, matches);
504+
}
505+
traces.push(trace);
505506
}
506507
}
507-
508508
}
509509

510-
this.gd.data = this.gd.data.filter(function(tr) { return tr !== undefined; });
510+
this.gd.data = traces;
511511
Plotly.redraw(this.gd);
512512

513513
// NOTE: we purposely do _not_ restore selection(s), since on filter,

0 commit comments

Comments
 (0)