Skip to content

Commit fece790

Browse files
committed
export theme as class
1 parent 07ebce6 commit fece790

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export(check_device)
292292
export(class_ggplot)
293293
export(class_ggplot_built)
294294
export(class_mapping)
295+
export(class_theme)
295296
export(combine_vars)
296297
export(complete_theme)
297298
export(continuous_scale)

R/plot-construction.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ S7::method(`+`, list(class_ggplot, S7::class_any)) <- function(e1, e2) {
6868
add_ggplot(e1, e2, e2name)
6969
}
7070

71-
S7::method(`+`, list(theme, S7::class_any)) <- function(e1, e2) {
71+
S7::method(`+`, list(class_theme, S7::class_any)) <- function(e1, e2) {
7272
e2name <- deparse(substitute(e2, env = caller_env(2)))
7373
add_theme(e1, e2, e2name)
7474
}
@@ -164,7 +164,7 @@ S7::method(ggplot_add, list(class_mapping, class_ggplot)) <-
164164
S7::set_props(plot, mapping = class_mapping(defaults(object, plot@mapping)))
165165
}
166166

167-
S7::method(ggplot_add, list(theme, class_ggplot)) <-
167+
S7::method(ggplot_add, list(class_theme, class_ggplot)) <-
168168
function(object, plot, ...) {
169169
S7::set_props(plot, theme = add_theme(plot@theme, object))
170170
}

R/plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class_ggplot <- S7::new_class(
3030
scales = class_scales_list,
3131
guides = class_guides,
3232
mapping = class_mapping,
33-
theme = theme,
33+
theme = class_theme,
3434
coordinates = class_coord,
3535
facet = class_facet,
3636
layout = class_layout,

R/theme.R

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,25 +549,39 @@ theme <- function(...,
549549
el
550550
})
551551
}
552-
S7::new_object(
553-
elements,
554-
complete = complete,
555-
validate = validate
556-
)
552+
class_theme(elements, complete = complete, validate = validate)
557553
}
558554

559-
theme <- S7::new_class(
555+
#' The theme class
556+
#'
557+
#' The theme class holds information on how non-data elements of the plot
558+
#' should be rendered. The preferred way to construct an object of this class
559+
#' is through the [`theme()`] function.
560+
#'
561+
#' @param elements A named list containing theme elements.
562+
#' @param complete A boolean value stating whether a theme is complete.
563+
#' @param validate A boolean value stating whether a theme should still be
564+
#' validated.
565+
#'
566+
#' @export
567+
class_theme <- S7::new_class(
560568
"theme", S7::new_S3_class("gg"),
561569
properties = list(
562570
complete = S7::class_logical,
563571
validate = S7::class_logical
564572
),
565-
constructor = theme
573+
constructor = function(elements, complete, validate) {
574+
S7::new_object(
575+
elements,
576+
complete = complete,
577+
validate = validate
578+
)
579+
}
566580
)
567581

568582
#' @export
569583
#' @rdname is_tests
570-
is.theme <- function(x) S7::S7_inherits(x, theme)
584+
is.theme <- function(x) S7::S7_inherits(x, class_theme)
571585

572586
# check whether theme is complete
573587
is_theme_complete <- function(x) {

man/class_theme.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)