@@ -53,3 +53,54 @@ update_stat_defaults <- function(stat, new) {
5353 g $ default_aes [names(new )] <- new
5454 invisible ()
5555}
56+
57+ # ' Resolve and get geom defaults
58+ # '
59+ # ' @param geom Some definition of a geom:
60+ # ' * A `function` that creates a layer, e.g. `geom_path()`.
61+ # ' * A layer created by such function
62+ # ' * A string naming a geom class in snake case without the `geom_`-prefix,
63+ # ' e.g. `"contour_filled"`.
64+ # ' * A geom class object.
65+ # ' @param theme A [`theme`] object. Defaults to the current global theme.
66+ # '
67+ # ' @return A list of aesthetics
68+ # ' @export
69+ # ' @keywords internal
70+ # '
71+ # ' @examples
72+ # ' # Using a function
73+ # ' get_geom_defaults(geom_raster)
74+ # '
75+ # ' # Using a layer includes static aesthetics as default
76+ # ' get_geom_defaults(geom_tile(fill = "white"))
77+ # '
78+ # ' # Using a class name
79+ # ' get_geom_defaults("density_2d")
80+ # '
81+ # ' # Using a class
82+ # ' get_geom_defaults(GeomPoint)
83+ # '
84+ # ' # Changed theme
85+ # ' get_geom_defaults("point", theme(geom = element_geom(ink = "purple")))
86+ get_geom_defaults <- function (geom , theme = theme_get()) {
87+ theme <- theme %|| % list (geom = .default_geom_element )
88+
89+ if (is.function(geom )) {
90+ geom <- geom()
91+ }
92+ if (is.layer(geom )) {
93+ data <- data_frame0(.id = 1L )
94+ data <- geom $ compute_geom_2(data = data )
95+ data $ .id <- NULL
96+ return (data )
97+ }
98+ if (is.character(geom )) {
99+ geom <- check_subclass(geom , " Geom" )
100+ }
101+ if (inherits(geom , " Geom" )) {
102+ out <- geom $ use_defaults(data = NULL )
103+ return (out )
104+ }
105+ stop_input_type(geom , as_cli(" a layer function, string or {.cls Geom} object" ))
106+ }
0 commit comments