datastorm-open / visNetwork

R package, using vis.js library for network visualization
Other
542 stars 127 forks source link

`selectedBy` selection is reset by `highlightNearest` hover #439

Open stragu opened 2 years ago

stragu commented 2 years ago

I am not sure if this is a bug or a feature request, but I am wondering if this behaviour should be different:

When a selectBy value is selected in the dropdown, and highlightNearest is enabled with the hover = TRUE option, hovering over a node will "cancel" or "deselect" the selection.

It would be great to have the selection be more persistent as a default (as in: select, then hover to highlight nearest of any node, then move pointer again to go back to original selection), or maybe have the option to choose how the two settings interact? And for consistency, this probably should affect the highlighting by hovering as well as by clicking in the same way. (In other words: if selectBy is set to "persistent", highlighting a node and its neighbours by clicking+click out OR hovering does not reset the dropdown selection.)

I am reporting this also because I've seen more inconsistent behaviour in a more complex visualisation (the select + hover worked as I wanted the first time, and then wouldn't after that), but I am having a hard time reproducing it with a minimal example...)

Steps to reproduce:

  1. Run this code:
library(visNetwork)
nodes <- data.frame(id = 1:3,
                    group = c("a", "a", "b"))
edges <- data.frame(from = 1:3,
                     to = c(2, 1, 1))
visNetwork(nodes, edges) |>
  visOptions(highlightNearest = list(enabled = TRUE, degree = 1, hover = TRUE),
             selectedBy = list(variable = "group"))
  1. Select a group in the dropdown
  2. Hover over a node and off the node again
  3. The selection is lost
  4. Try with clicking a node and clicking outside the node too: same result.

In any case, thank you so much for this fabulous package! :+1: