Skip to content

Commit 3b52285

Browse files
committed
make rotate_just() resilient for mixed S3/S7 classes
1 parent e14be3c commit 3b52285

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

R/guide-axis.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,13 @@ GuideAxis <- ggproto(
454454
# rather than dimensions of this axis alone.
455455
if (has_labels && params$position %in% c("left", "right")) {
456456
where <- layout$l[-c(1, length(layout$l))]
457-
just <- with(S7::props(elements$text), rotate_just(angle, hjust, vjust))$hjust %||% 0.5
457+
just <- rotate_just(element = elements$text)$hjust %||% 0.5
458458
gt <- gtable_add_cols(gt, unit(just, "null"), pos = min(where) - 1)
459459
gt <- gtable_add_cols(gt, unit(1 - just, "null"), pos = max(where) + 1)
460460
}
461461
if (has_labels && params$position %in% c("top", "bottom")) {
462462
where <- layout$t[-c(1, length(layout$t))]
463-
just <- with(S7::props(elements$text), rotate_just(angle, hjust, vjust))$vjust %||% 0.5
463+
just <- rotate_just(element = elements$text)$vjust %||% 0.5
464464
gt <- gtable_add_rows(gt, unit(1 - just, "null"), pos = min(where) - 1)
465465
gt <- gtable_add_rows(gt, unit(just, "null"), pos = max(where) + 1)
466466
}

R/guide-custom.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ GuideCustom <- ggproto(
113113

114114
gt <- self$add_title(
115115
gt, title, title_position,
116-
with(S7::props(elems$title), rotate_just(angle, hjust, vjust))
116+
rotate_just(element = elems$title)
117117
)
118118

119119
# Add padding and background

R/guide-legend.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ GuideLegend <- ggproto(
574574

575575
gt <- self$add_title(
576576
gt, grobs$title, elements$title_position,
577-
with(S7::props(elements$title), rotate_just(angle, hjust, vjust))
577+
rotate_just(element = elements$title)
578578
)
579579

580580
gt <- gtable_add_padding(gt, unit(elements$padding, "cm"))

R/margins.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ heightDetails.titleGrob <- function(x) {
198198
#' @return A list with two components, `hjust` and `vjust`, containing the rotated hjust and vjust values
199199
#'
200200
#' @noRd
201-
rotate_just <- function(angle, hjust, vjust) {
201+
rotate_just <- function(angle = NULL, hjust = NULL, vjust = NULL, element = NULL) {
202202
## Ideally we would like to do something like the following commented-out lines,
203203
## but it currently yields unexpected results for angles other than 0, 90, 180, 270.
204204
## Problems arise in particular in cases where the horizontal and the vertical
@@ -213,6 +213,14 @@ rotate_just <- function(angle, hjust, vjust) {
213213
#
214214
#hnew <- cos(rad) * hjust - sin(rad) * vjust + (1 - cos(rad) + sin(rad)) / 2
215215
#vnew <- sin(rad) * hjust + cos(rad) * vjust + (1 - cos(rad) - sin(rad)) / 2
216+
if (S7::S7_inherits(element)) {
217+
element <- S7::props(element)
218+
}
219+
if (!is.null(element)) {
220+
angle <- element$angle
221+
hjust <- element$hjust
222+
vjust <- element$vjust
223+
}
216224

217225
angle <- (angle %||% 0) %% 360
218226

0 commit comments

Comments
 (0)