Skip to content

Commit

Permalink
On the fly, enforce vanilla positional scales to return on empty vect…
Browse files Browse the repository at this point in the history
…ors from `scale$map(<vec>)`. Fixes resurgence of #33 as seen in #58
  • Loading branch information
jtlandis committed Feb 27, 2024
1 parent 13fee79 commit f04fee5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 16 additions & 5 deletions R/scales-sides-.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,25 @@ NULL
# fun
# }


mod_scale_map_method <- function(scale) {
ggproto(
NULL,
scale,
map = mod_ggproto_fun(scale$map) |>
mod_fun_at(quote(if (length(x)==0) return(x)), 1)
)
}

new_side_pos_scale <- function(scale, side) {
side <- match.arg(side, choices = c("x","y"))
# other <- switch(side, x = "y", y =)
ggproto(
"ggside_scale",
scale,
aesthetics = sprintf("%sside%s", side, scale$aesthetics),
map = mod_ggproto_fun(scale$map) |> mod_fun_at(quote(if (length(x)==0) return(x)), 1)
mod_scale_map_method(
ggproto(
"ggside_scale",
scale,
aesthetics = sprintf("%sside%s", side, scale$aesthetics)
)
)
}

Expand Down
6 changes: 3 additions & 3 deletions R/side-layout-.r
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ new_ggside_layout <- function(layout) {
find_ggside_scales = function(self, data) {
params <- self$facet_params
layout <- self$layout
x_scale <- self$panel_scales_x
y_scale <- self$panel_scales_y
x_scale <- lapply(self$panel_scales_x, mod_scale_map_method)
y_scale <- lapply(self$panel_scales_y, mod_scale_map_method)

if ("y" %in% params$ggside$sides_used &&
is.null(params$ggside$ysidex)) {
Expand Down Expand Up @@ -97,7 +97,7 @@ new_ggside_layout <- function(layout) {
x_scale[side_indx] <- lapply(side_indx, function(i) params$ggside$ysidex$clone())
self$panel_scales_x <- x_scale
}
y_scale <- self$panel_scales_y

if (!is.null(y_scale) && !is.null(params$ggside$xsidey) &&
!any(vapply(y_scale, function(scale) "xsidey" %in% scale$aesthetics, logical(1)))){
side_indx <- layout[layout$PANEL_TYPE=="x",]$SCALE_Y
Expand Down

0 comments on commit f04fee5

Please sign in to comment.