Skip to content

Commit

Permalink
More aggressively enforce device capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Feb 22, 2024
1 parent 62555b0 commit 5bb8e06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/geom-ribbon.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-geom-ribbon.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) +
Expand Down

0 comments on commit 5bb8e06

Please sign in to comment.