Skip to content

Commit 3bb2df1

Browse files
committed
class alias
1 parent 1f03f49 commit 3bb2df1

File tree

1 file changed

+77
-68
lines changed

1 file changed

+77
-68
lines changed

R/coord-transform.R

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ coord_transform <- function(x = "identity", y = "identity", xlim = NULL, ylim =
9898
if (is.character(x)) x <- as.transform(x)
9999
if (is.character(y)) y <- as.transform(y)
100100

101-
ggproto(NULL, CoordTrans,
102-
trans = list(x = x, y = y),
103-
limits = list(x = xlim, y = ylim),
104-
expand = expand,
105-
clip = clip
101+
ggproto(
102+
NULL, CoordTransform,
103+
trans = list(x = x, y = y),
104+
limits = list(x = xlim, y = ylim),
105+
expand = expand,
106+
clip = clip
106107
)
107108
}
108109

@@ -121,81 +122,89 @@ coord_trans <- function(...) {
121122
#' @format NULL
122123
#' @usage NULL
123124
#' @export
124-
CoordTrans <- ggproto("CoordTrans", Coord,
125-
is_free = function() TRUE,
126-
distance = function(self, x, y, panel_params) {
127-
max_dist <- dist_euclidean(panel_params$x.range, panel_params$y.range)
128-
dist_euclidean(self$trans$x$transform(x), self$trans$y$transform(y)) / max_dist
129-
},
125+
CoordTransform <- ggproto(
126+
"CoordTransform", Coord,
127+
is_free = function() TRUE,
128+
distance = function(self, x, y, panel_params) {
129+
max_dist <- dist_euclidean(panel_params$x.range, panel_params$y.range)
130+
dist_euclidean(self$trans$x$transform(x), self$trans$y$transform(y)) / max_dist
131+
},
130132

131-
backtransform_range = function(self, panel_params) {
132-
list(
133-
x = self$trans$x$inverse(panel_params$x.range),
134-
y = self$trans$y$inverse(panel_params$y.range)
135-
)
136-
},
133+
backtransform_range = function(self, panel_params) {
134+
list(
135+
x = self$trans$x$inverse(panel_params$x.range),
136+
y = self$trans$y$inverse(panel_params$y.range)
137+
)
138+
},
137139

138-
range = function(self, panel_params) {
139-
list(
140-
x = panel_params$x.range,
141-
y = panel_params$y.range
142-
)
143-
},
140+
range = function(self, panel_params) {
141+
list(
142+
x = panel_params$x.range,
143+
y = panel_params$y.range
144+
)
145+
},
144146

145-
transform = function(self, data, panel_params) {
146-
# trans_x() and trans_y() needs to keep Inf values because this can be called
147-
# in guide_transform.axis()
148-
trans_x <- function(data) {
149-
idx <- !is.infinite(data)
150-
data[idx] <- transform_value(self$trans$x, data[idx], panel_params$x.range)
151-
data
152-
}
153-
trans_y <- function(data) {
154-
idx <- !is.infinite(data)
155-
data[idx] <- transform_value(self$trans$y, data[idx], panel_params$y.range)
156-
data
157-
}
147+
transform = function(self, data, panel_params) {
148+
# trans_x() and trans_y() needs to keep Inf values because this can be called
149+
# in guide_transform.axis()
150+
trans_x <- function(data) {
151+
idx <- !is.infinite(data)
152+
data[idx] <- transform_value(self$trans$x, data[idx], panel_params$x.range)
153+
data
154+
}
155+
trans_y <- function(data) {
156+
idx <- !is.infinite(data)
157+
data[idx] <- transform_value(self$trans$y, data[idx], panel_params$y.range)
158+
data
159+
}
158160

159-
new_data <- transform_position(data, trans_x, trans_y)
161+
new_data <- transform_position(data, trans_x, trans_y)
160162

161-
warn_new_infinites(data$x, new_data$x, "x")
162-
warn_new_infinites(data$y, new_data$y, "y")
163+
warn_new_infinites(data$x, new_data$x, "x")
164+
warn_new_infinites(data$y, new_data$y, "y")
163165

164-
transform_position(new_data, squish_infinite, squish_infinite)
165-
},
166+
transform_position(new_data, squish_infinite, squish_infinite)
167+
},
166168

167-
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
168-
c(
169-
view_scales_from_scale_with_coord_trans(scale_x, self$limits$x, self$trans$x, self$expand),
170-
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, self$expand)
171-
)
172-
},
169+
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
170+
c(
171+
view_scales_from_scale_with_coord_trans(scale_x, self$limits$x, self$trans$x, self$expand),
172+
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, self$expand)
173+
)
174+
},
173175

174-
render_bg = function(panel_params, theme) {
175-
guide_grid(
176-
theme,
177-
panel_params$x.minor,
178-
panel_params$x.major,
179-
panel_params$y.minor,
180-
panel_params$y.major
181-
)
182-
},
176+
render_bg = function(panel_params, theme) {
177+
guide_grid(
178+
theme,
179+
panel_params$x.minor,
180+
panel_params$x.major,
181+
panel_params$y.minor,
182+
panel_params$y.major
183+
)
184+
},
183185

184-
render_axis_h = function(panel_params, theme) {
185-
list(
186-
top = panel_guides_grob(panel_params$guides, position = "top", theme = theme),
187-
bottom = panel_guides_grob(panel_params$guides, position = "bottom", theme = theme)
188-
)
189-
},
186+
render_axis_h = function(panel_params, theme) {
187+
list(
188+
top = panel_guides_grob(panel_params$guides, position = "top", theme = theme),
189+
bottom = panel_guides_grob(panel_params$guides, position = "bottom", theme = theme)
190+
)
191+
},
190192

191-
render_axis_v = function(panel_params, theme) {
192-
list(
193-
left = panel_guides_grob(panel_params$guides, position = "left", theme = theme),
194-
right = panel_guides_grob(panel_params$guides, position = "right", theme = theme)
195-
)
196-
}
193+
render_axis_v = function(panel_params, theme) {
194+
list(
195+
left = panel_guides_grob(panel_params$guides, position = "left", theme = theme),
196+
right = panel_guides_grob(panel_params$guides, position = "right", theme = theme)
197+
)
198+
}
197199
)
198200

201+
# TODO: deprecate this some time in the future
202+
#' @rdname ggplot2-ggproto
203+
#' @format NULL
204+
#' @usage NULL
205+
#' @export
206+
CoordTrans <- ggproto("CoordTrans", CoordTransform)
207+
199208
transform_value <- function(trans, value, range) {
200209
if (is.null(value))
201210
return(value)

0 commit comments

Comments
 (0)