@@ -311,13 +311,15 @@ ec.init <- function( df=NULL, preset=TRUE, ctype='scatter', load=NULL,
311311 tl.series $ coordinateSystem <- ' cartesian2d'
312312 if (tl.series $ coordinateSystem == ' cartesian2d' ) {
313313 xtem <- ' x' ; ytem <- ' y' }
314+ if (startsWith(tl.series $ coordinateSystem , ' cartesian' )) {
315+ xtem <- ' x' ; ytem <- ' y' ; ztem <- ' z' }
314316 else if (tl.series $ coordinateSystem == ' polar' ) {
315317 xtem <- ' radius' ; ytem <- ' angle' }
316318 else if (tl.series $ coordinateSystem %in% c(' geo' ,' leaflet' )) {
317319 xtem <- ' lng' ; ytem <- ' lat'
318320 center <- c(mean(unlist(df [,tl.series $ encode $ lng ])),
319321 mean(unlist(df [,tl.series $ encode $ lat ])))
320- if (tl.series $ coordinateSystem == ' geo' ) wt $ x $ opts $ geo $ center <- center
322+ if (tl.series $ coordinateSystem == ' geo' ) wt $ x $ opts $ geo $ center <- center
321323 if (tl.series $ coordinateSystem == ' leaflet' ) wt $ x $ opts $ leaflet $ center <- center
322324 }
323325 if (is.null(unlist(tl.series $ encode [xtem ]))) {
@@ -347,15 +349,15 @@ ec.init <- function( df=NULL, preset=TRUE, ctype='scatter', load=NULL,
347349 # multiple series for each Y, like y=c('col1', 'col3')
348350 series <- lapply(unname(unlist(tl.series $ encode [ytem ])),
349351 function (sname ) {
350- append(list (datasetIndex = di , name = sname ), tl.series )
352+ append(list (datasetIndex = di , name = sname ), tl.series )
351353 })
352354 series <- lapply(series , function (s ) {
353355 s $ encode [ytem ] <- s $ name # replace multiple col.names with one
354356 s
355357 })
356358
357- list (title = list (text = as.character(unique(gp [gvar ])), left = 40 ),
358- series = unname(series ))
359+ list (title = list (text = as.character(unique(gp [gvar ]))),
360+ series = unname(series ))
359361 })
360362
361363 wt $ x $ opts $ options <- optl
@@ -595,11 +597,11 @@ ecr.band <- function(df=NULL, lower=NULL, upper=NULL, type='polygon', ...) {
595597# ' @return A widget with error bars added if successful, otherwise the input wt
596598# '
597599# ' @details
598- # ' Grouped series are supported, but require the group column to be included in df . \cr
599- # ' ecr.ebars are custom series, so \emph{ec.init(load='custom')} is required . \cr
600- # ' ecr.ebars will add a chart legend and its own tooltip if none is provided.\cr
601- # ' ecr.ebars with name attribute will show separate in the legend \cr
602- # ' ecr.ebars should be set at the end , after all other series.
600+ # ' \emph{ecr.ebars} are custom series, so \emph{ec.init(load='custom')} is required . \cr
601+ # ' Grouped series are supported, but require the group column to be included in \emph{df} . \cr
602+ # ' Will add a chart legend and its own tooltip if none is provided.\cr
603+ # ' ecr.ebars with name attribute will show separate in the legend. \cr
604+ # ' Command should be called last , after all other series.
603605# '
604606# ' @examples
605607# ' if (interactive()) {
@@ -620,6 +622,8 @@ ecr.ebars <- function(wt, df=NULL, hwidth=6, ...) {
620622 stop(' df must be a data.frame' , call. = FALSE )
621623 if (! ' renderers' %in% unlist(lapply(wt $ dependencies , function (d ) d $ name )))
622624 stop(" use ec.init(load='custom') for ecr.ebars" , call. = FALSE )
625+ if (! is.null(wt $ saved ))
626+ stop(' Did you place ec.snip at end-of-pipe?' , call. = FALSE )
623627
624628 ser <- wt $ x $ opts $ series # all series
625629 if (is.null(ser )) stop(' series are missing' , call. = FALSE )
@@ -832,7 +836,9 @@ ecs.exec <- function(proxy, cmd='p_merge') {
832836# ' @param width Width of columns, one of xs, md, lg
833837# ' @param title Title for the set
834838# ' @return A container \code{\link[htmltools]{div}} in rmarkdown, otherwise \code{\link[htmltools]{browsable}}
835- # ' @details For 3-4 charts one would use multiple series with a \href{https://echarts.apache.org/en/option.html#grid}{grid}. For greater number of charts _ec.layout_ come in handy.
839+ # ' @details
840+ # ' For 3-4 charts one would use multiple series with a \href{https://echarts.apache.org/en/option.html#grid}{grid}. \cr
841+ # ' For greater number of charts _ec.layout_ come in handy.
836842# ' @examples
837843# ' options(browser = 'firefox')
838844# ' tmp <- lapply(list('dark','macarons','gray','jazz','dark-mushroom'),
@@ -954,21 +960,24 @@ ec.paxis <- function (df=NULL, minmax=TRUE, cols=NULL, ...) {
954960# ' "backgroundColor": "lemonchiffon"}')
955961# '
956962# ' @export
957- ec.theme <- function (wt , name , code = NULL )
963+ ec.theme <- function (wt , name , code = NULL )
958964{
959965 if (missing(name ))
960966 stop(' must define theme name' , call. = FALSE )
961-
967+ if (! is.null(wt $ saved ))
968+ stop(' Did you place ec.snip at end-of-pipe?' , call. = FALSE )
969+
970+ # if (length(wt$x[[1]])==0) wt$x[[1]] <- NULL # parasite list
962971 wt $ x $ theme <- name
963972 if (! is.null(code ))
964973 wt $ x $ themeCode <- code
965974 else {
966975 wt $ x $ themeCode <- NULL
967- path <- system.file(' themes' , package = ' echarty' )
976+ path <- system.file(' themes' , package = ' echarty' )
968977 dep <- htmltools :: htmlDependency(
969- name = name ,
970- version = ' 1.0.0' , src = c(file = path ),
971- script = paste0(name , ' .js' ))
978+ name = name ,
979+ version = ' 1.0.0' , src = c(file = path ),
980+ script = paste0(name , ' .js' ))
972981 wt $ dependencies <- append(wt $ dependencies , list (dep ))
973982 }
974983 wt
@@ -985,7 +994,8 @@ ec.theme <- function (wt, name, code = NULL)
985994# ' @return A JSON string if \code{json} is \code{TRUE} and
986995# ' a \code{list} otherwise.
987996# '
988- # ' @note Must be invoked or chained as last command.
997+ # ' @note Must be invoked or chained as last command.\cr
998+ # ' ec.inspect is incompatible with [ec.snip]
989999# '
9901000# ' @examples
9911001# ' # extract JSON
@@ -997,7 +1007,9 @@ ec.theme <- function (wt, name, code = NULL)
9971007# '
9981008# ' @export
9991009ec.inspect <- function (wt , target = NULL , json = TRUE , ... ) {
1000-
1010+ if (! is.null(wt $ saved ))
1011+ stop(' ec.inspect incompatible with ec.snip' , call. = FALSE )
1012+
10011013 opts <- wt $ x $ opts
10021014
10031015 if (! is.null(target )) {
@@ -1074,10 +1086,11 @@ ec.fromJson <- function(txt, ...) {
10741086# ' Utility to improve readability and typing speed
10751087# '
10761088# ' @param wt A widget to be converted to option list \cr
1077- # ' OR an option list to plot
1089+ # ' OR an option list to a plot
10781090# ' @details
1079- # ' On initialization, pipe _ec.snip_ after [ec.init], \cr
1080- # ' or set for the entire R session with \code{options('echarty.short'=TRUE)}.
1091+ # ' On initialization, add _ec.snip_ at the end of the [ec.init] pipe, \cr
1092+ # ' or set for the entire R session with \code{options('echarty.short'=TRUE)}.\cr
1093+ # ' Note: ec.theme, ecr.ebars, ec.inspect will not work with the session setting.
10811094# '
10821095# ' @examples
10831096# ' p <- cars |> ec.init() |> ec.snip()
@@ -1099,6 +1112,7 @@ ec.snip <- function(wt) {
10991112 }
11001113 else {
11011114 # return the chart widget to plot
1115+ # wt$x holds theme, registerMap, jcode, locale, renderer, etc.
11021116 p <- wt $ saved
11031117 wt $ saved <- NULL
11041118 p $ x $ opts <- wt
@@ -1206,16 +1220,7 @@ if (requireNamespace("shiny", quietly = TRUE)) {
12061220
12071221# ------------- Global Options -----------------
12081222# '
1209- # ' echarty uses the following global options: \cr \itemize{
1210- # ' \item echarty.theme = name of theme file (without extension), from folder /inst/themes
1211- # ' \item echarty.font = font family name
1212- # ' \item echarty.urltiles = tiles URL template for leaflet maps
1213- # ' \item echarty.short = a boolean flag, see [ec.snip]
1214- # ' }
1215- # ' @examples
1216- # ' options('echarty.short'=TRUE) # set
1217- # ' getOption('echarty.short') # get
1218- # ' options('echarty.short'=NULL) # remove
1223+ # ' For info on options and prefixes, type \emph{?echarty} in the R console.
12191224
12201225
12211226
0 commit comments