From 55b8d3d806407180881814cde2daec01e3445b37 Mon Sep 17 00:00:00 2001 From: rdatasculptor Date: Sat, 21 Oct 2023 11:29:41 +0200 Subject: [PATCH] Update nesting.R fix for e_add_nested in cases of more than one dataset in an echart --- R/nesting.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/R/nesting.R b/R/nesting.R index 18ae9de2..5ea5c9cb 100644 --- a/R/nesting.R +++ b/R/nesting.R @@ -80,26 +80,30 @@ e_add_nested <- function(e, param, ..., .serie = NULL, .data = NULL) { if (missing(e) || missing(param)) { stop("missing e or param", call. = FALSE) } - + if(is.null(.data)) ds <- e$x$data else ds <- map_grps_(.data, e$x$tl) - + for (i in seq_along(ds)) { data <- ds[[i]] |> dplyr::select(...) - + data <- apply(data, 1, as.list) - + for (j in seq_along(data)) { - if(!is.null(.serie) && .serie != j) - next if (!e$x$tl) { - e$x$opts$series[[i]]$data[[j]][[param]] <- data[[j]] + for(k in seq_along(e$x$opts$series)){ + if(!is.null(.serie) && .serie != k) + next + e$x$opts$series[[k]]$data[[j]][[param]] <- data[[j]] + } } else { for(k in seq_along(e$x$opts$options[[i]]$series)){ + if(!is.null(.serie) && .serie != k) + next e$x$opts$options[[i]]$series[[k]]$data[[j]][[param]] <- data[[j]] } }