Skip to content

Switch to scales::Range classes #5086

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 9 commits into from
Feb 21, 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
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Collate:
'position-nudge.R'
'position-stack.r'
'quick-plot.r'
'range.r'
'reshape-add-margins.R'
'save.r'
'scale-.r'
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* ggplot2 now uses `scales::DiscreteRange` and `scales::ContinuousRange`, which
are available to write scale extensions from scratch (@teunbrand, #2710).
* For the purposes of checking required or non-missing aesthetics, character
vectors are no longer considered non-finite (@teunbrand, @4284).
* Fixed bug in `coord_sf()` where graticule lines didn't obey
Expand Down
33 changes: 0 additions & 33 deletions R/range.r

This file was deleted.

18 changes: 9 additions & 9 deletions R/scale-.r
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ continuous_scale <- function(aesthetics, scale_name, palette, name = waiver(),
scale_name = scale_name,
palette = palette,

range = continuous_range(),
range = ContinuousRange$new(),
limits = limits,
trans = trans,
na.value = na.value,
Expand Down Expand Up @@ -211,7 +211,7 @@ discrete_scale <- function(aesthetics, scale_name, palette, name = waiver(),
scale_name = scale_name,
palette = palette,

range = discrete_range(),
range = DiscreteRange$new(),
limits = limits,
na.value = na.value,
na.translate = na.translate,
Expand Down Expand Up @@ -280,7 +280,7 @@ binned_scale <- function(aesthetics, scale_name, palette, name = waiver(),
scale_name = scale_name,
palette = palette,

range = continuous_range(),
range = ContinuousRange$new(),
limits = limits,
trans = trans,
na.value = na.value,
Expand Down Expand Up @@ -406,7 +406,7 @@ Scale <- ggproto("Scale", NULL,
cli::cli_abort("Not implemented")
},

range = ggproto(NULL, Range),
range = Range$new(),
limits = NULL,
na.value = NA,
expand = waiver(),
Expand Down Expand Up @@ -580,7 +580,7 @@ has_default_transform <- function(scale) {
#' @usage NULL
#' @export
ScaleContinuous <- ggproto("ScaleContinuous", Scale,
range = continuous_range(),
range = ContinuousRange$new(),
na.value = NA_real_,
rescaler = rescale,
oob = censor,
Expand Down Expand Up @@ -763,7 +763,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,

clone = function(self) {
new <- ggproto(NULL, self)
new$range <- continuous_range()
new$range <- ContinuousRange$new()
new
},

Expand Down Expand Up @@ -951,7 +951,7 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,

clone = function(self) {
new <- ggproto(NULL, self)
new$range <- discrete_range()
new$range <- DiscreteRange$new()
new
},

Expand Down Expand Up @@ -989,7 +989,7 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
#' @usage NULL
#' @export
ScaleBinned <- ggproto("ScaleBinned", Scale,
range = continuous_range(),
range = ContinuousRange$new(),
na.value = NA_real_,
rescaler = rescale,
oob = squish,
Expand Down Expand Up @@ -1155,7 +1155,7 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,

clone = function(self) {
new <- ggproto(NULL, self)
new$range <- continuous_range()
new$range <- ContinuousRange$new()
new
},

Expand Down
8 changes: 4 additions & 4 deletions R/scale-discrete-.r
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ scale_x_discrete <- function(..., expand = waiver(), guide = waiver(), position
sc <- discrete_scale(c("x", "xmin", "xmax", "xend"), "position_d", identity, ...,
expand = expand, guide = guide, position = position, super = ScaleDiscretePosition)

sc$range_c <- continuous_range()
sc$range_c <- ContinuousRange$new()
sc
}
#' @rdname scale_discrete
Expand All @@ -72,7 +72,7 @@ scale_y_discrete <- function(..., expand = waiver(), guide = waiver(), position
sc <- discrete_scale(c("y", "ymin", "ymax", "yend"), "position_d", identity, ...,
expand = expand, guide = guide, position = position, super = ScaleDiscretePosition)

sc$range_c <- continuous_range()
sc$range_c <- ContinuousRange$new()
sc
}

Expand Down Expand Up @@ -135,8 +135,8 @@ ScaleDiscretePosition <- ggproto("ScaleDiscretePosition", ScaleDiscrete,

clone = function(self) {
new <- ggproto(NULL, self)
new$range <- discrete_range()
new$range_c <- continuous_range()
new$range <- DiscreteRange$new()
new$range_c <- ContinuousRange$new()
new
}
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-range.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("continuous ranges expand as expected", {
r <- continuous_range()
r <- ContinuousRange$new()

r$train(1)
expect_equal(r$range, c(1, 1))
Expand All @@ -9,7 +9,7 @@ test_that("continuous ranges expand as expected", {
})

test_that("discrete ranges expand as expected", {
r <- discrete_range()
r <- DiscreteRange$new()

r$train("a")
expect_equal(r$range, "a")
Expand Down