Skip to content

Commit

Permalink
Merge branch 'main' into 1121_lbls_fmts_utilities@main
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua authored Nov 6, 2023
2 parents 2760b64 + f6f72b7 commit 5d4a89f
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tern
Title: Create Common TLGs Used in Clinical Trials
Version: 0.9.2.9008
Version: 0.9.2.9009
Date: 2023-11-06
Authors@R: c(
person("Joe", "Zhu", , "[email protected]", role = c("aut", "cre")),
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# tern 0.9.2.9008
# tern 0.9.2.9009

### New Features
* Added `ref_group_position` function to place the reference group facet last, first or at a certain position.
Expand All @@ -13,6 +13,9 @@
* Added `annot_coxph_ref_lbls` parameter to `g_km` to enable printing the reference group in table labels when `annot_coxph = TRUE`.
* Added `x_lab` parameter to `g_lineplot` to customize x-axis label.

### Bug Fixes
* Fixed bug in `decorate_grob` preventing text wrapping from accounting for font size.

### Miscellaneous
* Specified minimal version of package dependencies.

Expand Down
30 changes: 19 additions & 11 deletions R/decorate_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ decorate_grob <- function(grob,
titles,
footnotes,
page = "",
width_titles = grid::unit(1, "npc") - grid::stringWidth(page),
width_footnotes = grid::unit(1, "npc") - grid::stringWidth(page),
width_titles = grid::unit(1, "npc") - grid::unit(1.5, "cm"),
width_footnotes = grid::unit(1, "npc") - grid::unit(1.5, "cm"),
border = TRUE,
margins = grid::unit(c(1, 0, 1, 0), "lines"),
padding = grid::unit(rep(1, 4), "lines"),
Expand Down Expand Up @@ -161,6 +161,14 @@ decorate_grob <- function(grob,
gp = gp_footnotes
)

pg_footnote <- grid::textGrob(
paste("\n", page),
x = 1, y = 0,
just = c("right", "bottom"),
vp = grid::viewport(layout.pos.row = 4, layout.pos.col = 1),
gp = gp_footnotes
)

grid::gTree(
grob = grob,
titles = titles,
Expand Down Expand Up @@ -194,25 +202,20 @@ decorate_grob <- function(grob,
)
),
st_footnotes,
grid::textGrob(
page,
x = 1, y = 0,
just = c("right", "bottom"),
vp = grid::viewport(layout.pos.row = 3, layout.pos.col = 1),
gp = gp_footnotes
)
pg_footnote
),
childrenvp = NULL,
name = "titles_grob_footnotes",
vp = grid::vpStack(
grid::plotViewport(margins = outer_margins),
grid::viewport(
layout = grid::grid.layout(
nrow = 3, ncol = 1,
nrow = 4, ncol = 1,
heights = grid::unit.c(
grid::grobHeight(st_titles),
grid::unit(1, "null"),
grid::grobHeight(st_footnotes)
grid::grobHeight(st_footnotes),
grid::grobHeight(pg_footnote)
)
)
)
Expand Down Expand Up @@ -325,6 +328,11 @@ split_text_grob <- function(text,
if (grid::unitType(y) %in% c("sum", "min", "max")) y <- grid::convertUnit(y, default.units)
if (grid::unitType(width) %in% c("sum", "min", "max")) width <- grid::convertUnit(width, default.units)

if (length(gp) > 0) { # account for effect of gp on text width
width <- width * grid::convertWidth(grid::grobWidth(grid::textGrob(text)), "npc", valueOnly = TRUE) /
grid::convertWidth(grid::grobWidth(grid::textGrob(text, gp = gp)), "npc", valueOnly = TRUE)
}

## if it is a fixed unit then we do not need to recalculate when viewport resized
if (!inherits(width, "unit.arithmetic") && !is.null(attr(width, "unit")) &&
attr(width, "unit") %in% c("cm", "inches", "mm", "points", "picas", "bigpts", "dida", "cicero", "scaledpts")) { # nolint
Expand Down
4 changes: 2 additions & 2 deletions man/decorate_grob.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5d4a89f

Please sign in to comment.