Skip to content

Commit f094a43

Browse files
committed
rename range() function of coord to backtransform_range()
1 parent 01155ba commit f094a43

14 files changed

+33
-16
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ggplot2 3.0.0.9000
22

3+
* The function `range()` in `Coord` has been renamed to `backtransform_range()`
4+
to clarify its intended meaning. This affects developers of custom coords. It
5+
may also affect developers of custom geoms that use the `range()` function. That
6+
code should be migrated to use `backtransform_range()` (@clauswilke, breaking change).
7+
38
* `geom_sf()` now respects `lineend`, `linejoin`, and `linemitre` parameters
49
for lines and polygons (@alistaire47, #2826)
510

R/coord-.r

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
#' - `render_bg`: Renders background elements.
1414
#' - `render_axis_h`: Renders the horizontal axes.
1515
#' - `render_axis_v`: Renders the vertical axes.
16-
#' - `range(panel_params)`: Extracts the panel range provided
16+
#' - `backtransform_range(panel_params)`: Extracts the panel range provided
1717
#' in `panel_params` (created by `setup_panel_params()`, see below) and
18-
#' back-transforms to data coordinates. This back-transformation is needed
18+
#' backtransforms to data coordinates. This back-transformation is needed
1919
#' for coords such as `coord_flip()`, `coord_polar()`, `coord_trans()` where
2020
#' the range in the transformed coordinates differs from the range in the
2121
#' untransformed coordinates.
22+
#' - `range`: Deprecated, do not implement. Calls `backtransform_range()`.
2223
#' - `transform`: Transforms x and y coordinates.
2324
#' - `distance`: Calculates distance.
2425
#' - `is_linear`: Returns `TRUE` if the coordinate system is
@@ -84,14 +85,24 @@ Coord <- ggproto("Coord",
8485
# transform range given in transformed coordinates
8586
# back into range in given in (possibly scale-transformed)
8687
# data coordinates
87-
range = function(panel_params) {
88+
backtransform_range = function(panel_params) {
8889
warning(
8990
"range backtransformation not implemented in this coord; plot may be wrong.",
9091
call. = FALSE
9192
)
9293
list(x = panel_params$x.range, y = panel_params$y.range)
9394
},
9495

96+
# deprecated, do not use or reimplement
97+
# kept only for backwards compatibility
98+
range = function(self, panel_params) {
99+
warning(
100+
"function `Coord$range()` is deprecated; use `Coord$backtransform_range()`.",
101+
call. = FALSE
102+
)
103+
self$backtransform_range(panel_params)
104+
},
105+
95106
setup_panel_params = function(scale_x, scale_y, params = list()) {
96107
list()
97108
},

R/coord-cartesian-.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
8383
dist_euclidean(x, y) / max_dist
8484
},
8585

86-
range = function(panel_params) {
86+
backtransform_range = function(panel_params) {
8787
list(x = panel_params$x.range, y = panel_params$y.range)
8888
},
8989

R/coord-flip.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CoordFlip <- ggproto("CoordFlip", CoordCartesian,
4444
CoordCartesian$transform(data, panel_params)
4545
},
4646

47-
range = function(panel_params) {
47+
backtransform_range = function(panel_params) {
4848
list(x = panel_params$y.range, y = panel_params$x.range)
4949
},
5050

R/coord-map.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ CoordMap <- ggproto("CoordMap", Coord,
119119
out
120120
},
121121

122-
range = function(panel_params) {
122+
backtransform_range = function(panel_params) {
123123
# range is stored in data coordinates and doesn't have to be back-transformed
124124
list(x = panel_params$x.range, y = panel_params$y.range)
125125
},

R/coord-munch.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ coord_munch <- function(coord, data, range, segment_length = 0.01) {
1515
if (coord$is_linear()) return(coord$transform(data, range))
1616

1717
# range has theta and r values; get corresponding x and y values
18-
ranges <- coord$range(range)
18+
ranges <- coord$backtransform_range(range)
1919

2020
# Convert any infinite locations into max/min
2121
# Only need to work with x and y because for munching, those are the

R/coord-polar.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
9090
dist_polar(r, theta)
9191
},
9292

93-
range = function(self, panel_params) {
93+
backtransform_range = function(self, panel_params) {
9494
setNames(
9595
list(panel_params$theta.range, panel_params$r.range),
9696
c(self$theta, self$r)

R/coord-transform.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ CoordTrans <- ggproto("CoordTrans", Coord,
119119
dist_euclidean(self$trans$x$transform(x), self$trans$y$transform(y)) / max_dist
120120
},
121121

122-
range = function(self, panel_params) {
122+
backtransform_range = function(self, panel_params) {
123123
list(
124124
x = self$trans$x$inverse(panel_params$x.range),
125125
y = self$trans$y$inverse(panel_params$y.range)

R/geom-abline.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ geom_abline <- function(mapping = NULL, data = NULL,
111111
#' @export
112112
GeomAbline <- ggproto("GeomAbline", Geom,
113113
draw_panel = function(data, panel_params, coord) {
114-
ranges <- coord$range(panel_params)
114+
ranges <- coord$backtransform_range(panel_params)
115115

116116
data$x <- ranges$x[1]
117117
data$xend <- ranges$x[2]

R/geom-hline.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ geom_hline <- function(mapping = NULL, data = NULL,
3737
#' @export
3838
GeomHline <- ggproto("GeomHline", Geom,
3939
draw_panel = function(data, panel_params, coord) {
40-
ranges <- coord$range(panel_params)
40+
ranges <- coord$backtransform_range(panel_params)
4141

4242
data$x <- ranges$x[1]
4343
data$xend <- ranges$x[2]

R/geom-vline.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ geom_vline <- function(mapping = NULL, data = NULL,
3737
#' @export
3838
GeomVline <- ggproto("GeomVline", Geom,
3939
draw_panel = function(data, panel_params, coord) {
40-
ranges <- coord$range(panel_params)
40+
ranges <- coord$backtransform_range(panel_params)
4141

4242
data$x <- data$xintercept
4343
data$xend <- data$xintercept

R/sf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
361361
)
362362
},
363363

364-
range = function(panel_params) {
364+
backtransform_range = function(panel_params) {
365365
list(x = panel_params$x_range, y = panel_params$y_range)
366366
},
367367

R/summarise-plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ summarise_layout = function(p) {
3838
setNames(res, facet_vars)
3939
})
4040

41-
xyranges <- lapply(l$panel_params, l$coord$range)
41+
xyranges <- lapply(l$panel_params, l$coord$backtransform_range)
4242
layout$xmin <- vapply(xyranges, function(xyrange) xyrange$x[[1]], numeric(1))
4343
layout$xmax <- vapply(xyranges, function(xyrange) xyrange$x[[2]], numeric(1))
4444
layout$ymin <- vapply(xyranges, function(xyrange) xyrange$y[[1]], numeric(1))

man/ggplot2-ggproto.Rd

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

0 commit comments

Comments
 (0)