Skip to content

Commit 16dc109

Browse files
Revert coord-polar.r
1 parent 87fffc0 commit 16dc109

File tree

1 file changed

+22
-83
lines changed

1 file changed

+22
-83
lines changed

R/coord-polar.r

Lines changed: 22 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ CoordPolar <- ggproto("CoordPolar", Coord,
105105
},
106106

107107
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
108-
scales <- list(x = scale_x, y = scale_y)
108+
109109
ret <- list(x = list(), y = list())
110110
for (n in c("x", "y")) {
111-
scale <- scales[[n]]
111+
112+
scale <- get(paste0("scale_", n))
112113
limits <- self$limits[[n]]
113114

114115
if (self$theta == n) {
@@ -119,10 +120,6 @@ CoordPolar <- ggproto("CoordPolar", Coord,
119120
range <- expand_limits_scale(scale, expansion, coord_limits = limits)
120121

121122
out <- scale$break_info(range)
122-
123-
ret[[n]]$primary_axis <- view_scale_primary(scale, scale$get_limits(), out$range)
124-
ret[[n]]$secondary_axis <- view_scale_secondary(scale, scale$get_limits(), out$range)
125-
126123
ret[[n]]$range <- out$range
127124
ret[[n]]$major <- out$major_source
128125
ret[[n]]$minor <- out$minor_source
@@ -133,11 +130,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
133130
ret[[n]]$sec.labels <- out$sec.labels
134131
}
135132

136-
details <- list(
137-
x = ret$x$primary_axis,
138-
y = ret$y$primary_axis,
139-
x.sec = ret$x$secondary_axis,
140-
y.sec = ret$y$secondary_axis,
133+
details = list(
141134
x.range = ret$x$range, y.range = ret$y$range,
142135
x.major = ret$x$major, y.major = ret$y$major,
143136
x.minor = ret$x$minor, y.minor = ret$y$minor,
@@ -149,80 +142,18 @@ CoordPolar <- ggproto("CoordPolar", Coord,
149142
)
150143

151144
if (self$theta == "y") {
152-
# replace x to r, and x.foo to r.foo
153-
names(details) <- gsub("x(\\.|$)", "r\\1", names(details))
154-
names(details) <- gsub("y(\\.|$)", "theta\\1", names(details))
145+
names(details) <- gsub("x\\.", "r.", names(details))
146+
names(details) <- gsub("y\\.", "theta.", names(details))
155147
details$r.arrange <- scale_x$axis_order()
156148
} else {
157-
names(details) <- gsub("x(\\.|$)", "theta\\1", names(details))
158-
names(details) <- gsub("y(\\.|$)", "r\\1", names(details))
149+
names(details) <- gsub("x\\.", "theta.", names(details))
150+
names(details) <- gsub("y\\.", "r.", names(details))
159151
details$r.arrange <- scale_y$axis_order()
160152
}
161153

162154
details
163155
},
164156

165-
# TODO: it's not very nice to copy the whole method just to tweak the
166-
# `aesthetics` for r and theta
167-
setup_panel_guides = function(self, panel_params, guides, params = list()) {
168-
aesthetics <- c("r", "theta", "r.sec", "theta.sec")
169-
names(aesthetics) <- aesthetics
170-
171-
# If the panel_params doesn't contain the scale, do not use a guide for that aesthetic
172-
idx <- vapply(aesthetics, function(aesthetic) {
173-
scale <- panel_params[[aesthetic]]
174-
!is.null(scale) && inherits(scale, "ViewScale")
175-
}, logical(1L))
176-
aesthetics <- aesthetics[idx]
177-
178-
# resolve the specified guide from the scale and/or guides
179-
guides <- lapply(aesthetics, function(aesthetic) {
180-
resolve_guide(
181-
aesthetic,
182-
panel_params[[aesthetic]],
183-
guides,
184-
default = guide_axis(),
185-
null = guide_none()
186-
)
187-
})
188-
189-
# resolve the guide definition as a "guide" S3
190-
guides <- lapply(guides, validate_guide)
191-
192-
# if there is an "position" specification in the scale, pass this on to the guide
193-
# ideally, this should be specified in the guide
194-
guides <- lapply(aesthetics, function(aesthetic) {
195-
guide <- guides[[aesthetic]]
196-
scale <- panel_params[[aesthetic]]
197-
# position could be NULL here for an empty scale
198-
guide$position <- guide$position %|W|% scale$position
199-
guide
200-
})
201-
202-
panel_params$guides <- guides
203-
panel_params
204-
},
205-
206-
# TODO: it's not very nice to copy the whole method just to tweak the
207-
# `aesthetics` for r and theta
208-
train_panel_guides = function(self, panel_params, layers, default_mapping, params = list()) {
209-
aesthetics <- c("r", "theta", "r.sec", "theta.sec")
210-
names(aesthetics) <- aesthetics
211-
# If the panel_params doesn't contain the scale, there's no guide for the aesthetic
212-
aesthetics <- intersect(aesthetics, names(panel_params$guides))
213-
214-
panel_params$guides <- lapply(aesthetics, function(aesthetic) {
215-
axis <- strsplit(aesthetic, ".", fixed = TRUE)[[1]][1]
216-
guide <- panel_params$guides[[aesthetic]]
217-
guide <- guide_train(guide, panel_params[[aesthetic]])
218-
guide <- guide_transform(guide, self, panel_params)
219-
guide <- guide_geom(guide, layers, default_mapping)
220-
guide
221-
})
222-
223-
panel_params
224-
},
225-
226157
transform = function(self, data, panel_params) {
227158
data <- rename_data(self, data)
228159

@@ -281,23 +212,23 @@ CoordPolar <- ggproto("CoordPolar", Coord,
281212
element_render(theme, "panel.background"),
282213
if (length(theta) > 0) element_render(
283214
theme, majortheta, name = "angle",
284-
x = c(rbind(0, 0.45 * sin(theta))) + 0.5,
285-
y = c(rbind(0, 0.45 * cos(theta))) + 0.5,
215+
x = vec_interleave(0, 0.45 * sin(theta)) + 0.5,
216+
y = vec_interleave(0, 0.45 * cos(theta)) + 0.5,
286217
id.lengths = rep(2, length(theta)),
287218
default.units = "native"
288219
),
289220
if (length(thetamin) > 0) element_render(
290221
theme, minortheta, name = "angle",
291-
x = c(rbind(0, 0.45 * sin(thetamin))) + 0.5,
292-
y = c(rbind(0, 0.45 * cos(thetamin))) + 0.5,
222+
x = vec_interleave(0, 0.45 * sin(thetamin)) + 0.5,
223+
y = vec_interleave(0, 0.45 * cos(thetamin)) + 0.5,
293224
id.lengths = rep(2, length(thetamin)),
294225
default.units = "native"
295226
),
296227

297228
element_render(
298229
theme, majorr, name = "radius",
299-
x = rep(rfine, each = length(thetafine)) * sin(thetafine) + 0.5,
300-
y = rep(rfine, each = length(thetafine)) * cos(thetafine) + 0.5,
230+
x = rep(rfine, each = length(thetafine)) * rep(sin(thetafine), length(rfine)) + 0.5,
231+
y = rep(rfine, each = length(thetafine)) * rep(cos(thetafine), length(rfine)) + 0.5,
301232
id.lengths = rep(length(thetafine), length(rfine)),
302233
default.units = "native"
303234
)
@@ -375,6 +306,14 @@ CoordPolar <- ggproto("CoordPolar", Coord,
375306
)
376307
},
377308

309+
labels = function(self, labels, panel_params) {
310+
if (self$theta == "y") {
311+
list(x = labels$y, y = labels$x)
312+
} else {
313+
labels
314+
}
315+
},
316+
378317
modify_scales = function(self, scales_x, scales_y) {
379318
if (self$theta != "y")
380319
return()

0 commit comments

Comments
 (0)