Skip to content

Commit

Permalink
add test for releasing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Dec 13, 2024
1 parent 1b065e5 commit f05279f
Show file tree
Hide file tree
Showing 6 changed files with 605 additions and 7 deletions.
32 changes: 32 additions & 0 deletions R/layout-stack-build.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,44 @@ stack_build_composer.StackLayout <- function(stack, schemes, theme,
# layout.
#
# this occurs in the annotation stack (`position` is not `NULL`).
#
# here is the example:
# p1 <- ggplot(mtcars) +
# geom_point(aes(mpg, disp))
# p2 <- ggplot(mtcars) +
# geom_boxplot(aes(gear, disp, group = gear, fill = gear))
# p3 <- ggplot(mtcars) +
# geom_bar(aes(gear)) +
# facet_wrap(~cyl)
# align_plots(
# free_space(free_border(
# align_plots(
# # we shouldn't add free_space for the internal plot
# free_space(
# free_border(
# p1 + scale_y_continuous(
# expand = expansion(),
# labels = ~ paste("very very long labels", .x)
# ),
# "l"
# ),
# "l"
# ),
# p2 + theme(legend.position = "left"),
# guides = "l"
# ),
# "l"
# ), "l"),
# p3 + theme(plot.margin = margin(l = 5, unit = "cm")),
# ncol = 1
# )
stack_spaces <- .subset2(.subset2(schemes, "scheme_align"), "free_spaces")
if (is_string(stack_spaces) && !is.null(position)) {
released_spaces <- stack_spaces
} else {
released_spaces <- NULL
}

coords <- setup_layout_coords(stack@layout)
stack_composer_add(
plot_list,
Expand Down
3 changes: 2 additions & 1 deletion R/layout-stack-composer.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ stack_composer_add.ggalign_plot <- function(plot, composer, ...,
plot_schemes$scheme_align["free_spaces"] <- list(plot_spaces)
}
}
plot <- plot_build(plot = plot, ..., schemes = schemes) + theme_recycle()
plot <- plot_build(plot = plot, ..., schemes = plot_schemes) +
theme_recycle()
stack_composer_align_plot(composer, plot, size)
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/layout_quad.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Cannot add `align_kmeans(3L)` to `quad_free()`
i `quad_free()` cannot align observations in horizontal direction

# add `stack_layout()` builds well
# add `stack_layout()` works well

Cannot add `stack_freev()` to `quad_free()`
i no active annotation stack
Expand Down
Loading

0 comments on commit f05279f

Please sign in to comment.