@@ -94,7 +94,7 @@ Layout <- ggproto("Layout", NULL,
9494 theme ,
9595 self $ facet_params
9696 )
97- plot_table <- self $ set_panel_size(plot_table , theme )
97+ plot_table <- self $ facet $ set_panel_size(plot_table , theme )
9898
9999 # Draw individual labels, then add to gtable
100100 labels <- self $ coord $ labels(
@@ -298,54 +298,6 @@ Layout <- ggproto("Layout", NULL,
298298 })
299299 names(label_grobs ) <- names(labels )
300300 label_grobs
301- },
302-
303- set_panel_size = function (table , theme ) {
304-
305- new_widths <- calc_element(" panel.widths" , theme )
306- new_heights <- calc_element(" panel.heights" , theme )
307-
308- if (is.null(new_widths ) && is.null(new_heights )) {
309- return (table )
310- }
311-
312- if (isTRUE(table $ respect )) {
313- args <- ! c(is.null(new_widths ), is.null(new_heights ))
314- args <- c(" panel.widths" , " panel.heights" )[args ]
315- cli :: cli_warn(
316- " Aspect ratios are overruled by {.arg {args}} theme element{?s}."
317- )
318- table $ respect <- FALSE
319- }
320-
321- rows <- panel_rows(table )
322- cols <- panel_cols(table )
323-
324- if (length(new_widths ) == 1L && nrow(cols ) > 1L ) {
325- # Get total size of non-panel widths in between panels
326- extra <- setdiff(seq(min(cols $ l ), max(cols $ r )), union(cols $ l , cols $ r ))
327- extra <- unit(sum(width_cm(table $ widths [extra ])), " cm" )
328- # Distribute width proportionally
329- relative <- as.numeric(table $ widths [cols $ l ]) # assumed to be simple units
330- new_widths <- (new_widths - extra ) * (relative / sum(relative ))
331- }
332- if (! is.null(new_widths )) {
333- table $ widths [cols $ l ] <- rep(new_widths , length.out = nrow(cols ))
334- }
335-
336- if (length(new_heights ) == 1L && nrow(rows ) > 1L ) {
337- # Get total size of non-panel heights in between panels
338- extra <- setdiff(seq(min(rows $ t ), max(rows $ t )), union(rows $ t , rows $ b ))
339- extra <- unit(sum(height_cm(table $ heights [extra ])), " cm" )
340- # Distribute height proportionally
341- relative <- as.numeric(table $ heights [rows $ t ]) # assumed to be simple units
342- new_heights <- (new_heights - extra ) * (relative / sum(relative ))
343- }
344- if (! is.null(new_heights )) {
345- table $ heights [rows $ t ] <- rep(new_heights , length.out = nrow(rows ))
346- }
347-
348- table
349301 }
350302)
351303
0 commit comments