Skip to content

Commit 537ecb1

Browse files
committed
Hide selection box when another plot makes a selection
1 parent 3e0b4fc commit 537ecb1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

inst/htmlwidgets/plotly.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ HTMLWidgets.widget({
157157
graphDiv.on("plotly_selected", function plotly_selecting(e) {
158158
if (e) {
159159
var selectedKeys = pointsToKeys(e.points);
160-
grp.var("selection").set(selectedKeys);
160+
grp.var("selection").set(selectedKeys, {sender: el});
161161
}
162162
});
163163
// When plotly selection is cleared, update crosstalk
@@ -169,6 +169,17 @@ HTMLWidgets.widget({
169169
grp.var("selection").on("change", function crosstalk_sel_change(e) {
170170
// e.value is either null, or an array of newly selected values
171171

172+
if (e.sender !== el) {
173+
// If we're not the originator of this selection, and we have an
174+
// active selection outline box, we need to remove it. Otherwise
175+
// it could appear like there are two active brushes in one plot
176+
// group.
177+
var outlines = el.querySelectorAll(".select-outline");
178+
for (var i = 0; i < outlines.length; i++) {
179+
outlines[i].remove();
180+
}
181+
}
182+
172183
// Restyle each relevant trace
173184
var selectedPoints = keysToPoints(e.value || []);
174185

0 commit comments

Comments
 (0)