Skip to content

Commit

Permalink
fix layout_name not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Dec 17, 2024
1 parent dbc705d commit e741b86
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions R/align-.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ Align <- ggproto("Align", AlignProto,
self$extra_params
)
},
layout = function(self, layout_data, layout_coords, layout_name) {
layout = function(self, layout_data, layout_coords) {
input_data <- .subset2(self, "input_data")
input_params <- .subset2(self, "input_params")
object_name <- .subset2(self, "object_name")
layout_name <- .subset2(self, "layout_name")
call <- .subset2(self, "call")
layout_panel <- .subset2(layout_coords, "panel")
layout_index <- .subset2(layout_coords, "index")
Expand Down Expand Up @@ -331,11 +332,11 @@ Align <- ggproto("Align", AlignProto,
plot + switch_direction(
direction,
list(
cartesian_coord("y"),
cartesian_coord("y", self$layout_name),
discrete_ggalign(y = coords)
),
list(
cartesian_coord("x"),
cartesian_coord("x", self$layout_name),
discrete_ggalign(x = coords)
)
)
Expand Down
4 changes: 2 additions & 2 deletions R/cross-.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ summary.Cross <- function(object, ...) c(TRUE, FALSE)
#' @importFrom ggplot2 ggproto ggplot
#' @include plot-.R
Cross <- ggproto("Cross", AlignProto,
layout = function(self, layout_data, layout_coords, layout_name) {
layout = function(self, layout_data, layout_coords) {
if (is.null(.subset2(layout_coords, "nobs"))) {
cli_abort(sprintf(
"layout observations for %s must be initialized before adding {.var {%s}}",
layout_name, .subset2(self, "object_name")
.subset2(self, "layout_name"), .subset2(self, "object_name")
))
}
# we keep the names from the layout data for usage
Expand Down
4 changes: 2 additions & 2 deletions R/cross-gg.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ CrossGg <- ggproto("CrossGg", Cross,
}
plot$data <- data
if (is_horizontal(direction)) {
default_coord <- cartesian_coord("y")
default_coord <- cartesian_coord("y", self$layout_name)
default_align <- discrete_ggalign(y = coords)
default_expand <- default_expansion(x = expansion())
} else {
default_coord <- cartesian_coord("x")
default_coord <- cartesian_coord("x", self$layout_name)
default_expand <- default_expansion(y = expansion())
default_align <- discrete_ggalign(x = coords)
}
Expand Down
2 changes: 1 addition & 1 deletion R/free-gg.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ new_free_gg <- function(plot, data, size, active,

#' @importFrom ggplot2 ggproto
FreeGg <- ggproto("FreeGg", Free,
layout = function(self, layout_data, layout_coords, layout_name) {
layout = function(self, layout_data, layout_coords) {
if (is.waive(input_data <- self$input_data)) { # inherit from the layout
data <- layout_data
} else if (is.function(input_data)) {
Expand Down
1 change: 1 addition & 0 deletions R/ggplot-discrete.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ setup_limits <- function(axis, params) {
ggplot_add.discrete_ggalign <- function(object, plot, object_name) {
x_params <- .subset2(object, "x")
y_params <- .subset2(object, "y")
if (is.null(x_params) && is.null(y_params)) return(plot)

# we will set limits by default
if (!is.null(x_params) && (.subset2(x_params, "limits") %||% TRUE)) {
Expand Down
2 changes: 1 addition & 1 deletion R/layout-quad-build.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ quad_build.QuadLayout <- function(quad, schemes = NULL, theme = NULL,
if (length(aligned_axes)) {
p <- p +
align_melt_facet(default_facet, p$facet, strict = TRUE) +
cartesian_coord(aligned_axes) +
cartesian_coord(aligned_axes, object_name(quad)) +
discrete_ggalign(x = column_coords, y = row_coords)
}
p <- p + theme_recycle()
Expand Down
6 changes: 3 additions & 3 deletions R/plot-.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ AlignProto <- ggproto("AlignProto",

############################################################
# when added to the `Layout` object, will call following methods
layout = function(self, layout_data, layout_coords, layout_name) {
layout = function(self, layout_data, layout_coords) {
layout_coords
},
setup_plot = function(self, plot) plot,
Expand Down Expand Up @@ -215,13 +215,13 @@ stack_layout_add.ggalign_plot <- function(object, stack, object_name) {
align$direction <- stack@direction
align$position <- .subset2(stack@heatmap, "position")
align$object_name <- object_name
align$layout_name <- object_name(stack)

# this step, the object will act with the stack layout
# group rows into panel or reorder rows
new_coords <- align$layout(
layout_data = stack@data, # must be a matrix
layout_coords = old_coords,
layout_name = object_name(stack)
layout_coords = old_coords
)

# initialize the plot object
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/layout-align.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@

# `ggalign()` works well

Currently, `coord_polar()` is not supported
`coord_polar()` is not supported in the top annotation `stack_align()`
i Will use `coord_cartesian()` instead

0 comments on commit e741b86

Please sign in to comment.