visNetwork icon indicating copy to clipboard operation
visNetwork copied to clipboard

Upon selecting a node, only highlight paths with a specific type of edge

Open StarScream2010 opened this issue 5 years ago • 0 comments

I'm using visNetwork in R to generate a hierarchal network map. I want the paths of which get highlighted upon node selection to only follow a specific type of edge (eg, solid edges and dashed edges). Please follow my example below.


library(tidyverse)
library(visNetwork)

nodes = data.frame(id = 1:7, level = c(1, 2, 3, 3, 4, 2,1))
edges = data.frame(from = c(1, 2, 2, 4, 6,7,7), to = c(2, 3, 4, 5, 4,6,2),
                   dashes = c(FALSE, TRUE, FALSE,FALSE,FALSE,FALSE,TRUE))

visNetwork(nodes, edges) %>% 
  visHierarchicalLayout() %>% 
  visEdges(arrows = "to") %>% 
  visOptions(highlightNearest = list(enabled = TRUE, algorithm = "hierarchical",
                                     degree = n_distinct(nodes$level))) %>%
  visHierarchicalLayout(direction = "DU")

This code produces the below network map

                                   

However, when I select nodes 1 or 7 the path highlighting includes the dashed nodes.For example, see below.

I want the highlighting to exclude the nodes linked via dashed edges . For example, in the left picture above, node 3 would not be highlighted and in the right picture above, nodes 2 and 3 would not be highlighted.

Is there any way to achieve this or something similar?

Thanks

StarScream2010 avatar Apr 03 '20 14:04 StarScream2010