Skip to content

Commit

Permalink
Fix: styler
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades committed Sep 7, 2024
1 parent 8180345 commit fa578e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 9 additions & 2 deletions R/decorate_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,17 @@ split_text_grob <- function(text,
horizontal_npc_width_no_gp <- grid::convertWidth(
grid::grobWidth(
grid::textGrob(
paste0(text, collapse = "\n"))), "npc", valueOnly = TRUE)
paste0(text, collapse = "\n")
)
), "npc",
valueOnly = TRUE
)
horizontal_npc_width_with_gp <- grid::convertWidth(grid::grobWidth(
grid::textGrob(
paste0(text, collapse = "\n"), gp = gp)), "npc", valueOnly = TRUE)
paste0(text, collapse = "\n"),
gp = gp
)
), "npc", valueOnly = TRUE)

# Adapting width to the input gpar (it is normalized so does not matter what is text)
width <- width * horizontal_npc_width_no_gp / horizontal_npc_width_with_gp
Expand Down
13 changes: 7 additions & 6 deletions tests/testthat/test-decorate_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ testthat::test_that("Wrapping works consistently", {
collapse = " "
)
subtitles <- c("something\nwith\\n", "", "and such")
out <- split_text_grob(c(titles, subtitles), x = 0, y = 1,
just = c("left", "top"),
width = grid::unit(11.63, "inches") - grid::unit(1.5, "cm"),
vp = grid::viewport(layout.pos.row = 1, layout.pos.col = 1),
gp = grid::gpar()
)
out <- split_text_grob(c(titles, subtitles),
x = 0, y = 1,
just = c("left", "top"),
width = grid::unit(11.63, "inches") - grid::unit(1.5, "cm"),
vp = grid::viewport(layout.pos.row = 1, layout.pos.col = 1),
gp = grid::gpar()
)

expect_equal(
nchar(strsplit(out$label, "\n")[[1]]),
Expand Down

0 comments on commit fa578e4

Please sign in to comment.