datastorm-open / visNetwork

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

Changing legend node label color? #420

Open mercicle opened 3 years ago

mercicle commented 3 years ago

I've looked a while and can't seem to find a way to change the legend node label color, so e.g. if a node is black then change the text color white so it can be read:

addNodes = list( list(label = "A", shape = "circle",color="black", size=2,color.text='white'), list(label = "B", shape = "circle", color="red", size=2,color.text='white')), useGroups = FALSE,

bthieurmel commented 3 years ago

For label color, you have to use font and color. And dot notation like font.color is only for data.frame, not on list.

Two example with both notation :

nodes <- data.frame(id = 1:3, group = c("B", "A", "B"))
edges <- data.frame(from = c(1,2), to = c(2,3))

# using a data.frame

visNetwork(nodes, edges) %>%
  visGroups(groupname = "A", shape = "icon", icon = list(code = "f0c0", size = 75)) %>%
  visGroups(groupname = "B", shape = "icon", icon = list(code = "f007", color = "red")) %>%
  addFontAwesome() %>%
  visLegend(addNodes = list(
    list(label = "A", shape = "circle", color = "black",
         font = list(color = "white"), 
         size = 2)), useGroups = FALSE) 

visNetwork(nodes, edges) %>%
  visGroups(groupname = "A", shape = "icon", icon = list(code = "f0c0", size = 75)) %>%
  visGroups(groupname = "B", shape = "icon", icon = list(code = "f007", color = "red")) %>%
  addFontAwesome() %>%
  visLegend(addNodes = data.frame(label = "A", shape = "circle", size = 2,
                                  color = "black", font.color = "white"), 
         useGroups = FALSE) 
altayg commented 2 years ago

How would you just show a circle color around a node in the legend?