Skip to content

Commit 68fe80b

Browse files
committed
move element properties
1 parent 360c975 commit 68fe80b

File tree

2 files changed

+28
-64
lines changed

2 files changed

+28
-64
lines changed

R/properties.R

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
property_boolean <- function(allow_null = FALSE, default = TRUE) {
32
class <- S7::class_logical
43
class <- if (allow_null) S7::new_union(class, NULL) else class
@@ -38,65 +37,9 @@ property_choice <- function(options, allow_null = FALSE, default = NULL) {
3837
)
3938
}
4039

41-
element_props <- list(
42-
fill = S7::new_property(
43-
S7::new_union(S7::class_character, S7::new_S3_class("GridPattern"), S7::class_logical, NULL),
44-
default = NULL
45-
),
46-
colour = S7::new_property(
47-
S7::new_union(S7::class_character, S7::class_logical, NULL),
48-
default = NULL
49-
),
50-
family = S7::new_property(
51-
S7::new_union(S7::class_character, NULL),
52-
default = NULL
53-
),
54-
hjust = S7::new_property(
55-
S7::new_union(S7::class_numeric, NULL),
56-
default = NULL
57-
),
58-
vjust = S7::new_property(
59-
S7::new_union(S7::class_numeric, NULL),
60-
default = NULL
61-
),
62-
angle = S7::new_property(
63-
S7::new_union(S7::class_numeric, NULL),
64-
default = NULL
65-
),
66-
size = S7::new_property(
67-
S7::new_union(S7::class_numeric, NULL),
68-
default = NULL
69-
),
70-
lineheight = S7::new_property(
71-
S7::new_union(S7::class_numeric, NULL),
72-
default = NULL
73-
),
74-
margin = S7::new_property(
75-
S7::new_union(S7::new_S3_class("margin"), NULL),
76-
default = NULL
77-
),
78-
face = property_choice(c("plain", "bold", "italic", "oblique", "bold.italic"), allow_null = TRUE),
79-
linewidth = S7::new_property(
80-
S7::new_union(S7::class_numeric, NULL),
81-
default = NULL
82-
),
83-
linetype = S7::new_property(
84-
S7::new_union(S7::class_numeric, S7::class_character, NULL),
85-
default = NULL
86-
),
87-
lineend = property_choice(c("round", "butt", "square"), allow_null = TRUE),
88-
shape = S7::new_property(
89-
S7::new_union(S7::class_numeric, S7::class_character, NULL),
90-
default = NULL
91-
),
92-
arrow = S7::new_property(
93-
S7::new_union(S7::new_S3_class("arrow"), S7::class_logical, NULL),
94-
default = NULL
95-
),
96-
arrow.fill = S7::new_property(
97-
S7::new_union(S7::class_character, S7::class_logical, NULL),
98-
default = NULL
99-
),
100-
debug = property_boolean(allow_null = TRUE, default = NULL),
101-
inherit.blank = property_boolean(default = FALSE)
102-
)
40+
property_nullable <- function(class = S7::class_any, ...) {
41+
S7::new_property(
42+
class = S7::new_union(NULL, class),
43+
...
44+
)
45+
}

R/theme-elements.R

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,28 @@ element <- S7::new_class("element", abstract = TRUE)
8787
#' @rdname element
8888
element_blank <- S7::new_class("element_blank", parent = element)
8989

90-
#' @include properties.R
90+
# All properties are listed here so they can easily be recycled in the different
91+
# element classes
92+
element_props <- list(
93+
fill = property_nullable(S7::class_character | S7::new_S3_class("GridPattern") | S7::class_logical),
94+
colour = property_nullable(S7::class_character | S7::class_logical),
95+
family = property_nullable(S7::class_character),
96+
hjust = property_nullable(S7::class_numeric),
97+
vjust = property_nullable(S7::class_numeric),
98+
angle = property_nullable(S7::class_numeric),
99+
size = property_nullable(S7::class_numeric),
100+
lineheight = property_nullable(S7::class_numeric),
101+
margin = property_nullable(margin),
102+
face = property_choice(c("plain", "bold", "italic", "oblique", "bold.italic"), allow_null = TRUE),
103+
linewidth = property_nullable(S7::class_numeric),
104+
linetype = property_nullable(S7::class_numeric | S7::class_character),
105+
lineend = property_choice(c("round", "butt", "square"), allow_null = TRUE),
106+
shape = property_nullable(S7::class_numeric | S7::class_character),
107+
arrow = property_nullable(S7::new_S3_class("arrow") | S7::class_logical),
108+
arrow.fill = property_nullable(S7::class_character | S7::class_logical),
109+
debug = property_boolean(allow_null = TRUE, default = NULL),
110+
inherit.blank = property_boolean(default = FALSE)
111+
)
91112

92113
#' @export
93114
#' @rdname element

0 commit comments

Comments
 (0)