25
25
# ' The `r link_book("build step section", "internals#sec-ggplotbuild")`
26
26
# ' @keywords internal
27
27
# ' @export
28
- build_ggplot <- S7 :: new_generic( " build_ggplot " , " plot " , fun = function (plot , ... ) {
28
+ ggplot_build <- function (plot , ... ) {
29
29
env <- try_prop(plot , " plot_env" )
30
30
if (! is.null(env )) {
31
31
attach_plot_env(env )
32
32
}
33
- S7 :: S7_dispatch( )
34
- })
33
+ UseMethod( " ggplot_build " )
34
+ }
35
35
36
- S7 :: method(build_ggplot , class_ggplot_built ) <- function (plot , ... ) {
36
+ S7 :: method(ggplot_build , class_ggplot_built ) <- function (plot , ... ) {
37
37
plot # This is a no-op
38
38
}
39
39
40
- S7 :: method(build_ggplot , class_ggplot ) <- function (plot , ... ) {
40
+ S7 :: method(ggplot_build , class_ggplot ) <- function (plot , ... ) {
41
41
plot <- plot_clone(plot )
42
42
if (length(plot @ layers ) == 0 ) {
43
43
plot <- plot + geom_blank()
@@ -136,29 +136,17 @@ S7::method(build_ggplot, class_ggplot) <- function(plot, ...) {
136
136
build
137
137
}
138
138
139
- # TODO: the S3 generic should be phased out once S7 is adopted more widely
140
- # ' @rdname build_ggplot
141
- # ' @export
142
- ggplot_build <- function (plot , ... ) {
143
- UseMethod(" ggplot_build" )
144
- }
145
-
146
- # ' @export
147
- ggplot_build.default <- function (plot , ... ) {
148
- build_ggplot(plot )
149
- }
150
-
151
139
# ' @export
152
- # ' @rdname build_ggplot
140
+ # ' @rdname ggplot_build
153
141
get_layer_data <- function (plot = get_last_plot(), i = 1L ) {
154
142
ggplot_build(plot )@ data [[i ]]
155
143
}
156
144
# ' @export
157
- # ' @rdname build_ggplot
145
+ # ' @rdname ggplot_build
158
146
layer_data <- get_layer_data
159
147
160
148
# ' @export
161
- # ' @rdname build_ggplot
149
+ # ' @rdname ggplot_build
162
150
get_panel_scales <- function (plot = get_last_plot(), i = 1L , j = 1L ) {
163
151
b <- ggplot_build(plot )
164
152
@@ -172,19 +160,19 @@ get_panel_scales <- function(plot = get_last_plot(), i = 1L, j = 1L) {
172
160
}
173
161
174
162
# ' @export
175
- # ' @rdname build_ggplot
163
+ # ' @rdname ggplot_build
176
164
layer_scales <- get_panel_scales
177
165
178
166
# ' @export
179
- # ' @rdname build_ggplot
167
+ # ' @rdname ggplot_build
180
168
get_layer_grob <- function (plot = get_last_plot(), i = 1L ) {
181
169
b <- ggplot_build(plot )
182
170
183
171
b @ plot @ layers [[i ]]$ draw_geom(b @ data [[i ]], b @ layout )
184
172
}
185
173
186
174
# ' @export
187
- # ' @rdname build_ggplot
175
+ # ' @rdname ggplot_build
188
176
layer_grob <- get_layer_grob
189
177
190
178
# ' Build a plot with all the usual bits and pieces.
0 commit comments