Skip to content

Revert renaming Scale$trans to Scale$transformation #5626

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
Jan 8, 2024
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
3 changes: 1 addition & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ vectors interact with the scale system, namely: not at all.
* The `trans` argument in scales and secondary axes has been renamed to
`transform`. The `trans` argument itself is deprecated. To access the
transformation from the scale, a new `get_transformation()` method is
added to Scale-classes that retrieves the transformation object from the
new `Scale$transformation` field (#5558).
added to Scale-classes (#5558).

* Providing a numeric vector to `theme(legend.position)` has been deprecated.
To set the default legend position inside the plot use
Expand Down
12 changes: 6 additions & 6 deletions R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ sec_axis <- function(transform = NULL,

transform <- as_function(transform)
ggproto(NULL, AxisSecondary,
transform = transform,
trans = transform,
name = name,
breaks = breaks,
labels = labels,
Expand Down Expand Up @@ -153,7 +153,7 @@ is.derived <- function(x) {
#' @usage NULL
#' @export
AxisSecondary <- ggproto("AxisSecondary", NULL,
transform = NULL,
trans = NULL,
axis = NULL,
name = waiver(),
breaks = waiver(),
Expand All @@ -165,15 +165,15 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
detail = 1000,

empty = function(self) {
is.null(self$transform %||% self$trans)
is.null(self$trans)
},

# Inherit settings from the primary axis/scale
init = function(self, scale) {
if (self$empty()) {
return()
}
transform <- self$transform %||% self$trans
transform <- self$trans
if (!is.function(transform)) {
cli::cli_abort("Transformation for secondary axes must be a function.")
}
Expand All @@ -185,7 +185,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
},

transform_range = function(self, range) {
self$transform(range)
self$trans(range)
},

mono_test = function(self, scale){
Expand Down Expand Up @@ -299,7 +299,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
labels = self$labels,
limits = range,
expand = c(0, 0),
transformation = transformation
trans = transformation
)
scale$train(range)
scale
Expand Down
18 changes: 7 additions & 11 deletions R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam

range = ContinuousRange$new(),
limits = limits,
transformation = transform,
trans = transform,
na.value = na.value,
expand = expand,
rescaler = rescaler,
Expand Down Expand Up @@ -313,7 +313,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =

range = ContinuousRange$new(),
limits = limits,
transformation = transform,
trans = transform,
na.value = na.value,
expand = expand,
rescaler = rescaler,
Expand Down Expand Up @@ -356,7 +356,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
#' - `clone()` Returns a copy of the scale that can be trained
#' independently without affecting the original scale.
#'
#' - `transform()` Transforms a vector of values using `self$transformation`.
#' - `transform()` Transforms a vector of values using `self$trans`.
#' This occurs before the `Stat` is calculated.
#'
#' - `train()` Update the `self$range` of observed (transformed) data values with
Expand Down Expand Up @@ -386,7 +386,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
#' (`self$range`).
#'
#' - `get_breaks()` Calculates the final scale breaks in transformed data space
#' based on on the combination of `self$breaks`, `self$transformation$breaks()` (for
#' based on on the combination of `self$breaks`, `self$trans$breaks()` (for
#' continuous scales), and `limits`. Breaks outside of `limits` are assigned
#' a value of `NA` (continuous scales) or dropped (discrete scales).
#'
Expand All @@ -395,7 +395,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
#'
#' - `get_breaks_minor()` For continuous scales, calculates the final scale minor breaks
#' in transformed data space based on the rescaled `breaks`, the value of `self$minor_breaks`,
#' and the value of `self$transformation$minor_breaks()`. Discrete scales always return `NULL`.
#' and the value of `self$trans$minor_breaks()`. Discrete scales always return `NULL`.
#'
#' - `get_transformation()` Returns the scale's transformation object.
#'
Expand Down Expand Up @@ -554,11 +554,7 @@ Scale <- ggproto("Scale", NULL,
},

get_transformation = function(self) {
if (!is.null(self$trans)) {
deprecate_soft0("3.5.0", I("Scale$trans"), I("Scale$transformation"))
return(self$trans)
}
self$transformation
self$trans
},

clone = function(self) {
Expand Down Expand Up @@ -629,7 +625,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
oob = censor,
minor_breaks = waiver(),
n.breaks = NULL,
transformation = transform_identity(),
trans = transform_identity(),

is_discrete = function() FALSE,

Expand Down
2 changes: 1 addition & 1 deletion R/scale-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ ScaleContinuousDatetime <- ggproto("ScaleContinuousDatetime", ScaleContinuous,
tz <- attr(x, "tzone")
if (is.null(self$timezone) && !is.null(tz)) {
self$timezone <- tz
self$transformation <- transform_time(self$timezone)
self$trans <- transform_time(self$timezone)
}
ggproto_parent(ScaleContinuous, self)$transform(x)
},
Expand Down
6 changes: 3 additions & 3 deletions man/ggplot2-ggproto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tests/testthat/test-plot-summary-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ test_that("layout summary - reversed scales", {
lr <- summarise_layout(ggplot_build(pr))
expect_equal(lr$xmin, -7.27)
expect_equal(lr$xmax, -1.33)
expect_equal(lr$xscale[[1]]$transformation$name, "reverse")
expect_equal(lr$xscale[[1]]$transformation$transform(5), -5)
expect_equal(lr$xscale[[1]]$get_transformation()$name, "reverse")
expect_equal(lr$xscale[[1]]$get_transformation()$transform(5), -5)
})

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

test_that("coord summary - basic", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-scale-binned.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test_that('binned scales can calculate breaks on dates', {

scale <- scale_x_binned(transform = "date")
scale$train(scale$transform(data))
breaks <- scale$transformation$inverse(scale$get_breaks())
breaks <- scale$get_transformation()$inverse(scale$get_breaks())

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

scale <- scale_x_binned(transform = "time")
scale$train(scale$transform(data))
breaks <- scale$transformation$inverse(scale$get_breaks())
breaks <- scale$get_transformation()$inverse(scale$get_breaks())

expect_s3_class(breaks, "POSIXct")
expect_equal(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ test_that("numeric scale transforms can produce breaks", {
scale <- scale_x_continuous(transform = transform)
scale$train(scale$transform(limits))
view <- view_scale_primary(scale)
scale$transformation$inverse(view$get_breaks())
scale$get_transformation()$inverse(view$get_breaks())
}

expect_equal(test_breaks("asn", limits = c(0, 1)),
Expand Down
2 changes: 1 addition & 1 deletion vignettes/extending-ggplot2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ FacetTrans <- ggproto("FacetTrans", Facet,
if (!is.null(y_scale)) {
y_scale_orig <- y_scale$clone()
y_scale_new <- y_scale$clone()
y_scale_new$transformation <- params$trans
y_scale_new$trans <- params$trans
# Make sure that oob values are kept
y_scale_new$oob <- function(x, ...) x
scales$y <- list(y_scale_orig, y_scale_new)
Expand Down