christophergandrud / networkD3

D3 JavaScript Network Graphs from R
http://christophergandrud.github.io/networkD3
650 stars 269 forks source link

Sankey tooltip: if link value passed as string, don't round tooltip to integer #217

Closed octaviancorlade closed 6 years ago

octaviancorlade commented 6 years ago

Fixes #147, numeric values are currently rounded to integer in the tooltips.

A way to fix trying not to completely break backwards compatibility is to check whether the provided values are strings and in that case avoid formatting them.

Simple example:

library(networkD3)
links <- data.frame(source=c(0, 0), target=c(1, 2), value=c(0.5, 0.95))
nodes <- data.frame(names = c("first", "second", "third"))
sankeyNetwork(Links = links, Nodes = nodes, 
              Source = 'source', Target = 'target', Value = 'value')
screen shot 2017-09-28 at 16 16 22
links$value <- as.character(links$value)
sankeyNetwork(Links = links, Nodes = nodes,
              Source = 'source', Target = 'target', Value = 'value')
screen shot 2017-09-28 at 16 16 36