Skip to content

Commit 358325d

Browse files
authored
Revert renaming Scale$trans to Scale$transformation (#5626)
* revert renaming `Scale$trans` to `Scale$transformation` * use `get_transformation()` more consistently * use `get_transformation()` for y in function stat
1 parent 78125e0 commit 358325d

9 files changed

+28
-33
lines changed

NEWS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ vectors interact with the scale system, namely: not at all.
5353
* The `trans` argument in scales and secondary axes has been renamed to
5454
`transform`. The `trans` argument itself is deprecated. To access the
5555
transformation from the scale, a new `get_transformation()` method is
56-
added to Scale-classes that retrieves the transformation object from the
57-
new `Scale$transformation` field (#5558).
56+
added to Scale-classes (#5558).
5857

5958
* Providing a numeric vector to `theme(legend.position)` has been deprecated.
6059
To set the default legend position inside the plot use

R/axis-secondary.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ sec_axis <- function(transform = NULL,
109109

110110
transform <- as_function(transform)
111111
ggproto(NULL, AxisSecondary,
112-
transform = transform,
112+
trans = transform,
113113
name = name,
114114
breaks = breaks,
115115
labels = labels,
@@ -153,7 +153,7 @@ is.derived <- function(x) {
153153
#' @usage NULL
154154
#' @export
155155
AxisSecondary <- ggproto("AxisSecondary", NULL,
156-
transform = NULL,
156+
trans = NULL,
157157
axis = NULL,
158158
name = waiver(),
159159
breaks = waiver(),
@@ -165,15 +165,15 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
165165
detail = 1000,
166166

167167
empty = function(self) {
168-
is.null(self$transform %||% self$trans)
168+
is.null(self$trans)
169169
},
170170

171171
# Inherit settings from the primary axis/scale
172172
init = function(self, scale) {
173173
if (self$empty()) {
174174
return()
175175
}
176-
transform <- self$transform %||% self$trans
176+
transform <- self$trans
177177
if (!is.function(transform)) {
178178
cli::cli_abort("Transformation for secondary axes must be a function.")
179179
}
@@ -185,7 +185,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
185185
},
186186

187187
transform_range = function(self, range) {
188-
self$transform(range)
188+
self$trans(range)
189189
},
190190

191191
mono_test = function(self, scale){
@@ -299,7 +299,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
299299
labels = self$labels,
300300
limits = range,
301301
expand = c(0, 0),
302-
transformation = transformation
302+
trans = transformation
303303
)
304304
scale$train(range)
305305
scale

R/scale-.R

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
143143

144144
range = ContinuousRange$new(),
145145
limits = limits,
146-
transformation = transform,
146+
trans = transform,
147147
na.value = na.value,
148148
expand = expand,
149149
rescaler = rescaler,
@@ -313,7 +313,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
313313

314314
range = ContinuousRange$new(),
315315
limits = limits,
316-
transformation = transform,
316+
trans = transform,
317317
na.value = na.value,
318318
expand = expand,
319319
rescaler = rescaler,
@@ -356,7 +356,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
356356
#' - `clone()` Returns a copy of the scale that can be trained
357357
#' independently without affecting the original scale.
358358
#'
359-
#' - `transform()` Transforms a vector of values using `self$transformation`.
359+
#' - `transform()` Transforms a vector of values using `self$trans`.
360360
#' This occurs before the `Stat` is calculated.
361361
#'
362362
#' - `train()` Update the `self$range` of observed (transformed) data values with
@@ -386,7 +386,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
386386
#' (`self$range`).
387387
#'
388388
#' - `get_breaks()` Calculates the final scale breaks in transformed data space
389-
#' based on on the combination of `self$breaks`, `self$transformation$breaks()` (for
389+
#' based on on the combination of `self$breaks`, `self$trans$breaks()` (for
390390
#' continuous scales), and `limits`. Breaks outside of `limits` are assigned
391391
#' a value of `NA` (continuous scales) or dropped (discrete scales).
392392
#'
@@ -395,7 +395,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
395395
#'
396396
#' - `get_breaks_minor()` For continuous scales, calculates the final scale minor breaks
397397
#' in transformed data space based on the rescaled `breaks`, the value of `self$minor_breaks`,
398-
#' and the value of `self$transformation$minor_breaks()`. Discrete scales always return `NULL`.
398+
#' and the value of `self$trans$minor_breaks()`. Discrete scales always return `NULL`.
399399
#'
400400
#' - `get_transformation()` Returns the scale's transformation object.
401401
#'
@@ -554,11 +554,7 @@ Scale <- ggproto("Scale", NULL,
554554
},
555555

556556
get_transformation = function(self) {
557-
if (!is.null(self$trans)) {
558-
deprecate_soft0("3.5.0", I("Scale$trans"), I("Scale$transformation"))
559-
return(self$trans)
560-
}
561-
self$transformation
557+
self$trans
562558
},
563559

564560
clone = function(self) {
@@ -629,7 +625,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
629625
oob = censor,
630626
minor_breaks = waiver(),
631627
n.breaks = NULL,
632-
transformation = transform_identity(),
628+
trans = transform_identity(),
633629

634630
is_discrete = function() FALSE,
635631

R/scale-date.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ ScaleContinuousDatetime <- ggproto("ScaleContinuousDatetime", ScaleContinuous,
358358
tz <- attr(x, "tzone")
359359
if (is.null(self$timezone) && !is.null(tz)) {
360360
self$timezone <- tz
361-
self$transformation <- transform_time(self$timezone)
361+
self$trans <- transform_time(self$timezone)
362362
}
363363
ggproto_parent(ScaleContinuous, self)$transform(x)
364364
},

man/ggplot2-ggproto.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-plot-summary-api.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ test_that("layout summary - reversed scales", {
8080
lr <- summarise_layout(ggplot_build(pr))
8181
expect_equal(lr$xmin, -7.27)
8282
expect_equal(lr$xmax, -1.33)
83-
expect_equal(lr$xscale[[1]]$transformation$name, "reverse")
84-
expect_equal(lr$xscale[[1]]$transformation$transform(5), -5)
83+
expect_equal(lr$xscale[[1]]$get_transformation()$name, "reverse")
84+
expect_equal(lr$xscale[[1]]$get_transformation()$transform(5), -5)
8585
})
8686

8787
test_that("layout summary - log scales", {
8888
pl <- p + scale_x_log10() + scale_y_continuous(transform = "log2")
8989
ll <- summarise_layout(ggplot_build(pl))
90-
expect_equal(ll$xscale[[1]]$transformation$name, "log-10")
91-
expect_equal(ll$xscale[[1]]$transformation$transform(100), 2)
92-
expect_equal(ll$yscale[[1]]$transformation$name, "log-2")
93-
expect_equal(ll$yscale[[1]]$transformation$transform(16), 4)
90+
expect_equal(ll$xscale[[1]]$get_transformation()$name, "log-10")
91+
expect_equal(ll$xscale[[1]]$get_transformation()$transform(100), 2)
92+
expect_equal(ll$yscale[[1]]$get_transformation()$name, "log-2")
93+
expect_equal(ll$yscale[[1]]$get_transformation()$transform(16), 4)
9494
})
9595

9696
test_that("coord summary - basic", {

tests/testthat/test-scale-binned.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test_that('binned scales can calculate breaks on dates', {
6565

6666
scale <- scale_x_binned(transform = "date")
6767
scale$train(scale$transform(data))
68-
breaks <- scale$transformation$inverse(scale$get_breaks())
68+
breaks <- scale$get_transformation()$inverse(scale$get_breaks())
6969

7070
expect_s3_class(breaks, "Date")
7171
expect_equal(
@@ -83,7 +83,7 @@ test_that('binned scales can calculate breaks on date-times', {
8383

8484
scale <- scale_x_binned(transform = "time")
8585
scale$train(scale$transform(data))
86-
breaks <- scale$transformation$inverse(scale$get_breaks())
86+
breaks <- scale$get_transformation()$inverse(scale$get_breaks())
8787

8888
expect_s3_class(breaks, "POSIXct")
8989
expect_equal(

tests/testthat/test-scales.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ test_that("numeric scale transforms can produce breaks", {
468468
scale <- scale_x_continuous(transform = transform)
469469
scale$train(scale$transform(limits))
470470
view <- view_scale_primary(scale)
471-
scale$transformation$inverse(view$get_breaks())
471+
scale$get_transformation()$inverse(view$get_breaks())
472472
}
473473

474474
expect_equal(test_breaks("asn", limits = c(0, 1)),

vignettes/extending-ggplot2.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ FacetTrans <- ggproto("FacetTrans", Facet,
864864
if (!is.null(y_scale)) {
865865
y_scale_orig <- y_scale$clone()
866866
y_scale_new <- y_scale$clone()
867-
y_scale_new$transformation <- params$trans
867+
y_scale_new$trans <- params$trans
868868
# Make sure that oob values are kept
869869
y_scale_new$oob <- function(x, ...) x
870870
scales$y <- list(y_scale_orig, y_scale_new)

0 commit comments

Comments
 (0)