mjs_add_css_rule: Add a CSS rule to the rendered htmlwidget

Description Usage Arguments Details Value Note Examples

View source: R/rules.r

Description

This function will add a CSS rule to a widget-created DOM stylesheet. rule should be a valid CSS rule as you would enter in a <style>...</style> block. No checking is done to ensure validity.

Usage

1
mjs_add_css_rule(mjs, rule, warn = TRUE)

Arguments

mjs

metricsgraphics plot object

rule

character vector of CSS rule(s) to add to the widget DOM

warn

show warnings for global CSS rules? (default: TRUE)

Details

Use {{ID}} (followed by a space) to target the CSS rule just to the widget vs the whole DOM.

Vectorized over rule

Value

metricsgraphics plot object

Note

This is for expert use only. You need to know quite a bit about the visualization and target DOM to effectively use this function. CSS rules without the {{ID}} are applied to the entire DOM.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(1492)
stocks <- data.frame(
  time = as.Date('2009-01-01') + (365 * 0:9),
  X = rnorm(10, 0, 1),
  Y = rnorm(10, 0, 2),
  Z = rnorm(10, 0, 4))

stocks %>%
  mjs_plot(x=time, y=X) %>%
  mjs_line() %>%
  mjs_axis_x(xax_format="date") %>%
  mjs_add_css_rule("{{ID}} .blk { fill:black }") %>%
  mjs_annotate_region("2013-01-01", "2016-01-01", "Crazy times", "blk")

hrbrmstr/metricsgraphics documentation built on May 17, 2019, 5:10 p.m.