From 5bb8e0671a34565ee245e0688c715a5ac52f69e4 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 22 Feb 2024 15:58:38 +0100 Subject: [PATCH] More aggressively enforce device capabilities --- R/geom-ribbon.R | 6 ++++-- tests/testthat/test-geom-ribbon.R | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/R/geom-ribbon.R b/R/geom-ribbon.R index 1c9fa1ece2..462486f050 100644 --- a/R/geom-ribbon.R +++ b/R/geom-ribbon.R @@ -141,6 +141,9 @@ GeomRibbon <- ggproto("GeomRibbon", Geom, ) non_constant <- names(aes)[lengths(aes) > 1] if (coord$is_linear()) { + if (any(c("fill", "alpha") %in% non_constant)) { + check_device("gradients", action = "abort", maybe = TRUE) + } # For linear coords, we can make a fill/alpha gradient, so we allow # these to vary non_constant <- setdiff(non_constant, c("fill", "alpha")) @@ -150,8 +153,7 @@ GeomRibbon <- ggproto("GeomRibbon", Geom, "Aesthetics can not vary along a ribbon: {.and {.field {non_constant}}}." ) } - if (length(aes$fill) > 1 || length(aes$alpha) > 1) { - check_device("gradients") + if ((length(aes$fill) > 1 || length(aes$alpha) > 1)) { transformed <- coord$transform(flip_data(data, flipped_aes), panel_params) if (flipped_aes) { keep <- is.finite(tranformed$y) diff --git a/tests/testthat/test-geom-ribbon.R b/tests/testthat/test-geom-ribbon.R index e03af02a9c..22e98a81c2 100644 --- a/tests/testthat/test-geom-ribbon.R +++ b/tests/testthat/test-geom-ribbon.R @@ -76,6 +76,10 @@ test_that("outline.type option works", { }) test_that("ribbons can have gradients", { + skip_if_not( + check_device("gradients", action = "test"), + "graphics device does not support gradients." + ) df <- data.frame(x = 1:2, ymin = c(-1:-2), ymax = 1:2) p <- ggplot(df, aes(x, ymin = ymin, ymax = ymax, fill = x)) +