Skip to content

Commit 4912195

Browse files
committed
allow for relative spacing in redistribute_null_units()
1 parent 63ca94e commit 4912195

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

R/guides-.R

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -933,26 +933,20 @@ redistribute_null_units <- function(units, spacing, margin, type = "width") {
933933
}
934934

935935
# Get spacing between guides and margins in absolute units
936-
size <- switch(type, width = convertWidth, height = convertHeight)
937-
spacing <- size(spacing, "cm", valueOnly = TRUE)
938-
spacing <- sum(rep(spacing, length(units) - 1))
936+
size <- switch(type, width = width_cm, height = height_cm)
937+
spacing <- sum(rep(spacing, length.out = length(units) - 1))
939938
margin <- switch(type, width = margin[c(2, 4)], height = margin[c(1, 3)])
940-
margin <- sum(size(margin, "cm", valueOnly = TRUE))
939+
margin <- sum(size(margin))
941940

942941
# Get the absolute parts of the unit
943-
absolute <- vapply(units, function(u) {
944-
u <- absolute.size(u)
945-
u <- size(u, "cm", valueOnly = TRUE)
946-
sum(u)
947-
}, numeric(1))
948-
absolute_sum <- sum(absolute) + spacing + margin
942+
absolute <- vapply(units, function(u) sum(size(absolute.size(u))), numeric(1))
943+
absolute_sum <- sum(absolute) + sum(size(spacing)) + margin
949944

950945
# Get the null parts of the unit
946+
num_null <- function(x) sum(as.numeric(x)[unitType(x) == "null"])
951947
relative <- rep(0, length(units))
952-
relative[has_null] <- vapply(units[has_null], function(u) {
953-
sum(as.numeric(u)[unitType(u) == "null"])
954-
}, numeric(1))
955-
relative_sum <- sum(relative)
948+
relative[has_null] <- vapply(units[has_null], num_null, numeric(1))
949+
relative_sum <- sum(relative) + num_null(spacing)
956950

957951
if (relative_sum == 0) {
958952
return(unit(absolute, "cm"))

0 commit comments

Comments
 (0)