Skip to content

Commit 21ccbd3

Browse files
committed
More aggressively enforce device capabilities
1 parent 6724458 commit 21ccbd3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

R/geom-ribbon.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
141141
)
142142
non_constant <- names(aes)[lengths(aes) > 1]
143143
if (coord$is_linear()) {
144+
if (any(c("fill", "alpha") %in% non_constant)) {
145+
check_device("gradients", action = "abort", maybe = TRUE)
146+
}
144147
# For linear coords, we can make a fill/alpha gradient, so we allow
145148
# these to vary
146149
non_constant <- setdiff(non_constant, c("fill", "alpha"))
@@ -150,8 +153,7 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
150153
"Aesthetics can not vary along a ribbon: {.and {.field {non_constant}}}."
151154
)
152155
}
153-
if (length(aes$fill) > 1 || length(aes$alpha) > 1) {
154-
check_device("gradients")
156+
if ((length(aes$fill) > 1 || length(aes$alpha) > 1)) {
155157
transformed <- coord$transform(flip_data(data, flipped_aes), panel_params)
156158
if (flipped_aes) {
157159
keep <- is.finite(tranformed$y)

tests/testthat/test-geom-ribbon.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ test_that("outline.type option works", {
7676
})
7777

7878
test_that("ribbons can have gradients", {
79+
skip_if_not(
80+
check_device("gradients", action = "test"),
81+
"graphics device does not support gradients."
82+
)
7983

8084
df <- data.frame(x = 1:2, ymin = c(-1:-2), ymax = 1:2)
8185
p <- ggplot(df, aes(x, ymin = ymin, ymax = ymax, fill = x)) +

0 commit comments

Comments
 (0)