Bläddra i källkod

fix whitespace

tags/v0.4.1
Garrick Aden-Buie 4 år sedan
förälder
incheckning
66852c14e0
Ingen känd nyckel hittad för denna signaturen i databasen
8 ändrade filer med 33 tillägg och 38 borttagningar
  1. +0
    -3
      R/color.R
  2. +6
    -8
      R/ggplot2.R
  3. +1
    -1
      R/style_extra_css.R
  4. +15
    -15
      R/style_xaringan.R
  5. +2
    -2
      R/utils_theme-gen.R
  6. +6
    -6
      R/xaringanthemer-package.R
  7. +1
    -1
      tests/testthat/test-color.R
  8. +2
    -2
      tests/testthat/test-themes.R

+ 0
- 3
R/color.R Visa fil

@@ -12,7 +12,6 @@
#' if (requireNamespace("scales", quietly = TRUE)) {
#' scales::show_col(c(blue_light, blue, blue_dark))
#' }
#'
#' @return A character string with the lightened or darkened color in
#' hexadecimal format.
#' @name lighten_darken_color
@@ -49,7 +48,6 @@ darken_color <- function(color_hex, strength = 0.8) {
#' if (requireNamespace("scales", quietly = TRUE)) {
#' scales::show_col(c(blue, blue_transparent))
#' }
#'
#' @return A character string with added opacity level as hexadecimal characters.
#' @export
apply_alpha <- function(color_hex, opacity = 0.5) {
@@ -83,7 +81,6 @@ adjust_value_color <- function(color_hex, strength = 0.5) {
#' if (requireNamespace("scales", quietly = TRUE)) {
#' scales::show_col(c(light_green, contrast_green, dark_purple, contrast_purple))
#' }
#'
#' @return The `black` color or `white` color according to which color provides
#' the greates contrast with the input color.
#'

+ 6
- 8
R/ggplot2.R Visa fil

@@ -422,8 +422,8 @@ theme_xaringan_set_defaults <- function(
"boxplot" = list(color = text_color),
"contour" = list(color = text_color),
"density" = list(color = text_color,
fill = text_color,
alpha = 0.1),
fill = text_color,
alpha = 0.1),
"dotplot" = list(color = accent_color),
"errorbarh" = list(color = text_color),
"crossbar" = list(color = text_color),
@@ -436,17 +436,17 @@ theme_xaringan_set_defaults <- function(
"step" = list(color = text_color),
"point" = list(color = accent_color),
"polygon" = list(color = accent_color,
fill = accent_color),
fill = accent_color),
"quantile" = list(color = text_color),
"rug" = list(color = blend(0.5)),
"segment" = list(color = text_color),
"smooth" = list(fill = blend(0.75),
color = accent_secondary_color),
color = accent_secondary_color),
"spoke" = list(color = text_color),
"label" = list(color = text_color,
family= text_font %||% get_theme_font("text")),
family= text_font %||% get_theme_font("text")),
"text" = list(color = text_color,
family= text_font %||% get_theme_font("text")),
family= text_font %||% get_theme_font("text")),
"rect" = list(fill = text_color),
"tile" = list(fill = text_color),
"violin" = list(fill = text_color),
@@ -587,7 +587,6 @@ safely_set_geom <- function(geom, new) {
#' # Fill color matches teal text
#' scale_xaringan_color_discrete(direction = -1)
#' }
#'
#' @name scale_xaringan
NULL

@@ -1022,7 +1021,6 @@ requires_xaringanthemer_env <- function(
#' theme_xaringan_get_value("background_color")
#' theme_xaringan_get_value("header_color")
#' theme_xaringan_get_value("text_bold_color")
#'
#' @return The value of the xaringanthemer style parameter.
#' @export
theme_xaringan_get_value <- function(setting, css_file = NULL) {

+ 1
- 1
R/style_extra_css.R Visa fil

@@ -119,7 +119,7 @@ list2css <- function(css) {
list2fonts <- function(fonts) {
if (
length(setdiff(names(google_font('fam')), names(fonts))) == 0 &&
!inherits(fonts, "google_font")
!inherits(fonts, "google_font")
) {
# concatenating a string and a google_font() provides a wacky list
stop(

+ 15
- 15
R/style_xaringan.R Visa fil

@@ -344,7 +344,7 @@ style_xaringan <- function(
force(code_font_family)
force(code_font_url)
force(code_font_family_fallback)
# the defaults are google fonts
is_default <- function(type, suffix) {
# check if font arg value is from xaringanthemer_font_default
@@ -362,7 +362,7 @@ style_xaringan <- function(
r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}")
eval(parse(text = r_set_font_is_google))
}
# Make sure font names are wrapped in quotes if they have spaces
f_args <- names(formals(sys.function()))
for (var in f_args[grepl("font_family$", f_args)]) {
@@ -371,7 +371,7 @@ style_xaringan <- function(
eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")")))
}
}
# Warn if base_font_size isn't absolute
css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px")
if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) {
@@ -385,7 +385,7 @@ style_xaringan <- function(
immediate. = TRUE
)
}
# If certain colors aren't in hexadecimal it may cause problems with theme_xaringan()
# TODO: at some point I'd rather be able to process CSS colors or variables
colors_used_by_theme_xaringan <- list(
@@ -399,18 +399,18 @@ style_xaringan <- function(
)
colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null)
colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL)
if (any(!colors_are_hex)) {
colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex]
colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ")
warning(
glue::glue("Colors that will be used by `theme_xaringan()` need to be in ",
"hexadecimal format: {colors_better_as_hex}"),
"hexadecimal format: {colors_better_as_hex}"),
immediate. = TRUE,
call. = FALSE
)
}
# Use font_..._google args to overwrite font args
for (var in f_args[grepl("font_google$", f_args)]) {
gf <- eval(parse(text = var))
@@ -433,10 +433,10 @@ style_xaringan <- function(
}
eval(parse(text = paste0(group, "_font_is_google <- 1")))
}
extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts)
extra_font_imports <- paste(extra_font_imports, collapse = "\n")
# convert NA arguments to NULL
for (var in f_args) {
val <- eval(parse(text = var))
@@ -445,7 +445,7 @@ style_xaringan <- function(
is_na <- length(val) == 0
if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe()))
}
# prepare variables for template
body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ")
background_size_fallback <- if (is.null(background_position)) "cover" else "100%"
@@ -454,7 +454,7 @@ style_xaringan <- function(
title_slide_background_image %??% "cover"
)
table_row_even_background_color <- table_row_even_background_color %||% background_color
# stash theme settings in package env
lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env))
for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) {
@@ -464,9 +464,9 @@ style_xaringan <- function(
envir = xaringanthemer_env
)
}
xaringanthemer_version <- utils::packageVersion("xaringanthemer")
# prepare header background object
needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes)
header_background_ignore_classes[needs_leading_dot] <- paste0(
@@ -491,9 +491,9 @@ style_xaringan <- function(
content_padding_top = header_background_content_padding_top,
ignore = header_background_ignore_classes
)
colors <- prepare_colors(colors)
tf <- system.file("resources", "template.css", package = "xaringanthemer")
template <- readLines(tf, warn = FALSE)
template <- paste(template, collapse = "\n")

+ 2
- 2
R/utils_theme-gen.R Visa fil

@@ -5,8 +5,8 @@ plural_element <- function(css_name) {
is_mult <- grepl(",|and|or", css_name)
is_class <- grepl("^\\.", css_name)
ifelse(is_class,
ifelse(is_mult, "classes", "class"),
ifelse(is_mult, "elements", "element")
ifelse(is_mult, "classes", "class"),
ifelse(is_mult, "elements", "element")
)
}


+ 6
- 6
R/xaringanthemer-package.R Visa fil

@@ -17,8 +17,8 @@ xaringanthemer_env$std_ggplot_defaults <- list(
"boxplot" = list(color = "grey20", fill = "white"),
"contour" = list(color = "#3366FF"),
"density" = list(color = "black",
fill = NA,
alpha = NA),
fill = NA,
alpha = NA),
"dotplot" = list(color = "black"),
"errorbarh" = list(color = "black"),
"crossbar" = list(color = "black"),
@@ -31,17 +31,17 @@ xaringanthemer_env$std_ggplot_defaults <- list(
"step" = list(color = "black"),
"point" = list(color = "black"),
"polygon" = list(color = NA,
fill = "grey20"),
fill = "grey20"),
"quantile" = list(color = "#3366FF"),
"rug" = list(color = "black"),
"segment" = list(color = "black"),
"smooth" = list(fill = "grey60",
color = "#3366FF"),
color = "#3366FF"),
"spoke" = list(color = "black"),
"label" = list(color = "black",
family = ""),
family = ""),
"text" = list(color = "black",
family = ""),
family = ""),
"rect" = list(fill = "grey35"),
"tile" = list(fill = "grey20"),
"violin" = list(fill = "white", color = "grey20")

+ 1
- 1
tests/testthat/test-color.R Visa fil

@@ -16,7 +16,7 @@ describe("prepare_colors()", {
expect_warning(prepare_colors(c("light/blue" = "#88f")), "light/blue")
expect_warning(prepare_colors(c("-lightblue" = "#88f")), "-lightblue")
expect_warning(prepare_colors(c("_lightblue" = "#88f")), "_lightblue")
colors <- c("light_blue" = "#88f", "light-blue" = "#88f")
expect_silent(
expect_equal(

+ 2
- 2
tests/testthat/test-themes.R Visa fil

@@ -80,10 +80,10 @@ test_that("default fonts are correctly identified as google font", {
})

expect_equal(theme_vars$text_font_family,
quote_elements_w_spaces(xaringanthemer_font_default("text_font_family")))
quote_elements_w_spaces(xaringanthemer_font_default("text_font_family")))
expect_true(theme_vars$text_font_is_google)
expect_equal(theme_vars$header_font_family,
quote_elements_w_spaces(xaringanthemer_font_default("header_font_family")))
quote_elements_w_spaces(xaringanthemer_font_default("header_font_family")))
expect_true(theme_vars$header_font_is_google)
})


Laddar…
Avbryt
Spara