Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions R/geom-label.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,27 @@ labelGrob <- function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"),
descent <- font_descent(
text.gp$fontfamily, text.gp$fontface, text.gp$fontsize, text.gp$cex
)
# To balance labels, we ensure the top includes at least the descent height
# and subtract the descent height from the bottom padding
padding[1] <- unit.pmax(padding[1], descent)
padding[3] <- unit.pmax(padding[3] - descent, unit(0, "pt"))

hjust <- resolveHJust(just, NULL)
vjust <- resolveVJust(just, NULL)

text <- titleGrob(
label = label, hjust = hjust, vjust = vjust, x = x, y = y,
label = label, hjust = hjust, vjust = vjust, x = x,
y = y + (1 - vjust) * descent,
margin = padding, margin_x = TRUE, margin_y = TRUE,
gp = text.gp
)

height <- heightDetails(text)
box <- roundrectGrob(
x = x, y = y - (1 - vjust) * descent,
x = x, y = y + (0.5 - vjust) * height,
width = widthDetails(text),
height = heightDetails(text),
just = c(hjust, vjust),
height = height,
just = c(hjust, 0.5),
r = r, gp = rect.gp, name = "box"
)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.