From 3b35395fe39969138ece727e3a7928c9a7e3ce9d Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Mon, 4 Sep 2023 11:39:23 +0200 Subject: [PATCH] Fix #473 --- NEWS.md | 3 ++- R/transition_reveal.R | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index ac8ebc8..907ec66 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,8 @@ * Fix for using `"svg"` device during knitting (#484) * Fix for correctly getting chunk options during knitting (#485) -* Fix a bug in `transition_reveal()` that would remove terminal data (#480) +* Fix a bug in `transition_reveal()` that would remove data during transitions + (#480 and #473) * General upkeep to keep it in line with the evolvling coding principles in ggplot2 (move to using vctrs, cli, lifecycle, etc) * `transition_reveal()` now throws an error when it is used in conjunction with diff --git a/R/transition_reveal.R b/R/transition_reveal.R index d878e6a..71292f2 100644 --- a/R/transition_reveal.R +++ b/R/transition_reveal.R @@ -151,10 +151,12 @@ TransitionReveal <- ggproto('TransitionReveal', Transition, ) all_frames$group <- paste0(all_frames$group, '<', all_frames$.frame, '>') all_frames$.frame <- NULL - repeated <- c(diff(all_frames$.time), 1) <= .Machine$double.eps & - c(all_frames$group[-nrow(all_frames)] == all_frames$group[-1], TRUE) & - all_frames$.phase == 'raw' - all_frames[!repeated, ] + transitions <- setdiff(which(all_frames$.phase == "transition"), 1L) + transitions <- transitions[all_frames$.phase[transitions-1L] == "raw" & all_frames$group[transitions-1L] == all_frames$group[transitions]] + possible_repeats <- sort(c(transitions, transitions - 1L)) + repeated <- duplicated(all_frames[possible_repeats, names(all_frames) != '.phase'], fromLast = TRUE) + repeated <- possible_repeats[repeated] + if (length(repeated) == 0) all_frames else all_frames[-repeated, ] } )