Skip to content

Commit 9e6df2c

Browse files
author
Yunuuuu
committed
fix: align tag sizes when placed on the canvas
1 parent 8a102ce commit 9e6df2c

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

R/alignpatch-alignpatches.R

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ PatchAlignpatches <- ggproto(
639639

640640
# setup sizes for non-panel rows/columns --------------
641641
sizes <- table_sizes(
642+
widths = .subset2(gt, "widths"),
643+
heights = .subset2(gt, "heights"),
642644
sizes_list, panel_widths, panel_heights,
643645
area, dims[2L], dims[1L]
644646
)
@@ -806,11 +808,13 @@ PatchAlignpatches <- ggproto(
806808
)
807809

808810
#' @importFrom grid convertHeight convertWidth unit
809-
table_sizes <- function(sizes_list, panel_widths, panel_heights,
811+
table_sizes <- function(widths, heights, sizes_list,
812+
panel_widths, panel_heights,
810813
area, ncol, nrow) {
811814
# `null` unit of the panel area will be converted into 0
812815
# we'll set the panel width and height afterward
813-
widths <- lapply(sizes_list, function(sizes) {
816+
widths <- convertWidth(widths, "mm", valueOnly = TRUE)
817+
subplots_widths <- lapply(sizes_list, function(sizes) {
814818
if (is.null(sizes)) {
815819
left <- right <- NULL
816820
} else {
@@ -829,7 +833,7 @@ table_sizes <- function(sizes_list, panel_widths, panel_heights,
829833
}
830834
c(l, 0, r)
831835
})
832-
widths <- vapply(seq_len(ncol * TABLE_COLS), function(i) {
836+
subplots_widths <- vapply(seq_len(ncol * TABLE_COLS), function(i) {
833837
area_col <- locate_recycle_which_block(i, TABLE_COLS)
834838
col_loc <- locate_recycle_which_position(i, TABLE_COLS)
835839
if (col_loc == LEFT_BORDER + 1L) {
@@ -839,7 +843,7 @@ table_sizes <- function(sizes_list, panel_widths, panel_heights,
839843
idx <- field(area, area_side) == area_col
840844
if (any(idx)) {
841845
max(
842-
vapply(.subset(widths, idx), function(width) {
846+
vapply(.subset(subplots_widths, idx), function(width) {
843847
.subset(width, col_loc)
844848
}, numeric(1L), USE.NAMES = FALSE),
845849
0L
@@ -848,7 +852,10 @@ table_sizes <- function(sizes_list, panel_widths, panel_heights,
848852
0L
849853
}
850854
}, numeric(1L), USE.NAMES = FALSE)
851-
heights <- lapply(sizes_list, function(sizes) {
855+
widths <- pmax(widths, subplots_widths)
856+
857+
heights <- convertHeight(heights, "mm", valueOnly = TRUE)
858+
subplots_heights <- lapply(sizes_list, function(sizes) {
852859
if (is.null(sizes)) {
853860
top <- bottom <- NULL
854861
} else {
@@ -867,7 +874,7 @@ table_sizes <- function(sizes_list, panel_widths, panel_heights,
867874
}
868875
c(t, 0, b)
869876
})
870-
heights <- vapply(seq_len(nrow * TABLE_ROWS), function(i) {
877+
subplots_heights <- vapply(seq_len(nrow * TABLE_ROWS), function(i) {
871878
area_row <- locate_recycle_which_block(i, TABLE_ROWS)
872879
row_loc <- locate_recycle_which_position(i, TABLE_ROWS)
873880
if (row_loc == TOP_BORDER + 1L) {
@@ -878,7 +885,7 @@ table_sizes <- function(sizes_list, panel_widths, panel_heights,
878885
if (any(idx)) {
879886
max(
880887
vapply(
881-
.subset(heights, idx), .subset, numeric(1L),
888+
.subset(subplots_heights, idx), .subset, numeric(1L),
882889
row_loc,
883890
USE.NAMES = FALSE
884891
),
@@ -888,6 +895,7 @@ table_sizes <- function(sizes_list, panel_widths, panel_heights,
888895
0L
889896
}
890897
}, numeric(1L), USE.NAMES = FALSE)
898+
heights <- pmax(heights, subplots_heights)
891899

892900
# restore the panel sizes ----------------------------
893901
widths <- unit(widths, "mm")

0 commit comments

Comments
 (0)