datastorm-open / visNetwork

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

Color problems in nodes #473

Open TimothyEbert opened 3 months ago

TimothyEbert commented 3 months ago

I am using RStudio running on a PC (DELL Latitude 7440) using R 4.4.1 and RStudio version 2024.4.2.764. I am making network plots with 6 nodes. I assign custom colors to the nodes and edges.

The problem is that some colors appear to cause problems where some edges and nodes to not appear with the right color. I check the edges data frame, and the colors are correct but an edge with one color in the data frame will print as a different color. This graph is good: image If I change to "brown4" then I get this: image

Is there a pallet that does not have problems, or what is causing this issue?

TimothyEbert commented 3 months ago

The following is a minimally reproducible example where I have removed all of the code that converts the raw data into node and edges. I have also left out code that adjusts the physics.

library(visNetwork)

Build nodes

nodes <- data.frame( id=c("C", "G", "NP", "D", "E1", "E2"), label=c("C", "G", "NP", "D", "E1", "E2"), size = c(45.095856, 37.859089, 116.437705, 1.546333, 1.373999, 23.07729), color.background = c("cyan", "blue", "brown4", "lightgreen", "lightgreen", "lightgreen") )

Build edges

edges <- data.frame( to = c('C', 'C', 'C', 'D', 'D', 'E1', 'E1', 'E2', 'E2', 'G', 'G', 'NP'), from = c('D', 'G', 'NP', 'C', 'E1', 'C', 'E2', 'C', 'E1', 'C', 'NP', 'C'), width = c(5.135724, 5.629823, 13.597379, 12.25, 12.4, 15.97265, 6.712251, 10, 13.333333, 19.62963, 6.666667, 20), arrows = "to", font_multi = "html", color = c('lightgreen', 'blue', 'brown4', 'cyan', 'lightgreen', 'cyan', 'lightgreen', 'cyan', 'lightgreen', 'cyan', 'brown4', 'cyan') ) visNetwork(nodes, edges)

Code where color works

Build nodes

nodes <- data.frame( id=c("C", "G", "NP", "D", "E1", "E2"), label=c("C", "G", "NP", "D", "E1", "E2"), size = c(45.095856, 37.859089, 116.437705, 1.546333, 1.373999, 23.07729), color.background = c("cyan", "blue", "brown", "lightgreen", "lightgreen", "lightgreen") )

Build edges

edges <- data.frame( to = c('C', 'C', 'C', 'D', 'D', 'E1', 'E1', 'E2', 'E2', 'G', 'G', 'NP'), from = c('D', 'G', 'NP', 'C', 'E1', 'C', 'E2', 'C', 'E1', 'C', 'NP', 'C'), width = c(5.135724, 5.629823, 13.597379, 12.25, 12.4, 15.97265, 6.712251, 10, 13.333333, 19.62963, 6.666667, 20), arrows = "to", font_multi = "html", color = c('lightgreen', 'blue', 'brown', 'cyan', 'lightgreen', 'cyan', 'lightgreen', 'cyan', 'lightgreen', 'cyan', 'brown', 'cyan') ) visNetwork(nodes, edges)

philibe commented 1 week ago

In simple html brown4 gives /!\Invalid Property Value in F12/debug of a browser.

They works:

Their color doesn't work:

brown4 doesn't seem exist in in https://www.w3.org/wiki/CSS/Properties/color/keywords