Skip to content

Missing Scale$get_transformation() #5607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
}
if (is.derived(self$name) && !is.waive(scale$name)) self$name <- scale$name
if (is.derived(self$breaks)) self$breaks <- scale$breaks
if (is.waive(self$breaks)) self$breaks <- scale$transformation$breaks
if (is.waive(self$breaks)) self$breaks <- scale$get_transformation()$breaks
if (is.derived(self$labels)) self$labels <- scale$labels
if (is.derived(self$guide)) self$guide <- scale$guide
},
Expand Down
2 changes: 1 addition & 1 deletion R/guide-axis-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ GuideAxisLogticks <- ggproto(

# Reconstruct a transformation if user has prescaled data
if (!is.null(params$prescale_base)) {
trans_name <- scale$scale$transformation$name
trans_name <- scale$get_transformation()$name
if (trans_name != "identity") {
cli::cli_warn(paste0(
"The {.arg prescale_base} argument will override the scale's ",
Expand Down
2 changes: 1 addition & 1 deletion R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ check_breaks_labels <- function(breaks, labels, call = NULL) {
default_transform <- function(self, x) {
transformation <- self$get_transformation()
new_x <- transformation$transform(x)
check_transformation(x, new_x, self$transformation$name, call = self$call)
check_transformation(x, new_x, transformation$name, call = self$call)
new_x
}

Expand Down
12 changes: 9 additions & 3 deletions R/scales-.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ ScalesList <- ggproto("ScalesList", NULL,
# If the scale contains to trans or trans is identity, there is no need
# to transform anything
idx_skip <- vapply(self$scales, function(x) {
transformation <- x$get_transformation()
has_default_transform(x) &&
(is.null(x$transformation) || identical(x$transformation$transform, identity))
(is.null(transformation) || identical(transformation$transform, identity))
}, logical(1L))
scales <- self$scales[!idx_skip]

Expand All @@ -113,8 +114,9 @@ ScalesList <- ggproto("ScalesList", NULL,
# If the scale contains to trans or trans is identity, there is no need
# to transform anything
idx_skip <- vapply(self$scales, function(x) {
transformation <- x$get_transformation()
has_default_transform(x) &&
(is.null(x$transformation) || identical(x$transformation$transform, identity))
(is.null(transformation) || identical(transformation$transform, identity))
}, logical(1))
scales <- self$scales[!idx_skip]

Expand All @@ -129,7 +131,11 @@ ScalesList <- ggproto("ScalesList", NULL,
if (length(aesthetics) == 0) {
return()
}
lapply(df[aesthetics], scale$transformation$inverse)
inverse <- scale$get_transformation()$inverse
if (is.null(inverse)) {
return()
}
lapply(df[aesthetics], inverse)
}
), recursive = FALSE)

Expand Down
4 changes: 2 additions & 2 deletions R/stat-function.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ StatFunction <- ggproto("StatFunction", Stat,
} else {
# For continuous scales, need to back transform from transformed range
# to original values
x_trans <- scales$x$transformation$inverse(xseq)
x_trans <- scales$x$get_transformation()$inverse(xseq)
}
}

Expand All @@ -75,7 +75,7 @@ StatFunction <- ggproto("StatFunction", Stat,
y_out <- inject(fun(x_trans, !!!args))
if (!is.null(scales$y) && !scales$y$is_discrete()) {
# For continuous scales, need to apply transform
y_out <- scales$y$transformation$transform(y_out)
y_out <- scales$y$get_transformation()$transform(y_out)
}

data_frame0(x = xseq, y = y_out)
Expand Down