Skip to content

Commit 6a8cc53

Browse files
authored
Refactor serie assignment in chartgpu_serie function
1 parent b29985d commit 6a8cc53

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

R/options.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@
1616
chartgpu_serie <- function(chart, name, label = NULL, color = NULL, ...) {
1717
stopifnot("`chart` must have been created with `chartgpu`" = inherits(chart, "chartgpu"))
1818
stopifnot("`name` must be of length 1" = length(name) == 1)
19+
serie <- dropNulls(list(name = label, color = color, ...))
20+
if (!is.null(serie$data))
21+
serie$data <- parse_data(unname(serie$data))
1922
idx <- which(chart$x$series_names == name)
23+
if (!is.null(serie$data) & length(idx) < 1) {
24+
if (is.null(serie$type))
25+
serie$type <- "line"
26+
idx <- length(chart$x$series_names) + 1
27+
chart$x$series_names <- c(chart$x$series_names, name)
28+
chart$x$options$series[[idx]] <- list()
29+
}
2030
stopifnot("Serie not found!" = length(idx) == 1)
2131
chart$x$options$series[[idx]] <- modifyList(
2232
x = chart$x$options$series[[idx]],
23-
val = dropNulls(list(name = label, color = color, ...))
33+
val = serie
2434
)
2535
return(chart)
2636
}

0 commit comments

Comments
 (0)