Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some colors ignored in sankeyNetwork(colourScale = ...) #242

Open
wlandau opened this issue Jul 13, 2018 · 3 comments
Open

Some colors ignored in sankeyNetwork(colourScale = ...) #242

wlandau opened this issue Jul 13, 2018 · 3 comments

Comments

@wlandau
Copy link

wlandau commented Jul 13, 2018

The following graph should have a green node, but it appears blue. Tested with both the CRAN release and 9c0a9c9.

nodes <- data.frame(
  id = letters[1:3],
  label = c("blue", "green", "black"),
  status = c("imported", "up to date", "outdated"),
  stringsAsFactors = FALSE 
)
edges <- data.frame(
  src = c(0, 0, 1),
  target = c(2, 1, 2),
  value = 1
)
color <- "d3.scaleOrdinal() .domain(['imported', 'up to date', 'outdated']) .range(['#1874CD', '#228B22', '#000000'])"
networkD3::sankeyNetwork(
  Links = edges,
  Nodes = nodes,
  NodeID = "label",
  Source = "src",
  Target = "target",
  NodeGroup = "status",
  Value = "value",
  colourScale = color,
  fontSize = 16
)

color

@cjyetman
Copy link
Collaborator

This happens because there is a space in "up to date". If you change the group value and the value in your color domain to ""up-to-date", it should work as expected.

pretty sure this is caused by this line: return color(d.group.replace(/ .*/, ""));

not sure if that line has some other important purpose

@wlandau
Copy link
Author

wlandau commented Jul 13, 2018

Thanks CJ, I would not have expected that. Removing spaces works. For my own application, this is an acceptable workaround.

nodes <- data.frame(
  id = letters[1:3],
  label = c("blue", "green", "black"),
  status = c("imported", "up-to-date", "outdated"),
  stringsAsFactors = FALSE 
)
edges <- data.frame(
  src = c(0, 0, 1),
  target = c(2, 1, 2),
  value = 1
)
color <- "d3.scaleOrdinal() .domain(['imported', 'up-to-date', 'outdated']) .range(['#1874CD', '#228B22', '#000000'])"
networkD3::sankeyNetwork(
  Links = edges,
  Nodes = nodes,
  NodeID = "label",
  Source = "src",
  Target = "target",
  NodeGroup = "status",
  Value = "value",
  colourScale = color,
  fontSize = 16
)

color2

@cjyetman
Copy link
Collaborator

We should at least at a note to the documentation that group values must not have a space. Allowing for spaces in the group name would break backwards compatibility, so I'm not sure we should do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants