Преглед изворни кода

Ensure that text_font reaches theme_xaringan_set_defaults() when set_ggplot_defaults == TRUE

tags/v0.3.0
Garrick Aden-Buie пре 6 година
родитељ
комит
d8ec41f343
2 измењених фајлова са 32 додато и 6 уклоњено
  1. +15
    -6
      R/ggplot2.R
  2. +17
    -0
      tests/testthat/test-ggplot2.R

+ 15
- 6
R/ggplot2.R Прегледај датотеку

get_theme_font("header") get_theme_font("header")
} }


text_font %||% "sans"
title_font %||% "sans"
text_font <- text_font %||% "sans"
title_font <- title_font %||% "sans"


if (set_ggplot_defaults) { if (set_ggplot_defaults) {
accent_color <- accent_color %||% xaringanthemer_env$header_color %||% text_color accent_color <- accent_color %||% xaringanthemer_env$header_color %||% text_color
accent_secondary_color <- accent_secondary_color %||% xaringanthemer_env$text_bold_color %||% accent_color accent_secondary_color <- accent_secondary_color %||% xaringanthemer_env$text_bold_color %||% accent_color
accent_color <- full_length_hex(accent_color) accent_color <- full_length_hex(accent_color)
accent_secondary_color <- full_length_hex(accent_secondary_color) accent_secondary_color <- full_length_hex(accent_secondary_color)
theme_xaringan_set_defaults(text_color, background_color, accent_color, accent_secondary_color)
theme_xaringan_set_defaults(
text_color = text_color,
background_color = background_color,
accent_color = accent_color,
accent_secondary_color = accent_secondary_color,
text_font = text_font
)
} }


theme <- ggplot2::theme( theme <- ggplot2::theme(
return(invisible()) return(invisible())
} }



old_default <- xaringanthemer_env$old_ggplot_defaults old_default <- xaringanthemer_env$old_ggplot_defaults
old_default_not_std <- vapply(old_default, function(x) length(x) > 0, logical(1)) old_default_not_std <- vapply(old_default, function(x) length(x) > 0, logical(1))
old_default <- old_default[old_default_not_std] old_default <- old_default[old_default_not_std]
} }


safely_set_geom <- function(geom, new) { safely_set_geom <- function(geom, new) {
warn <- function(x) {
rlang::warn(x$message)
invisible()
}
tryCatch( tryCatch(
{ {
ggplot2::update_geom_defaults(geom, new) ggplot2::update_geom_defaults(geom, new)
}, },
error = function(e) invisible(),
warning = function(w) invisible()
error = warn,
warning = warn
) )
} }



+ 17
- 0
tests/testthat/test-ggplot2.R Прегледај датотеку

}) })
) )
}) })

it("correctly overwrites geom default values", {
fonts <- with_clean_session(function() {
style <- xaringanthemer::style_xaringan(outfile = NULL)

g <- ggplot2::ggplot(mtcars, ggplot2::aes(x = cyl, y = disp, label = carb))
fonts <- list()
plot1 <- g + ggplot2::geom_text() + xaringanthemer::theme_xaringan()
fonts[[1]] <- plot1$layers[[1]]$geom$default_aes$family
plot2 <- g + ggplot2::geom_text() + xaringanthemer::theme_xaringan(text_font = "Ranga", text_font_use_google = TRUE)
fonts[[2]] <- plot2$layers[[1]]$geom$default_aes$family
fonts
})

expect_equal(fonts[[1]], "Noto Sans")
expect_equal(fonts[[2]], "Ranga")
})
}) })


describe("theme_xaringan_inverse()", { describe("theme_xaringan_inverse()", {

Loading…
Откажи
Сачувај