When I select a group of nodes from the dropdown, I want the nearest nodes one degree away to also be highlighted. Currently, only the nodes in the group are highlighted.
I thought the highlightNearest with degree = 1 would help, but that only seems to affect when a single node is selected, not when a group is selected.
library(visNetwork)
nb <- 10
nodes <- data.frame(
id = 1:nb, label = paste("Label", 1:nb),
group = sample(LETTERS[1:3], nb, replace = TRUE), value = 1:nb,
title = paste0("<p>", 1:nb, "<br>Tooltip !</p>"), stringsAsFactors = FALSE
)
edges <- data.frame(
from = c(8, 2, 7, 6, 1, 8, 9, 4, 6, 2),
to = c(3, 7, 2, 7, 9, 1, 5, 3, 2, 9),
value = rnorm(nb, 10), label = paste("Edge", 1:nb),
title = paste0("<p>", 1:nb, "<br>Edge Tooltip !</p>")
)
visNetwork(nodes, edges, height = "500px", width = "100%") %>%
visOptions(
selectedBy = "group",
highlightNearest = TRUE,
nodesIdSelection = TRUE
) %>%
visLayout(randomSeed = 123)
When I select group A, I see nodes "Label 4", "Label 9", and "Lable 10" highlighted. The edges touching those nodes are also highlighted. Screenshot:
I want the nearest nodes to also be highlighted: "Label 1", "Label 2", "Label 5" and "Label 3" Screenshot with hand-drawn arrows pointed at the extra 4 nodes that should be highlighted:
If I click on nodes "Label 4" & "Label 9" directly, the nearest nodes are highlighted like I want them to be. I want this same highlighting behavior to also work when I select a group. Screenshots: