@@ -46,45 +46,45 @@ ggwrap <- function(plot, ..., align = "panel", on_top = FALSE,
4646 plot.background = element_blank(),
4747 panel.background = element_blank()
4848 )
49- grob <- make_inset(
49+ inset <- make_inset(
5050 plot = plot , ... , align = align , on_top = on_top ,
5151 clip = clip , vp = vp
5252 )
53- make_wrap(patch , grob )
53+ make_wrap(patch , inset )
5454}
5555
56- make_wrap <- function (patch , grob ) UseMethod(" make_wrap" )
56+ make_wrap <- function (patch , inset ) UseMethod(" make_wrap" )
5757
5858# ' @export
59- make_wrap.patch_ggplot <- function (patch , grob ) {
59+ make_wrap.patch_ggplot <- function (patch , inset ) {
6060 patch <- add_class(patch , " wrapped_plot" )
61- make_wrap(patch , grob )
61+ make_wrap(patch , inset )
6262}
6363
6464# ' @export
65- make_wrap.ggplot <- function (patch , grob ) {
65+ make_wrap.ggplot <- function (patch , inset ) {
6666 patch <- add_class(patch , " patch_ggplot" )
67- make_wrap(patch , grob )
67+ make_wrap(patch , inset )
6868}
6969
7070# ' @export
71- make_wrap.wrapped_plot <- function (patch , grob ) {
72- if (attr( grob , " on_top" )) {
73- attr( patch , " wrapped_grobs_above " ) <- c(
74- attr( patch , " wrapped_grobs_above " ), list (grob )
71+ make_wrap.wrapped_plot <- function (patch , inset ) {
72+ if (.subset2( inset , " on_top" )) {
73+ patch $ ggalign_wrapped_insets_above <- c(
74+ patch $ ggalign_wrapped_insets_above , list (inset )
7575 )
7676 } else {
77- attr( patch , " wrapped_grobs_under " ) <- c(
78- attr( patch , " wrapped_grobs_under " ), list (grob )
77+ patch $ ggalign_wrapped_insets_under <- c(
78+ patch $ ggalign_wrapped_insets_under , list (inset )
7979 )
8080 }
8181 patch
8282}
8383
8484# ' @export
85- make_wrap.alignpatches <- function (patch , grob ) {
85+ make_wrap.alignpatches <- function (patch , inset ) {
8686 patch <- add_class(patch , " wrapped_plot" )
87- make_wrap(patch , grob )
87+ make_wrap(patch , inset )
8888}
8989
9090# ################################################
@@ -94,12 +94,14 @@ alignpatch.wrapped_plot <- function(x) {
9494 Parent <- NextMethod()
9595 ggproto(
9696 " PatchWrapped" , Parent ,
97- wrapped_grobs_under = attr( x , " wrapped_grobs_under " ) ,
98- wrapped_grobs_above = attr( x , " wrapped_grobs_above " ) ,
97+ ggalign_wrapped_insets_under = x $ ggalign_wrapped_insets_under ,
98+ ggalign_wrapped_insets_above = x $ ggalign_wrapped_insets_above ,
9999 patch_gtable = function (self , plot = Parent $ plot ) {
100100 ans <- ggproto_parent(Parent , self )$ patch_gtable(plot = plot )
101- ans <- add_wrapped_grobs(ans , self $ wrapped_grobs_under , FALSE )
102- add_wrapped_grobs(ans , self $ wrapped_grobs_above , TRUE )
101+ ans <- add_wrapped_insets(
102+ ans , self $ ggalign_wrapped_insets_under , FALSE
103+ )
104+ add_wrapped_insets(ans , self $ ggalign_wrapped_insets_above , TRUE )
103105 }
104106 )
105107}
@@ -136,19 +138,20 @@ alignpatch.HeatmapAnnotation <- alignpatch.Heatmap
136138alignpatch.pheatmap <- function (x ) alignpatch(ggwrap(x , align = " full" ))
137139
138140# ################################################# 3
139- add_wrapped_grobs <- function (gt , grobs , on_top ) {
140- if (is.null(grobs )) return (gt ) # styler: off
141- for (i in seq_along(grobs )) {
142- gt <- add_wrapped_grob (gt , .subset2(grobs , i ), on_top , i )
141+ add_wrapped_insets <- function (gt , insets , on_top ) {
142+ if (is.null(insets )) return (gt ) # styler: off
143+ for (i in seq_along(insets )) {
144+ gt <- add_wrapped_inset (gt , .subset2(insets , i ), on_top , i )
143145 }
144146 gt
145147}
146148
147149# ' @importFrom gtable gtable is.gtable gtable_add_grob
148- add_wrapped_grob <- function (gt , grob , on_top , i ) {
149- align <- attr( grob , " align" )
150- clip <- attr( grob , " clip" )
150+ add_wrapped_inset <- function (gt , inset , on_top , i ) {
151+ align <- .subset2( inset , " align" )
152+ clip <- .subset2( inset , " clip" )
151153 layout <- .subset2(gt , " layout" )
154+ grob <- .subset2(inset , " grob" )
152155 if (on_top ) {
153156 z <- Inf
154157 } else {
0 commit comments