Kaynağa Gözat

Add validate_anim_opts() and fix passing of options to static_plot()

Set option "tidyexplain.strict_dots" to TRUE for checking for issues with extra arguments being passed in ... to the _plot() functions.
pkg-add-anim-opts-fixed
Garrick Aden-Buie 7 yıl önce
ebeveyn
işleme
259d86b6b1
1 değiştirilmiş dosya ile 18 ekleme ve 5 silme
  1. +18
    -5
      R/plot_helpers.R

+ 18
- 5
R/plot_helpers.R Dosyayı Görüntüle

) )
} }


validate_anim_opts <- function(ao, quiet = FALSE, strict = getOption("tidyexplain.strict_dots", FALSE)) {
if (!inherits(ao, "anim_opts")) {
rlang::warn("Use `anim_options()` to set `anim_opts`")
}
extra_names <- setdiff(names(ao), names(formals(anim_options)))
if (!quiet && length(extra_names)) {
extra_names <- paste0(sprintf("`%s`", extra_names), collapse = ", ")
msg <- paste("Unknown animation options will be ignored:", extra_names)
if (isTrue(strict)) rlang::abort(msg) else rlang::warn(msg)
}
invisible(ao)
}

#' Animates a plot #' Animates a plot
#' #'
#' @param d a processed dataset #' @param d a processed dataset
..., ...,
anim_opts = anim_options(...) anim_opts = anim_options(...)
) { ) {
ao <- anim_opts
ao <- validate_anim_opts(anim_opts)
ease_opts <- if (!is.null(ao$ease_other)) { ease_opts <- if (!is.null(ao$ease_other)) {
ao$ease_other$default <- ao$ease_default ao$ease_other$default <- ao$ease_default
ao$ease_other ao$ease_other
} else list(default = ao$ease_default) } else list(default = ao$ease_default)
ao_ease_aes <- do.call(ease_aes, ease_opts) ao_ease_aes <- do.call(ease_aes, ease_opts)


static_plot(d, title, ao$text_family, ao$title_family, ao$text_size, ao$title_size) +
static_plot(d, title, anim_opts = ao) +
transition_states(.frame, ao$transition_length, ao$state_length) + transition_states(.frame, ao$transition_length, ao$state_length) +
ao$enter_ +
ao$exit_ +
ao$enter +
ao$exit +
ao_ease_aes ao_ease_aes
} }


..., ...,
anim_opts = anim_options(...) anim_opts = anim_options(...)
) { ) {
ao <- anim_opts
ao <- validate_anim_opts(anim_opts)
text_size <- get_text_size(ao$text_size, default = 5) text_size <- get_text_size(ao$text_size, default = 5)
title_size <- get_title_size(ao$title_size, default = 17) title_size <- get_title_size(ao$title_size, default = 17)



Yükleniyor…
İptal
Kaydet