From 9baa753c3f7deb5bfd3042fb37183a024f227f86 Mon Sep 17 00:00:00 2001 From: Victor Perrier Date: Tue, 13 Jun 2023 18:01:21 +0200 Subject: [PATCH] added parse_dumbbell_data() --- R/parse-data.R | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/R/parse-data.R b/R/parse-data.R index 07b121c..b101d47 100644 --- a/R/parse-data.R +++ b/R/parse-data.R @@ -110,6 +110,44 @@ parse_timeline_data <- function(.list) { } +parse_dumbbell_data <- function(.list) { + if (is.null(.list$group)) { + lapply( + X = seq_len(length(.list[[1]])), + FUN = function(i) { + val <- lapply(.list, `[[`, i) + l <- list( + x = as.character(val$y), + y = list(val$x, val$xend) + ) + if (!is.null(val$fill)) { + l$fillColor <- val$fill + } + l + } + ) + } else { + grouped <- as.data.frame(.list, stringsAsFactors = FALSE) + grouped$group <- NULL + grouped <- split( + x = grouped, + f = .list$group + ) + grouped <- lapply(grouped, as.list) + lapply( + X = names(grouped), + FUN = function(name) { + list( + name = name, + data = parse_dumbbell_data(grouped[[name]]) + ) + } + ) + } +} + + + parse_candlestick_data <- function(.list) { list(list( type = "candlestick",