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

Add default_anim_opts()

Lets us define default animation options by animation family that can be overridden by the user at runtime. Demonstration of usage with animate_gather() and animate_spread()
pull/18/head
Garrick Aden-Buie пре 7 година
родитељ
комит
86a4f387f5
2 измењених фајлова са 21 додато и 3 уклоњено
  1. +4
    -3
      R/animate_tidyr.R
  2. +17
    -0
      R/plot_helpers.R

+ 4
- 3
R/animate_tidyr.R Прегледај датотеку

@@ -1,4 +1,3 @@

#' Animates the gather function
#'
#' @param w a data_frame in the wide format
@@ -29,7 +28,8 @@
#' # if you want to have a less detailed animation, you can also use
#' animate_gather(wide, "person", "sales", -year, export = "gif", detailed = FALSE)
#' }
animate_gather <- function(w, key, value, ..., export = "gif", detailed = TRUE, anim_opts = anim_options()) {
animate_gather <- function(w, key, value, ..., export = "gif", detailed = TRUE, anim_opts = NULL) {
anim_opts <- default_anim_opts("gather", anim_opts)
lhs <- w
rhs <- tidyr::gather(w, !!key, !!value, ...)

@@ -88,7 +88,8 @@ animate_gather <- function(w, key, value, ..., export = "gif", detailed = TRUE,
#' # if you want to have a less detailed animation, you can also use
#' animate_spread(long, key = "person", value = "sales", export = "gif", detailed = FALSE)
#' }
animate_spread <- function(l, key, value, export = "gif", detailed = TRUE, ..., anim_opts = anim_options()) {
animate_spread <- function(l, key, value, export = "gif", detailed = TRUE, ..., anim_opts = NULL) {
anim_opts <- default_anim_opts("spread", anim_opts)

lhs <- l
rhs <- tidyr::spread(l, key = key, value = value)

+ 17
- 0
R/plot_helpers.R Прегледај датотеку

@@ -89,6 +89,23 @@ remove_default_anim_opts <- function(ao) {
ao[!same]
}

default_anim_opts <- function(family, ao_custom = NULL) {
family_options <- c("join", "set", "gather", "spread")
family <- match.arg(family, family_options, several.ok = FALSE)
ao_default <- switch(
family,
"gather" = anim_options(enter = enter_fade(), exit = exit_fade(),
ease_default = "sine-in-out",
ease_other = list(y = "cubic-out", x = "cubic-in")),
"spread" = anim_options(enter = enter_fade(), exit = exit_fade(),
ease_default = "sine-in-out",
ease_other = list(y = "cubic-out", x = "cubic-in")),
anim_options()
)
if (is.null(ao_custom)) return(ao_default)
merge(ao_custom, ao_default)
}

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

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