Skip to content

Commit

Permalink
fix error on clearing crosstalk selection
Browse files Browse the repository at this point in the history
  • Loading branch information
casperhart committed Apr 24, 2022
1 parent 01582b8 commit cd63424
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* `ggplotly()` now respects `guide(aes = "none")` (e.g., `guide(fill = "none")`) when constructing legend entries. (#2067)
* Fixed an issue with translating `GGally::ggcorr()` via `ggplotly()`. (#2012)
* Fixed an issue where clearing a crosstalk filter would raise an error in the JS console (#2087)
* Fixed an issue with `{crosstalk}` where running `selectionHandle.clear()` from another visual causes plotly to throw an error. (#2098)


## Improvements

Expand Down
8 changes: 4 additions & 4 deletions inst/htmlwidgets/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,15 @@ TraceManager.prototype.updateFilter = function(group, keys) {
};

TraceManager.prototype.updateSelection = function(group, keys) {
if (keys !== null && !Array.isArray(keys)) {

if (keys !== null && keys !== undefined && !Array.isArray(keys)) {
throw new Error("Invalid keys argument; null or array expected");
}

// if selection has been cleared, or if this is transient
// selection, delete the "selection traces"
var nNewTraces = this.gd.data.length - this.origData.length;
if (keys === null || !this.highlight.persistent && nNewTraces > 0) {
if (keys === null || keys === undefined || !this.highlight.persistent && nNewTraces > 0) {
var tracesToRemove = [];
for (var i = 0; i < this.gd.data.length; i++) {
if (this.gd.data[i]._isCrosstalkTrace) tracesToRemove.push(i);
Expand All @@ -655,7 +655,7 @@ TraceManager.prototype.updateSelection = function(group, keys) {
}
}

if (keys === null) {
if (keys === null || keys === undefined) {

Plotly.restyle(this.gd, {"opacity": this.origOpacity});

Expand Down

0 comments on commit cd63424

Please sign in to comment.