Explorar el Código

Add merge method for two anim_options() objects

pull/18/head
Garrick Aden-Buie hace 7 años
padre
commit
e6fced3886
Se han modificado 2 ficheros con 22 adiciones y 0 borrados
  1. +14
    -0
      R/plot_helpers.R
  2. +8
    -0
      tests/testthat/test-anim_options.R

+ 14
- 0
R/plot_helpers.R Ver fichero

@@ -75,6 +75,20 @@ validate_anim_opts <- function(ao, quiet = FALSE, strict = getOption("tidyexplai
invisible(ao)
}

merge.anim_opts <- function(ao_new, ao_base = anim_options()) {
ao_new <- remove_default_anim_opts(ao_new)
utils::modifyList(ao_base, ao_new, TRUE)
}

remove_default_anim_opts <- function(ao) {
ao_default <- anim_options()
same_names <- purrr::map2_lgl(ao, ao_default, ~ identical(names(.x), names(.y)))
same <- purrr::map2_lgl(ao, ao_default, ~ identical(.x, .y))
same[["enter"]] <- same_names[["enter"]]
same[["exit"]] <- same_names[["exit"]]
ao[!same]
}

#' Animates a plot
#'
#' @param d a processed dataset

+ 8
- 0
tests/testthat/test-anim_options.R Ver fichero

@@ -0,0 +1,8 @@
context("test-anim_options")

test_that("merging of animation options works", {
ao_new <- anim_options(5, 3, text_size = 9, title_size = 13)
ao_old <- anim_options(ease_default = "cubic-in", text_family = "Times New Roman")
ao_merged <- anim_options(5, 3, "cubic-in", text_size = 9, title_size = 13, text_family = "Times New Roman")
expect_equal(merge(ao_new, ao_old), ao_merged)
})

Cargando…
Cancelar
Guardar