Skip to content

Commit c87c36d

Browse files
teunbrandthomasp85
authored andcommitted
Missing Scale$get_transformation() (#5607)
* Use `Scale$get_transformation()` more * Only inverse transform is there is an actual transform
1 parent fa24e40 commit c87c36d

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

R/axis-secondary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
179179
}
180180
if (is.derived(self$name) && !is.waive(scale$name)) self$name <- scale$name
181181
if (is.derived(self$breaks)) self$breaks <- scale$breaks
182-
if (is.waive(self$breaks)) self$breaks <- scale$transformation$breaks
182+
if (is.waive(self$breaks)) self$breaks <- scale$get_transformation()$breaks
183183
if (is.derived(self$labels)) self$labels <- scale$labels
184184
if (is.derived(self$guide)) self$guide <- scale$guide
185185
},

R/guide-axis-logticks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ GuideAxisLogticks <- ggproto(
149149

150150
# Reconstruct a transformation if user has prescaled data
151151
if (!is.null(params$prescale_base)) {
152-
trans_name <- scale$scale$transformation$name
152+
trans_name <- scale$get_transformation()$name
153153
if (trans_name != "identity") {
154154
cli::cli_warn(paste0(
155155
"The {.arg prescale_base} argument will override the scale's ",

R/scale-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ check_breaks_labels <- function(breaks, labels, call = NULL) {
609609
default_transform <- function(self, x) {
610610
transformation <- self$get_transformation()
611611
new_x <- transformation$transform(x)
612-
check_transformation(x, new_x, self$transformation$name, call = self$call)
612+
check_transformation(x, new_x, transformation$name, call = self$call)
613613
new_x
614614
}
615615

R/scales-.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ ScalesList <- ggproto("ScalesList", NULL,
8989
# If the scale contains to trans or trans is identity, there is no need
9090
# to transform anything
9191
idx_skip <- vapply(self$scales, function(x) {
92+
transformation <- x$get_transformation()
9293
has_default_transform(x) &&
93-
(is.null(x$transformation) || identical(x$transformation$transform, identity))
94+
(is.null(transformation) || identical(transformation$transform, identity))
9495
}, logical(1L))
9596
scales <- self$scales[!idx_skip]
9697

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

@@ -129,7 +131,11 @@ ScalesList <- ggproto("ScalesList", NULL,
129131
if (length(aesthetics) == 0) {
130132
return()
131133
}
132-
lapply(df[aesthetics], scale$transformation$inverse)
134+
inverse <- scale$get_transformation()$inverse
135+
if (is.null(inverse)) {
136+
return()
137+
}
138+
lapply(df[aesthetics], inverse)
133139
}
134140
), recursive = FALSE)
135141

R/stat-function.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ StatFunction <- ggproto("StatFunction", Stat,
6666
} else {
6767
# For continuous scales, need to back transform from transformed range
6868
# to original values
69-
x_trans <- scales$x$transformation$inverse(xseq)
69+
x_trans <- scales$x$get_transformation()$inverse(xseq)
7070
}
7171
}
7272

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

8181
data_frame0(x = xseq, y = y_out)

0 commit comments

Comments
 (0)