forked from JanMarvin/openxlsx2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-color.R
44 lines (37 loc) · 1020 Bytes
/
class-color.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#' Create a new wbColour object
#' @param name A name of a color known to R
#' @param auto A boolean.
#' @param indexed An indexed color values.
#' @param hex A rgb color as ARGB hex value "FF000000".
#' @param theme A zero based index referencing a value in the theme.
#' @param tint A tint value applied. Range from -1 (dark) to 1 (light).
#' @return a `wbColour` object
#' @export
wb_color <- function(
name = NULL,
auto = NULL,
indexed = NULL,
hex = NULL,
theme = NULL,
tint = NULL
) {
if (!is.null(name)) hex <- validate_color(name)
z <- c(
auto = as_xml_attr(auto),
indexed = as_xml_attr(indexed),
rgb = as_xml_attr(hex),
theme = as_xml_attr(theme),
tint = as_xml_attr(tint)
)
z <- z[z != ""]
if (is.null(z))
z <- c(name = "black")
# wbColour for historical reasons
class(z) <- c("character", "wbColour")
z
}
#' @export
#' @rdname wb_color
#' @usage NULL
wb_colour <- wb_color
is_wbColour <- function(x) inherits(x, "wbColour")