From c6cdff61689f8a6f0564f985b1d237e6e4711d14 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Fri, 25 Oct 2024 10:10:54 +0200 Subject: [PATCH] clean up grid code --- NAMESPACE | 1 - R/grid.R | 28 +++++----------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index e99ed42..ad0ed87 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,7 +11,6 @@ S3method(dimnames,gtable) S3method(heightDetails,gtable) S3method(length,gtable) S3method(makeContent,gtable) -S3method(makeContext,gTableChild) S3method(makeContext,gtable) S3method(plot,gtable) S3method(print,gtable) diff --git a/R/grid.R b/R/grid.R index 8306b51..ef62848 100644 --- a/R/grid.R +++ b/R/grid.R @@ -29,7 +29,7 @@ gtable_layout <- function(x) { vpname <- function(row) { row <- unclass(row) - paste(row$name, ".", row$t, "-", row$r, "-", row$b, "-", row$l, sep = "") + paste0(row$name, ".", row$t, "-", row$r, "-", row$b, "-", row$l) } #' @export @@ -51,30 +51,18 @@ makeContext.gtable <- function(x) { #' @export makeContent.gtable <- function(x) { + child_name <- vpname(x$layout) children_vps <- mapply(child_vp, - vp_name = vpname(x$layout), + vp_name = child_name, t = .subset2(x$layout, "t"), r = .subset2(x$layout, "r"), b = .subset2(x$layout, "b"), l = .subset2(x$layout, "l"), clip = .subset2(x$layout, "clip"), SIMPLIFY = FALSE ) - x$grobs <- mapply(wrap_gtableChild, x$grobs, children_vps, + x$grobs <- mapply(grobTree, x$grobs, name = child_name, vp = children_vps, SIMPLIFY = FALSE ) - setChildren(x, do.call("gList", x$grobs[order(.subset2(x$layout, "z"))])) -} - -#' @export -makeContext.gTableChild <- function(x) { - if (is.null(x$vp)) { - x$vp <- x$wrapvp - } else { - x$vp <- vpStack(x$wrapvp, x$vp) - } - # A gTableChild extends an arbitrary grob class - # so allow existing makeContext() behaviour of - # original grob class to still occur - NextMethod() + setChildren(x, inject(gList(!!!x$grobs[order(.subset2(x$layout, "z"))]))) } # Return the viewport for a child grob in a gtable @@ -84,9 +72,3 @@ child_vp <- function(vp_name, t, r, b, l, clip) { layout.pos.col = l:r, clip = clip ) } - -# Turn a grob into a gtableChild, and store information about the -# viewport used within the gtable -wrap_gtableChild <- function(grob, vp) { - grobTree(grob, name = vp$name, vp = vp) -}