add line to candlestick chart

This commit is contained in:
pvictor 2020-12-15 19:14:25 +01:00
parent c7fcaab4bd
commit 898ff0f729
3 changed files with 13 additions and 4 deletions

View File

@ -141,7 +141,7 @@ make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL) {
mapdata$x[is.na(mapdata$x)] <- "NA"
x_order <- unique(mapdata$x)
if (is_x_datetime(mapdata)) {
add_names <- FALSE
add_names <- c("x", "y")
x_order <- sort(x_order)
} else {
add_names <- names(mapping)

View File

@ -31,8 +31,8 @@ add_line <- function(ax,
} else {
apex_type <- ax$x$mixed_type
}
if (!isTRUE(apex_type %in% c("line", "bar", "scatter")))
stop("add_line: apex() must be a column or scatter chart.", call. = FALSE)
if (!isTRUE(apex_type %in% c("line", "bar", "scatter", "candlestick")))
stop("add_line: apex() must be a column, scatter or candlestick chart.", call. = FALSE)
ax$x$ax_opts$chart$type <- "line"
if (is.null(data))
data <- ax$x$data
@ -56,6 +56,13 @@ add_line <- function(ax,
ax$x$ax_opts$stroke$width <- c(ax$x$ax_opts$stroke$width, 4)
}
}
if (identical(apex_type, "candlestick")) {
if (is.null(ax$x$ax_opts$stroke$width)) {
ax$x$ax_opts$stroke$width <- c(1, 4)
} else {
ax$x$ax_opts$stroke$width <- c(ax$x$ax_opts$stroke$width, 4)
}
}
if (identical(type, "line")) {
ax$x$ax_opts$stroke$curve <- "straight"
} else if (identical(type, "spline")) {

View File

@ -35,7 +35,8 @@ parse_df <- function(data, add_names = FALSE) {
# format(x)
js_date(x)
} else if (inherits(x, "POSIXt")) {
as.numeric(x) * 1000
# as.numeric(x) * 1000
js_date(x)
} else if (inherits(x, "factor")) {
as.character(x)
} else {
@ -112,6 +113,7 @@ parse_timeline_data <- function(.list) {
parse_candlestick_data <- function(.list) {
list(list(
type = "candlestick",
data = lapply(
X = seq_len(length(.list[[1]])),
FUN = function(i) {