Skip to content

Commit

Permalink
CSS warning
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Aug 12, 2015
1 parent ad2161e commit 81b6b07
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: taucharts
Title: Create Interactive Charts with the JavaScript 'TauCharts' Library
Version: 0.3.3.9001
Version: 0.3.4.9000
Authors@R: c(
person("Bob", "Rudis", email = "[email protected]", role = c("aut", "cre")),
person("Kent", "Russell", email = "[email protected]", role = c("aut", "ctb")),
Expand Down
17 changes: 15 additions & 2 deletions R/rules.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#'
#' @param tau taucharts object
#' @param rule character vector of CSS rule(s) to add to the widget DOM
#' @param warn show warnings for global CSS rules? (default: \code{TRUE})
#' @return taucharts htmlwidget 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.
#' and target DOM to effectively use this function. CSS rules without the \code{\{\{ID\}\}}
#' are applied to the entire DOM.
#' @export
#' @examples
#' # change the default white tooltip to black
Expand All @@ -33,7 +35,18 @@
#' tau_color_manual(c("blue", "maroon", "black")) %>%
#' tau_tooltip() %>%
#' make_black_tooltip()
tau_add_css_rule <- function(tau, rule) {
tau_add_css_rule <- function(tau, rule, warn=TRUE) {

# if any of the CSS statements in 'rule' do not have {{ID}} targets, warn the user
if (warn) {
if (!any(grepl("\\{\\{ID\\}\\}", rule))) {
# special case for the tooltip since that resides outsie the widget div
# it has to be targeted globally unless the TauCharts folks change the behavior
if (!all(grepl("graphical-report__tooltip", rule[which(!grepl("\\{\\{ID\\}\\}", rule))]))) {
message("NOTE: CSS rules without {{ID}} are applied to the entire DOM.")
}
}
}
tau$x$forCSS <- c(tau$x$forCSS, rule)
tau
}
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The following datasets are included:

### News

- Version 0.3.4.9000 released : added warning for global targeted CSS rules and font ref fix thx to @jlewis91
- Version 0.3.3.9001 released : fix for custom colors and `tau_line`
- Version 0.3.3 released : custom font for chart (`?tau_set_font`)
- Version 0.3.2 released : custom colors working in legend & trendlines
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The following datasets are included:

### News

- Version 0.3.4.9000 released : added warning for global targeted CSS rules and font ref fix thx to @jlewis91
- Version 0.3.3.9001 released : fix for custom colors and `tau_line`
- Version 0.3.3 released : custom font for chart (`?tau_set_font`)
- Version 0.3.2 released : custom colors working in legend & trendlines
Expand Down Expand Up @@ -77,7 +78,7 @@ library(taucharts)

# current verison
packageVersion("taucharts")
#> [1] '0.3.3'
#> [1] '0.3.4.9000'
```

### Test Results
Expand All @@ -87,7 +88,7 @@ library(taucharts)
library(testthat)

date()
#> [1] "Mon Aug 10 20:17:36 2015"
#> [1] "Wed Aug 12 16:37:18 2015"

test_dir("tests/")
#> testthat results ========================================================================================================
Expand Down
7 changes: 5 additions & 2 deletions man/tau_add_css_rule.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
\alias{tau_add_css_rule}
\title{Add a CSS rule to the rendered htmlwidget}
\usage{
tau_add_css_rule(tau, rule)
tau_add_css_rule(tau, rule, warn = TRUE)
}
\arguments{
\item{tau}{taucharts object}

\item{rule}{character vector of CSS rule(s) to add to the widget DOM}

\item{warn}{show warnings for global CSS rules? (default: \code{TRUE})}
}
\value{
taucharts htmlwidget object
Expand All @@ -28,7 +30,8 @@ Vectorized over \code{rule}
}
\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.
and target DOM to effectively use this function. CSS rules without the \code{\{\{ID\}\}}
are applied to the entire DOM.
}
\examples{
# change the default white tooltip to black
Expand Down
2 changes: 1 addition & 1 deletion man/tau_set_font.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\usage{
tau_set_font(tau,
family = "OpenSans, 'Helvetica Neue', Helvetica, Arial, sans-serif",
import_url = "http://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,700,600italic,700italic,800,300,300italic,800italic")
import_url = "https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,700,600italic,700italic,800,300,300italic,800italic")
}
\arguments{
\item{family}{CSS \code{font-family} spec (just the comma-separated font names)}
Expand Down

0 comments on commit 81b6b07

Please sign in to comment.