coolbutuseless / minisvg

Create SVG documents with R
https://coolbutuseless.github.io/package/minisvg/
MIT License
31 stars 3 forks source link

Translating colors from R to SVG #3

Closed dmi3kno closed 4 years ago

dmi3kno commented 4 years ago

It seems like the package is translating colors from R to SVG literally. It works for most colors, but not all. This for example returns black square

library(minisvg)

doc <- svg_doc(width = 100, height = 100)
doc$append(stag$rect(x = 0, y=0, width=70, height=70, fill='violetred'))
doc$show()

While it should be

rgb(t(col2rgb("violetred")), maxColorValue = 255)
#>  "#D02090"

I think round-tripping the color names like that can help fix those corner cases where colors do not get properly matched.

coolbutuseless commented 4 years ago

Fixed in 5725818fd

If the user specifies a colour which is an R colour, but not a CSS colour, then it will be converted to a hexcolour.