@@ -228,14 +228,19 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL,
228228
229229 # Plugins implemented as dynamic load on-demand
230230 if (' 3D' %in% load ) {
231- if (preset ) {
232- wt $ x $ opts $ xAxis <- NULL # replace 2D presets with 3D
231+ if (preset ) { # replace 2D presets with 3D
232+ wt $ x $ opts $ xAxis <- NULL
233233 wt $ x $ opts $ yAxis <- NULL
234- wt $ x $ opts $ series [[1 ]] <- list (type = ' scatter3D' ) # NULL
235234 wt $ x $ opts $ grid3D <- list (list ())
236235 wt $ x $ opts $ xAxis3D <- list (list ())
237236 wt $ x $ opts $ yAxis3D <- list (list ())
238237 wt $ x $ opts $ zAxis3D <- list (list ())
238+ if (! is.null(group1 ) && dplyr :: is.grouped_df(df )) {
239+ # make all series scatter3D
240+ wt $ x $ opts $ series <- lapply(wt $ x $ opts $ series ,
241+ function (s ) { s $ type = ' scatter3D' ; s })
242+ } else
243+ wt $ x $ opts $ series [[1 ]] <- list (type = ' scatter3D' )
239244 }
240245 wt <- ec.plugjs(wt , ' https://cdn.jsdelivr.net/npm/echarts-gl@2.0.8/dist/echarts-gl.min.js' , ask )
241246 }
@@ -244,13 +249,14 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL,
244249 if (preset ) {
245250 wt $ x $ opts $ xAxis <- NULL
246251 wt $ x $ opts $ yAxis <- NULL
247- wt $ x $ opts $ geo = list (map = ' world' , roam = TRUE , zoom = 6 )
252+ wt $ x $ opts $ series <- list (list (type = ' map' , map = ' world' , roam = TRUE ))
253+ # wt$x$opts$geo = list(map='world', roam=TRUE) # duplicate of series
248254 # if (!is.null(df)) # cancelled: dont know if first 2 cols are lng,lat
249255 # wt$x$opts$geo$center= c(mean(unlist(df[,1])), mean(unlist(df[,2])))
250256 }
251257 }
252258 if (' liquid' %in% load )
253- wt <- ec.plugjs(wt , ' https://cdn.jsdelivr.net/npm/echarts-liquidfill@3.0 .0/dist/echarts-liquidfill.min.js' , ask )
259+ wt <- ec.plugjs(wt , ' https://cdn.jsdelivr.net/npm/echarts-liquidfill@3.1 .0/dist/echarts-liquidfill.min.js' , ask )
254260
255261 if (' gmodular' %in% load )
256262 wt <- ec.plugjs(wt , ' https://cdn.jsdelivr.net/npm/echarts-graph-modularity@2.0.0/dist/echarts-graph-modularity.min.js' , ask )
@@ -448,7 +454,8 @@ ec.data <- function(df, format='dataset', header=TRUE) {
448454# '
449455# ' Helper function to address data column(s) by index or name
450456# '
451- # ' @param col A column index(number), column name(string) or a \code{\link[base]{sprintf}} format string. \cr
457+ # ' @param col A column index(number), column name(string) or a \code{\link[base]{sprintf}} format string.
458+ # ' @param scale A decimal/integer number to multiply the column value by. Only when \emph{col} is a single index.
452459# ' @param ... Comma separated list of column indexes or names, when \emph{col} is \emph{sprintf}. This allows formatting of multiple columns, as for a tooltip.
453460# '
454461# ' @details Column indexes are counted in R and start at 1.\cr
@@ -469,11 +476,12 @@ ec.data <- function(df, format='dataset', header=TRUE) {
469476# ' p
470477# '
471478# ' @export
472- ec.clmn <- function (col = NULL , ... ) {
479+ ec.clmn <- function (col = NULL , scale = 1 , ... ) {
473480 if (is.null(col )) stop(' col is required' , call. = FALSE )
481+ if (is.null(scale )) scale = 1
474482 args <- list (... )
475483 if (is.na(suppressWarnings(as.numeric(col )))) { # col is string
476- if (length(args )== 0 )
484+ if (length(args )== 0 )
477485 ret <- paste0(' return x.data.' ,col ,' ;' )
478486 else { # col a sprintf
479487 spf <- paste(" var sprintf = (str, argv) => !argv.length ? str :" ,
@@ -488,23 +496,22 @@ ec.clmn <- function(col=NULL, ...) {
488496 else { # multiple numeric, they could be in x, x.data, x.value
489497 tmp <- paste(tmp , collapse = ' ,' )
490498 ret <- paste0(sub(' @' ,' %d' ,spf ),
491- " let ss=[" ,tmp ," ]; " ,
492- " ss=ss.map(e => x.value!=null ? x.value[e] : x.data!=null ? x.data[e] : x[e]);" ,
493- " let c = sprintf(`" ,col ," `, ss); return c; " )
499+ " let ss=[" ,tmp ," ]; " ,
500+ " ss=ss.map(e => x.value!=null ? x.value[e] : x.data!=null ? x.data[e] : x[e]);" ,
501+ " let c = sprintf(`" ,col ," `, ss); return c; " )
494502 }
495503 }
496504 }
497- else { # col is numeric thus solitary parameter
505+ else { # col is solitary numeric
498506 if (length(args ) > 0 ) # { cat(length(args));
499507 warning(' col is numeric, others are ignored' , call. = FALSE )
500508 col <- as.numeric(col ) - 1 # from R to JavaScript counting
501- ret <- paste0(' let c = (x.data) ? x.data[' ,col ,' ] : x[' ,col ,' ]; return c;' )
509+ scl <- if (scale == 1 ) ' return c;' else paste0(' return (parseFloat(c)*' ,scale ,' );' )
510+ ret <- paste0(' let c = (x.data) ? x.data[' ,col ,' ] : x[' ,col ,' ]; ' ,scl )
502511 }
503- # cat(ret)
504512 htmlwidgets :: JS(paste0(' function(x) {' , ret , ' }' ))
505513}
506514
507-
508515# ' Charts layout
509516# '
510517# ' Set multiple charts in rows/columns format
0 commit comments