Skip to content

Commit 54d564d

Browse files
authored
Amend #6070 (#6381)
* fix radial displacement * include reverse settings in panel parameters * make axis aware of reverse settings * add visual tests for problem
1 parent 8639ee8 commit 54d564d

13 files changed

+305
-30
lines changed

R/coord-cartesian-.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
102102
self$range(panel_params)
103103
},
104104

105-
transform = function(self, data, panel_params) {
106-
reverse <- self$reverse %||% "none"
105+
transform = function(data, panel_params) {
106+
reverse <- panel_params$reverse %||% "none"
107107
x <- panel_params$x[[switch(reverse, xy = , x = "reverse", "rescale")]]
108108
y <- panel_params$y[[switch(reverse, xy = , y = "reverse", "rescale")]]
109109
data <- transform_position(data, x, y)
@@ -113,7 +113,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
113113
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
114114
c(
115115
view_scales_from_scale(scale_x, self$limits$x, params$expand[c(4, 2)]),
116-
view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)])
116+
view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)]),
117+
reverse = self$reverse %||% "none"
117118
)
118119
},
119120

R/coord-radial.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05),
524524
return(list(x = c(0, 1), y = c(0, 1)))
525525
}
526526
arc <- sort(arc)
527+
inner_radius <- sort(inner_radius)
527528

528529
# X and Y position of the sector arc ends
529530
xmax <- 0.5 * sin(arc) + 0.5

R/coord-sf.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
8686
target_crs <- panel_params$crs
8787

8888
# CoordSf doesn't use the viewscale rescaling, so we just flip ranges
89-
reverse <- self$reverse %||% "none"
89+
reverse <- panel_params$reverse %||% "none"
9090
x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x_range)
9191
y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y_range)
9292

@@ -268,7 +268,8 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
268268
y_range = y_range,
269269
crs = params$crs,
270270
default_crs = params$default_crs,
271-
!!!viewscales
271+
!!!viewscales,
272+
reverse = self$reverse %||% "none"
272273
)
273274

274275
# Rescale graticule for panel grid

R/coord-transform.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ CoordTransform <- ggproto(
149149
transform = function(self, data, panel_params) {
150150
# trans_x() and trans_y() needs to keep Inf values because this can be called
151151
# in guide_transform.axis()
152-
reverse <- self$reverse %||% "none"
152+
reverse <- panel_params$reverse %||% "none"
153153
x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x.range)
154154
y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y.range)
155155
trans_x <- function(data) {
@@ -174,7 +174,8 @@ CoordTransform <- ggproto(
174174
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
175175
c(
176176
view_scales_from_scale_with_coord_trans(scale_x, self$limits$x, self$trans$x, params$expand[c(4, 2)]),
177-
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)])
177+
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)]),
178+
reverse = self$reverse %||% "none"
178179
)
179180
},
180181

R/guide-axis.R

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,32 +167,36 @@ GuideAxis <- ggproto(
167167
}
168168

169169
opposite <- setdiff(c("x", "y"), aesthetic)
170-
opposite_value <- if (position %in% c("top", "right")) -Inf else Inf
171170

172-
data_frame(
173-
!!aesthetic := value,
174-
!!opposite := opposite_value
175-
)
171+
data_frame(!!aesthetic := value)
176172
},
177173

178174
transform = function(self, params, coord, panel_params) {
179175
key <- params$key
180176
position <- params$position
181177
check <- FALSE
182178

179+
aesthetic <- names(key)[!grepl("^\\.", names(key))]
180+
ortho <- setdiff(c("x", "y"), params$aesthetic)
181+
override <- switch(position %||% "", bottom = , left = -Inf, Inf)
182+
183+
if (!(panel_params$reverse %||% "none") %in% c("xy", ortho)) {
184+
override <- -override
185+
}
186+
183187
if (!(is.null(position) || nrow(key) == 0)) {
184188
check <- TRUE
185-
aesthetics <- names(key)[!grepl("^\\.", names(key))]
186-
if (!all(c("x", "y") %in% aesthetics)) {
187-
other_aesthetic <- setdiff(c("x", "y"), aesthetics)
188-
override_value <- if (position %in% c("bottom", "left")) -Inf else Inf
189-
key[[other_aesthetic]] <- override_value
189+
if (!all(c("x", "y") %in% aesthetic)) {
190+
key[[ortho]] <- override
190191
}
191192
key <- coord$transform(key, panel_params)
192193
params$key <- key
193194
}
194195

195196
if (!is.null(params$decor)) {
197+
if (!ortho %in% names(params$decor)) {
198+
params$decor[[ortho]] <- override
199+
}
196200
params$decor <- coord_munch(coord, params$decor, panel_params)
197201

198202
if (!coord$is_linear()) {
Lines changed: 61 additions & 0 deletions
Loading
Lines changed: 61 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)