@@ -30,8 +30,8 @@ noCoord <- c('polar','radar','singleAxis','parallelAxis','calendar')
3030# ' @param ctype Chart type, default is 'scatter'.
3131# ' @param preset Boolean (default TRUE). Build preset attributes like dataset, series, xAxis, yAxis, etc.
3232# ' @param series.param Additional attributes for preset series, default is NULL.\cr
33- # ' Can be used for non-timeline and timeline series (instead of _tl.series_). A single list defines one series type only. \cr
34- # ' One could also define all series directly with _series=list(list(...),list...)_ instead .
33+ # ' Defines a single series type. Can be used for both non-timeline and timeline series. \cr
34+ # ' Multiple series types need to be defined directly with _series=list(list(...),list...)_ or added with [ec.upd] .
3535# ' @param tl.series Deprecated, use _timeline_ and _series.param_ instead.\cr
3636# ' @param ... Optional widget attributes. See Details. \cr
3737# ' @param width,height Optional valid CSS unit (like \code{'100\%'},
@@ -120,6 +120,7 @@ noCoord <- c('polar','radar','singleAxis','parallelAxis','calendar')
120120# ' )
121121# '
122122# ' @importFrom htmlwidgets createWidget sizingPolicy getDependency JS shinyWidgetOutput shinyRenderWidget
123+ # ' @importFrom utils read.csv
123124# ' @import dplyr
124125# '
125126# ' @export
@@ -156,9 +157,11 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
156157 useDirtyRect <- if (is.null(opt1 $ useDirtyRect )) FALSE else opt1 $ useDirtyRect
157158 xtKey <- if (is.null(opt1 $ xtKey )) ' XkeyX' else opt1 $ xtKey
158159 if (xtKey == ' XkeyX' ) df $ XkeyX <- dfKey # add new column for Xtalk filtering, if needed
160+ # allow debug feedback thru cat() in JS and R code:
161+ dbg <- if (is.null(opt1 $ dbg )) FALSE else opt1 $ dbg
159162 # remove the above attributes since they are not valid ECharts options
160163 opt1 $ ask <- opt1 $ js <- opt1 $ renderer <- opt1 $ locale <- NULL
161- opt1 $ useDirtyRect <- opt1 $ elementId <- opt1 $ xtKey <- NULL
164+ opt1 $ useDirtyRect <- opt1 $ elementId <- opt1 $ xtKey <- opt1 $ dbg <- NULL
162165 axis2d <- c(' pictorialBar' ,' candlestick' ,' boxplot' ,' scatterGL' ) # 'custom',
163166
164167 # forward widget options using x
@@ -168,7 +171,7 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
168171 renderer = renderer ,
169172 locale = locale ,
170173 useDirtyRect = useDirtyRect ,
171- jcode = js ,
174+ jcode = js , dbg = dbg ,
172175 opts = opt1 ,
173176 settings = list (
174177 crosstalk_key = key ,
@@ -285,11 +288,11 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
285288 return (list (x = xtem , y = ytem , z = ' z' , c = ser $ coordinateSystem ))
286289 }
287290 doVMap <- function (wid ) {
288- # visualMap assist
291+ # visualMap assist: auto add min/max/calculable (categories==piecewise)
289292 vm <- wid $ opts $ visualMap
290293 out <- NULL
291294 if (! is.null(df ) && ! is.null(vm ) &&
292- is.null(vm $ min ) && is.null(vm $ max ) &&
295+ is.null(vm $ min ) && is.null(vm $ max ) && is.null( vm $ categories ) &&
293296 (is.null(vm $ type ) || (vm $ type == ' continuous' )) ) {
294297
295298 xx <- length(colnames(df )) # last numeric column by default
@@ -300,7 +303,6 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
300303 ) xx <- ' value'
301304 if (! is.null(vm $ dimension )) xx <- vm $ dimension
302305 out <- list (
303- # dimension= xx,
304306 min = min(na.omit(df [,xx ])),
305307 max = max(na.omit(df [,xx ])),
306308 calculable = TRUE
@@ -471,6 +473,7 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
471473 ),
472474 dependencies = deps
473475 )
476+ # if (dbg) cat('\naxis2d=',axis2d)
474477
475478 tmp <- getOption(' echarty.font' )
476479 if (! is.null(tmp ))
@@ -482,20 +485,14 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
482485
483486 # ------------- plugins loading -----------------------------
484487 opt1 <- wt $ x $ opts
485- load <- opt1 $ load ;
486- wt $ x $ opts $ load <- NULL
488+ load <- opt1 $ load ; wt $ x $ opts $ load <- NULL
487489 if (length(load )== 1 && grepl(' ,' , load , fixed = TRUE ))
488490 load <- unlist(strsplit(load , ' ,' ))
489491
490492 path <- system.file(' js' , package = ' echarty' )
491493 dep <- NULL
492494
493495 if (' world' %in% load ) {
494- dep <- htmltools :: htmlDependency(
495- name = ' world' , version = ' 1.0.0' ,
496- src = c(file = path ), script = ' world.js' )
497- wt $ dependencies <- append(wt $ dependencies , list (dep ))
498-
499496 if (preset ) {
500497 wt $ x $ opts $ xAxis <- wt $ x $ opts $ yAxis <- NULL
501498 if (! is.null(df )) { # coordinateSystem='geo' needed for all series
@@ -511,11 +508,14 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
511508 # if (!is.null(df)) # cancelled: don't know if df first 2 cols are 'lng','lat'
512509 # wt$x$opts$geo$center= c(mean(unlist(df[,1])), mean(unlist(df[,2])))
513510 }
511+ dep <- htmltools :: htmlDependency(
512+ name = ' world' , version = ' 1.0.0' ,
513+ src = c(file = path ), script = ' world.js' )
514+ wt $ dependencies <- append(wt $ dependencies , list (dep ))
514515 }
515-
516516 if (' leaflet' %in% load ) {
517- # coveralls pops error, win/linux ok :
518- # stopifnot("ec.init: library 'leaflet' not installed"= file.exists(file.path(.libPaths(), 'leaflet')[[1]]))
517+ # coveralls pops error, win/linux ok :
518+ # stopifnot("ec.init: library 'leaflet' not installed"= file.exists(file.path(.libPaths(), 'leaflet')[[1]]))
519519 if (! file.exists(file.path(.libPaths(), ' leaflet' )[[1 ]])) warning(" ec.init: library 'leaflet' not installed" )
520520 if (preset ) {
521521 # customizations for leaflet
@@ -572,9 +572,10 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
572572 }
573573
574574 # Plugins implemented as dynamic load on-demand
575- cdn <- ' https://cdn.jsdelivr.net/npm/'
576- if (' 3D' %in% load ) {
577- if (preset ) { # replace 2D presets with 3D
575+ if (any(load %in% c(' 3D' ,' liquid' ,' gmodular' ,' wordcloud' ))) {
576+ plf <- read.csv(system.file(' plugins.csv' , package = ' echarty' ), header = TRUE , stringsAsFactors = FALSE )
577+ if (' 3D' %in% load ) {
578+ if (preset ) { # replace 2D presets with 3D
578579 isScatGL <- ' scatterGL' %in% unlist(lapply(opt1 $ series , \(k ){k $ type })) # scatterGL is 2D
579580 if (! isScatGL && is.null(opt1 $ globe ) && is.null(opt1 $ geo3D ) ) {
580581 wt $ x $ opts $ xAxis <- wt $ x $ opts $ yAxis <- NULL
@@ -593,21 +594,12 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
593594 \(s ) { s $ type = if (s $ type == ' scatter' ) ' scatter3D' else s $ type ; s })
594595 }
595596 }
596- wt <- ec.plugjs(wt ,
597- paste0(cdn ,' echarts-gl@2.0.9/dist/echarts-gl.min.js' ), ask )
598- }
599- if (' liquid' %in% load )
600- wt <- ec.plugjs(wt ,
601- paste0(cdn ,' echarts-liquidfill@latest/dist/echarts-liquidfill.min.js' ), ask )
602-
603- if (' gmodular' %in% load )
604- wt <- ec.plugjs(wt ,
605- paste0(cdn ,' echarts-graph-modularity@latest/dist/echarts-graph-modularity.min.js' ), ask )
606-
607- if (' wordcloud' %in% load )
608- wt <- ec.plugjs(wt ,
609- paste0(cdn ,' echarts-wordcloud@latest/dist/echarts-wordcloud.min.js' ), ask )
610-
597+ wt <- ec.plugjs(wt , plf [plf $ name == ' 3D' ,]$ url , ask )
598+ }
599+ if (' liquid' %in% load ) wt <- ec.plugjs(wt , plf [plf $ name == ' liquid' ,]$ url , ask )
600+ if (' gmodular' %in% load ) wt <- ec.plugjs(wt , plf [plf $ name == ' gmodular' ,]$ url , ask )
601+ if (' wordcloud' %in% load ) wt <- ec.plugjs(wt , plf [plf $ name == ' wordcloud' ,]$ url , ask )
602+ }
611603 # load unknown plugins
612604 unk <- load [! load %in% c(' leaflet' ,' custom' ,' world' ,' lottie' ,' ecStat' ,
613605 ' 3D' ,' liquid' ,' gmodular' ,' wordcloud' )]
@@ -653,6 +645,7 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
653645 tmp <- xyNamesCS(tl.series )
654646 xtem <- tmp $ x ; ytem <- tmp $ y
655647 if (! is.null(tmp $ c )) tl.series $ coordinateSystem <- tmp $ c
648+ # if (dbg) cat('\ntl=',tmp$x,' ',tmp$y,' ',tmp$c)
656649
657650 if (any(c(' geo' ,' leaflet' ) %in% tl.series $ coordinateSystem )) {
658651 klo <- ' lng' ; kla <- ' lat'
@@ -670,7 +663,7 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
670663 if (tl.series $ coordinateSystem == ' leaflet' )
671664 wt $ x $ opts $ leaflet $ center <- center
672665 }
673- }
666+ }
674667
675668 if (tl.series $ type == ' map' ) {
676669 xtem <- ' name' ; ytem <- ' value'
@@ -1209,9 +1202,9 @@ ec.plugjs <- function(wt=NULL, source=NULL, ask=FALSE) {
12091202 startsWith(source , ' http' ) || startsWith(source , ' file://' ))
12101203 fname <- basename(source )
12111204 fname <- unlist(strsplit(fname , ' ?' , fixed = TRUE ))[1 ] # when 'X.js?key=Y'
1212- # if (!endsWith(fname, '.js'))
1213- # stop('ec.plugjs expecting .js suffix', call. = FALSE)
1205+ # if (!endsWith(fname, '.js')) stop('ec.plugjs expecting .js suffix', call. = FALSE)
12141206 path <- system.file(' js' , package = ' echarty' )
1207+
12151208 ffull <- paste0(path ,' /' ,fname )
12161209 if (! file.exists(ffull )) {
12171210 if (ask ) {
@@ -1223,19 +1216,20 @@ ec.plugjs <- function(wt=NULL, source=NULL, ask=FALSE) {
12231216 if (is.na(ans )) ans <- FALSE # was cancelled
12241217 } else
12251218 ans <- TRUE
1226- if (ans ) {
1227- try(withCallingHandlers(
1228- download.file(source , ffull , quiet = TRUE ), # method = "libcurl"),
1229- error = function (w ) { ans <- FALSE },
1230- warning = function (w ) { ans <- FALSE }
1231- # cat('ec.plugjs Error:', sub(".+HTTP status was ", "", w, source))
1232- )) # ,silent=TRUE)
1219+ if (ans && ! exists(' ec.webR' )) { # WebR dislikes download.file
1220+ # try(withCallingHandlers( # function(w) { ans <- FALSE }
1221+ errw <- function (w ) { ans <- FALSE
1222+ cat(' ec.plugjs:' , sub(" .+HTTP status was " , " " , w , source )) }
1223+ tryCatch({
1224+ download.file(source , ffull , quiet = TRUE ) }, # method = "libcurl"),
1225+ error = errw , warning = errw
1226+ )
12331227 }
12341228 if (! ans ) return (wt ) # error
12351229 }
12361230 dep <- htmltools :: htmlDependency(
1237- name = fname , version = ' 1.0.0 ' , src = c(file = path ),
1238- script = fname
1231+ name = fname , version = ' 1.1.1 ' , src = c(file = path ),
1232+ script = fname
12391233 )
12401234 wt $ dependencies <- append(wt $ dependencies , list (dep ))
12411235 return (wt )
0 commit comments