Skip to content

Commit 9aa186c

Browse files
committed
Make the input panels for Facet$draw_panesl predicatable
1 parent 8b2a764 commit 9aa186c

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

R/coord-.R

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,14 @@ Coord <- ggproto("Coord",
211211
},
212212

213213
draw_panel = function(self, panel, params, theme) {
214-
fg <- self$render_fg(params, theme)
215-
bg <- self$render_bg(params, theme)
214+
fg <- ensure_grob(self$render_fg(params, theme))
215+
bg <- ensure_grob(self$render_bg(params, theme))
216216
if (isTRUE(theme$panel.ontop)) {
217-
panel <- list2(!!!panel, bg, fg)
217+
panel <- gList(panel, bg, fg)
218218
} else {
219-
panel <- list2(bg, !!!panel, fg)
219+
panel <- gList(bg, panel, fg)
220220
}
221-
gTree(
222-
children = inject(gList(!!!panel)),
223-
vp = viewport(clip = self$clip)
224-
)
221+
gTree(children = panel, vp = viewport(clip = self$clip))
225222
}
226223
)
227224

R/coord-radial.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
405405
# Note that clipping path is applied to panel without coord
406406
# foreground/background (added in parent method).
407407
# These may contain decorations that needn't be clipped
408-
panel <- list(gTree(
409-
children = inject(gList(!!!panel)),
410-
vp = viewport(clip = clip_path)
411-
))
408+
panel <- editGrob(panel, vp = viewport(clip = clip_path))
412409
}
413410
ggproto_parent(Coord, self)$draw_panel(panel, params, theme)
414411
},

R/layer.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ Layer <- ggproto("Layer", NULL,
452452
}
453453

454454
data <- self$geom$handle_na(data, self$computed_geom_params)
455-
self$geom$draw_layer(data, self$computed_geom_params, layout, layout$coord)
455+
grobs <- self$geom$draw_layer(data,
456+
self$computed_geom_params,
457+
layout, layout$coord
458+
)
459+
lapply(grobs, ensure_grob)
456460
}
457461
)
458462

R/layout.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ Layout <- ggproto("Layout", NULL,
7878

7979
# Draw individual panels, then assemble into gtable
8080
panels <- lapply(seq_along(panels[[1]]), function(i) {
81-
panel <- lapply(panels, `[[`, i)
82-
panel <- c(facet_bg[i], panel, facet_fg[i])
81+
panel <- gTree(children = inject(gList(!!!lapply(panels, `[[`, i))))
82+
panel <- gTree(children = gList(
83+
ensure_grob(facet_bg[[i]]),
84+
panel,
85+
ensure_grob(facet_fg[[i]])
86+
))
8387
panel <- self$coord$draw_panel(panel, self$panel_params[[i]], theme)
8488
ggname(paste("panel", i, sep = "-"), panel)
8589
})

R/utilities-grid.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ grid::unit
44
#' @export
55
grid::arrow
66

7+
# helper function to ensure the object is a grob
8+
# This will simply return a `zeroGrob()` for non-grob object
9+
ensure_grob <- function(x) {
10+
if (inherits(x, "gList")) x <- gTree(children = x)
11+
if (is.grob(x)) x else zeroGrob()
12+
}
13+
714
# Name ggplot grid object
815
# Convenience function to name grid objects
916
#

0 commit comments

Comments
 (0)