wch / webshot

Take screenshots of web pages from R
http://wch.github.io/webshot/
227 stars 40 forks source link

Colors and transparency wrong in PNG #87

Closed sneumann closed 5 years ago

sneumann commented 5 years ago

Hi, I have a graph with visNetwork that looks great as HTML in Browser, but very poor as PNG after webshot, colors and transparency are gone, see pictures at the end. The code is

library(visNetwork)
library(webshot)

nodes <- data.frame(id = 1:3, 
                    color.background = c(rgb(200, 0, 0, 128, max = 255),
                                         rgb(0, 200, 0, 128, max = 255), 
                                         rgb(0, 0, 200, 128, max = 255)))
edges <- data.frame(from = c(1,2), to = c(1,3))

vn <- visNetwork(nodes = nodes, 
                 edges = edges) %>% 
  visOptions(highlightNearest = TRUE)

show(vn)

saveNetwork(vn, "vn.html")
webshot("vn.html", "vn.png")

This is particularly annoying as in more crowded networks the text labels are underneath the nodes, and not readable without transparency. The colors work nicely if there is no transparency: rgb(0, 200, 0, max = 255).

1) How to get color + transparency into webshot PNGs ? 2) How to get the labels atop of the nodes in case of overlap ?

Thanks in advance, yours, Steffen

Screenshot from 2019-08-06 15-02-22 Screenshot from 2019-08-06 15-01-39

sneumann commented 5 years ago

Confirmed with phantomjs .../github/webshot/inst/webshot.js '[{"url":"file:///.../vn.html","file":"vn-phantomjs.png"}]' Also no difference between node attributes color and the color.background used above.

wch commented 5 years ago

@sneumann Can you try out https://github.com/rstudio/webshot2 and see if it works for you?

sneumann commented 5 years ago

Thanks Winston, that worked. Yours, Steffen