Skip to content

Commit 89b8f4d

Browse files
authored
make sure using the prepared r_axis_inside for all methods (#6412)
* make sure using the prepared `r_axis_inside` for all methods * reduce the code changes * Use `$setup_params()` to prepare `r_axis_inside` * check `r.axis.inside` in the CoordRadial constructor * more direct indicative warning message * accept the test
1 parent 1ae5a90 commit 89b8f4d

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

R/coord-radial.R

+17-18
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ coord_radial <- function(theta = "x",
102102
arc <- switch(reverse, thetar = , theta = rev(arc), arc)
103103

104104
r.axis.inside <- r.axis.inside %||% !(abs(arc[2] - arc[1]) >= 1.999 * pi)
105+
if (isFALSE(r.axis.inside)) {
106+
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, arc)
107+
if (!any(place)) {
108+
cli::cli_warn(c(
109+
"No appropriate placement found for outside {.field r.axis}.",
110+
i = "Will use {.code r.axis.inside = TRUE} instead"
111+
))
112+
r.axis.inside <- TRUE
113+
}
114+
}
105115

106116
inner.radius <- c(inner.radius, 1) * 0.4
107117
inner.radius <- switch(reverse, thetar = , r = rev, identity)(inner.radius)
@@ -453,25 +463,14 @@ CoordRadial <- ggproto("CoordRadial", Coord,
453463

454464
setup_params = function(self, data) {
455465
params <- ggproto_parent(Coord, self)$setup_params(data)
456-
if (!isFALSE(self$r_axis_inside)) {
457-
return(params)
458-
}
459-
460-
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, self$arc)
461-
if (!any(place)) {
462-
cli::cli_warn(c(
463-
"No appropriate placement found for {.arg r_axis_inside}.",
464-
i = "Axis will be placed at panel edge."
465-
))
466-
params$r_axis_inside <- TRUE
467-
return(params)
466+
if (isFALSE(self$r_axis_inside)) {
467+
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, self$arc)
468+
params$r_axis <- if (any(place[c(1, 3)])) "left" else "bottom"
469+
params$fake_arc <- switch(
470+
which(place[c(1, 3, 2, 4)])[1],
471+
c(0, 2), c(1, 3), c(0.5, 2.5), c(1.5, 3.5)
472+
) * pi
468473
}
469-
470-
params$r_axis <- if (any(place[c(1, 3)])) "left" else "bottom"
471-
params$fake_arc <- switch(
472-
which(place[c(1, 3, 2, 4)])[1],
473-
c(0, 2), c(1, 3), c(0.5, 2.5), c(1.5, 3.5)
474-
) * pi
475474
params
476475
}
477476
)

tests/testthat/_snaps/coord-polar.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
---
1111

12-
No appropriate placement found for `r_axis_inside`.
13-
i Axis will be placed at panel edge.
12+
No appropriate placement found for outside r.axis.
13+
i Will use `r.axis.inside = TRUE` instead
1414

1515
# when both x and y are AsIs, they are not transformed
1616

0 commit comments

Comments
 (0)