datastorm-open / visNetwork

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

Highlight Edges with Color Column #462

Open ramadatta opened 1 year ago

ramadatta commented 1 year ago

Hi,

In the following code, when you have color column in the edges dataframe, the options hover and highlight does not seems work. Is there anyway to highlight the edges when you have color column in edges do this?

nodes <- data.frame(id = 1:15, label = paste("Label", 1:15),
                    group = sample(LETTERS[1:3], 15, replace = TRUE))

edges <- data.frame(id = 1:15, from = trunc(runif(15)*(15-1))+1,
                    to = trunc(runif(15)*(15-1))+1)

#edges$color <- rainbow(15)

visNetwork(nodes, edges) %>% 
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visEdges(color = list(color = "blue",highlight ="red",hover = "red")) %>% #Hover and Highlight parameters work!
  visInteraction(hover = T)

edges$color <- rainbow(15)

visNetwork(nodes, edges) %>% 
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visEdges(color = list(highlight ="red",hover = "red")) %>% #Hover and Highlight parameters does not work!
  visInteraction(hover = T)

Many thanks in advance!

BioLaoXu commented 2 months ago

This solution can also work:

nodes <- data.frame(id = 1:15, label = paste("Label", 1:15),
                    group = sample(LETTERS[1:3], 15, replace = TRUE))

edges <- data.frame(id = 1:15, from = trunc(runif(15)*(15-1))+1,
                    to = trunc(runif(15)*(15-1))+1)

net <- igraph::graph_from_data_frame(d=edges,vertices=nodes,directed = F)
visNetwork::visIgraph(net,layout = "layout_in_circle",type = "full") %>%
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visEdges(color = list(highlight ="red",hover = "red")) %>% 
  visInteraction(hover = T)