USGS-VIZLAB / vizlab

Package with utilities for building vizlab pages
Creative Commons Zero v1.0 Universal
25 stars 14 forks source link

robust way to grab style info from css into R #196

Open aappling-usgs opened 7 years ago

aappling-usgs commented 7 years ago

Would be nice to be able to share information between CSS and R plots. One way to do this is to read the CSS into R plotting functions, then use the style info there. Saves us the (arduous?) step of creating a third location for that shared info, especially because we want to be able to experiment quickly with CSS changes.

This feature was proposed by @lindsaycarr during Irma viz. @jread-usgs responded, "the interns created a really amazing way to do that :point_up: which we couldn't get dialed up for this in time, but might be a priority for later"

lindsayplatt commented 7 years ago

Created two not robust functions that do this: locate_css_class and locate_css_class_detail

https://github.com/USGS-VIZLAB/hurricane-irma/blob/master/scripts/visualize/visualize_utils.R#L195-L215

Example use:

css <- readLines("example.css")
state_css <- locate_css_class(css, ".county-polygon")
state_color <- locate_css_class_detail(state_css, "fill")
state_color
[1] "#d1d6d8"