I have a scatterplot in which points are densely clustered. After zooming in on some of them, double-clicking on empty space resets the axes, which is what I want. But in many cases, it also selects a new point -- which isn't what I want. After all, I double-clicked on empty space. I had no intention of selecting a new point.
The problem seems to be twofold. First, each double click is also registered as a single click. Second, the single click is registered at the post-axis-reset coordinates -- not the coordinates that I actually see when I double-click. And the post-axis-reset coordinates map to a plotted point, even though I am clicking on empty space when I am zoomed in. How can I fix the problem?
Here is a minimal illustration. The Plotly figure is generated from R, but that doesn't seem important:
library(plotly)
x <- c(rnorm(3000, 0, 3), rnorm(1000, 0, 0.2))
y <- c(rnorm(3000, 0, 3), rnorm(1000, 0, 0.2))
groups <- rep(c("a", "b", "c", "d"), 1000)
myData <- highlight_key( data.frame(x, y, groups), ~groups )
myPlot <- plot_ly(
x = ~x, y = ~y,
color = ~groups,
data = myData)
highlight(myPlot, color = "red")
This animated GIF shows the figure that the code creates, and it also illustrates the problem.
The problem has been noted before. But I can't seem to solve it by pre-empting the default click-to-select functionality when double-clicking, or by using any other strategy. A few things that I've tried:
After a
plotly_doubleclickevent is triggered, alter the stored JSON data so that x > highlight > on is null. Then redraw withPlotly.newPlot().After a
plotly_doubleclickevent is triggered, useremove.listener()to disableplotly_clickevents. But by the time thatplotly_doubleclickis triggered, it seems to be too late for this strategy to work: the single-click (plotly_click) event has already been triggered.Change layout > ordering from "traces first" to "layout first"
Telling the
plotly_clickevent handler toreturn falsewhen a double-click is detected. (I used this method to make theplotly_clickevent handler detect whether the click that activated it was part of a double click.) This strategy may work for clicking on legends, but it doesn't seem to work for clicking on the plot itself.
None of this worked. But I think that there must be a solution -- is there?