From fb0b8f0e1b9d551b65e03198027e55349fdbdae0 Mon Sep 17 00:00:00 2001 From: helgasoft Date: Wed, 15 Sep 2021 18:55:55 -0700 Subject: [PATCH] add parameters locale and useDirtyRect to ec.init --- DESCRIPTION | 6 +++--- NEWS.md | 4 ++++ R/echarty.R | 23 ++++++++++++++--------- inst/htmlwidgets/echarty.js | 6 +++--- man/ec.clmn.Rd | 4 ++-- man/ec.examples.Rd | 4 ++-- man/ec.init.Rd | 9 +++++---- 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 633bedf..13dcf6c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: echarty Title: Minimal R/Shiny Interface to JavaScript Library 'ECharts' -Date: 2021-08-11 -Version: 0.3.1.1 +Date: 2021-09-15 +Version: 0.3.1.2 Authors@R: c( person("Larry", "Helgason", email = "larry@helgasoft.com", role = c("aut", "cre", "cph")), person("John", "Coene", email = "jcoenep@gmail.com", role = c("aut", "cph")) @@ -24,7 +24,7 @@ Suggests: rmarkdown, knitr, shiny -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 Roxygen: list(markdown = TRUE) URL: https://github.com/helgasoft/echarty BugReports: https://github.com/helgasoft/echarty/issues/ diff --git a/NEWS.md b/NEWS.md index 226a274..0ac2699 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # history of echarty package development +## v. 0.3.1.2 + +- _ec.init_ added ECharts parameters _locale_ and _useDirtyRect_ + ## v. 0.3.1 - _ec.init_ param _timeline_ renamed to _tl.series_ diff --git a/R/echarty.R b/R/echarty.R index ae9e5f8..5abdcfb 100644 --- a/R/echarty.R +++ b/R/echarty.R @@ -23,10 +23,12 @@ #' Attribute \emph{coordinateSystem} is set to \emph{'cartesian2d'} by default. Auto-generated \emph{timeline} and \emph{options} will be preset for the chart as well. #' @param ... other arguments to pass to the widget. \cr #' Custom widget arguments include: \cr \itemize{ -#' \item js - a string with a Javascript expression to evaluate -#' \item renderer - 'canvas'(default) or 'svg' #' \item elementId - Id of the widget, default is NULL(auto-generated) -#' \item ask - the \emph{plugjs} parameter when \emph{load} is present, TRUE or FALSE(default) +#' \item ask - the \emph{plugjs} parameter when \emph{load} is present, FALSE by default +#' \item js - single string or a two-strings vector with JavaScript expressions to evaluate. First is evaluated before and second after chart initialization. Chart object 'opts' is exposed for the second script. +#' \item renderer - 'canvas'(default) or 'svg' +#' \item locale - 'EN'(default) or 'ZH' or other, see \href{https://echarts.apache.org/en/api.html#echarts.init}{here} +#' \item useDirtyRect - enable dirty rectangle rendering or not, FALSE by default, see \href{https://echarts.apache.org/en/api.html#echarts.init}{here} #' } #' @return A widget to plot, or to save and expand with more features. #' @@ -47,7 +49,6 @@ #' \item gmodular - graph modularity, see \href{https://github.com/ecomfe/echarts-graph-modularity}{source} \cr #' \item wordcloud - cloud of words, see \href{https://github.com/ecomfe/echarts-wordcloud}{source} \cr #' } or install you own third-party plugins. -#' Parameter 'js' accepts a vector of one or two strings. The first one is executed before chart initialization, the second - after. Chart object 'opts' is exposed in the second script. #' #' @examples #' # basic scatter chart from a data.frame, using presets @@ -73,12 +74,14 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL, width=NULL, height=NULL, ...) { opts <- list(...) + elementId <- if (is.null(opts$elementId)) NULL else opts$elementId + js <- if (is.null(opts$js)) NULL else opts$js ask <- if (is.null(opts$ask)) FALSE else opts$ask renderer <- if (is.null(opts$renderer)) 'canvas' else tolower(opts$renderer) - js <- if (!is.null(opts$js)) opts$js else NULL - elementId <- if (is.null(opts$elementId)) NULL else opts$elementId + locale <- if (is.null(opts$locale)) 'EN' else toupper(opts$locale) + useDirtyRect <- if (is.null(opts$useDirtyRect)) FALSE else opts$useDirtyRect # remove the above since they are not valid ECharts options - opts$ask <- opts$js <- opts$renderer <- opts$elementId <- NULL + opts$ask <- opts$js <- opts$renderer <- opts$locale <- opts$useDirtyRect <- opts$elementId <- NULL # presets are used as default for examples and testing # user can also ignore or replace them @@ -114,6 +117,8 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL, theme = '', draw = TRUE, renderer = renderer, + locale = locale, + useDirtyRect = useDirtyRect, mapping = list(), events = list(), buttons = list(), @@ -232,7 +237,7 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL, wt$x$opts$yAxis3D <- list(list()) wt$x$opts$zAxis3D <- list(list()) } - wt <- ec.plugjs(wt, 'https://cdn.jsdelivr.net/npm/echarts-gl@2.0.6/dist/echarts-gl.min.js', ask) + wt <- ec.plugjs(wt, 'https://cdn.jsdelivr.net/npm/echarts-gl@2.0.8/dist/echarts-gl.min.js', ask) } if ('world' %in% load) { wt <- ec.plugjs(wt, 'https://cdn.jsdelivr.net/npm/echarts@4.9.0/map/js/world.js', ask) @@ -447,7 +452,7 @@ ec.data <- function(df, format='dataset', header=TRUE) { #' @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. #' #' @details Column indexes are counted in R and start at 1.\cr -#' \emph{col} as sprintf supports only two placeholders - %d for numeric and %s for string.\cr +#' \emph{col} as sprintf supports only two placeholders - %d for column indexes and %s for column names.\cr #' \emph{col} as sprintf can contain double quotes, but not single or backquotes.\cr #' Useful to set formatter, color, symbolSize, etc. #' diff --git a/inst/htmlwidgets/echarty.js b/inst/htmlwidgets/echarty.js index 6f4e396..afe9920 100644 --- a/inst/htmlwidgets/echarty.js +++ b/inst/htmlwidgets/echarty.js @@ -64,19 +64,19 @@ HTMLWidgets.widget({ tmp = x.eval; try { eval(tmp); - } catch(err) { console.log('eva1:' + err.message) } + } catch(err) { console.log('eva1: ' + err.message) } } } chart = echarts.init(document.getElementById(el.id), x.theme, - {renderer: x.renderer}); + {renderer: x.renderer, locale: x.locale, useDirtyRect: x.useDirtyRect}); opts = evalFun(x.opts); if (eva2) { try { eval(eva2); - } catch(err) { console.log('eva2:' + err.message) } + } catch(err) { console.log('eva2: ' + err.message) } } if(x.draw === true) diff --git a/man/ec.clmn.Rd b/man/ec.clmn.Rd index 1df6e6d..49983e0 100644 --- a/man/ec.clmn.Rd +++ b/man/ec.clmn.Rd @@ -16,13 +16,13 @@ Helper function to address data column(s) by index or name } \details{ Column indexes are counted in R and start at 1.\cr -\emph{col} as sprintf supports only two placeholders - \%d for numeric and \%s for string.\cr +\emph{col} as sprintf supports only two placeholders - \%d for column indexes and \%s for column names.\cr \emph{col} as sprintf can contain double quotes, but not single or backquotes.\cr Useful to set formatter, color, symbolSize, etc. } \examples{ tmp <- data.frame(Species = as.vector(unique(iris$Species)), - emoji = c('\U0001F33B','\U0001F335','\U0001F33A')) # 🌻,🌵,🌺 + emoji = c('\U0001F33B','\U0001F335','\U0001F33A')) # 🌻,🌵,🌺 df <- iris \%>\% dplyr::inner_join(tmp) # add 6th column 'emoji' p <- df \%>\% dplyr::group_by(Species) \%>\% ec.init() p$x$opts$series <- list(list( diff --git a/man/ec.examples.Rd b/man/ec.examples.Rd index 22304b8..23321a7 100644 --- a/man/ec.examples.Rd +++ b/man/ec.examples.Rd @@ -251,9 +251,9 @@ datset <- list( list('Jasmin Krause', 52, 'Musician', 287, '2011-02-14'), list('Li Lei', 37, 'Teacher', 219, '2011-02-18'), list('Karle Neumann', 25, 'Engineer', 253, '2011-04-02'), - list('Adrian Groß', 19, 'Teacher', NULL, '2011-01-16'), + list('Adrian Groß', 19, 'Teacher', NULL, '2011-01-16'), list('Mia Neumann', 71, 'Engineer', 165, '2011-03-19'), - list('Böhm Fuchs', 36, 'Musician', 318, '2011-02-24'), + list('Böhm Fuchs', 36, 'Musician', 318, '2011-02-24'), list('Han Meimei', 67, 'Engineer', 366, '2011-03-12'))), list(transform = list(type= 'sort', config=list( list(dimension='profession', order='desc'), diff --git a/man/ec.init.Rd b/man/ec.init.Rd index 8a88126..02f345e 100644 --- a/man/ec.init.Rd +++ b/man/ec.init.Rd @@ -41,10 +41,12 @@ string and have \code{'px'} appended.} \item{...}{other arguments to pass to the widget. \cr Custom widget arguments include: \cr \itemize{ -\item js - a string with a Javascript expression to evaluate -\item renderer - 'canvas'(default) or 'svg' \item elementId - Id of the widget, default is NULL(auto-generated) -\item ask - the \emph{plugjs} parameter when \emph{load} is present, TRUE or FALSE(default) +\item ask - the \emph{plugjs} parameter when \emph{load} is present, FALSE by default +\item js - single string or a two-strings vector with JavaScript expressions to evaluate. First is evaluated before and second after chart initialization. Chart object 'opts' is exposed for the second script. +\item renderer - 'canvas'(default) or 'svg' +\item locale - 'EN'(default) or 'ZH' or other, see \href{https://echarts.apache.org/en/api.html#echarts.init}{here} +\item useDirtyRect - enable dirty rectangle rendering or not, FALSE by default, see \href{https://echarts.apache.org/en/api.html#echarts.init}{here} }} } \value{ @@ -71,7 +73,6 @@ Built-in plugins: \cr \itemize{ \item gmodular - graph modularity, see \href{https://github.com/ecomfe/echarts-graph-modularity}{source} \cr \item wordcloud - cloud of words, see \href{https://github.com/ecomfe/echarts-wordcloud}{source} \cr } or install you own third-party plugins. -Parameter 'js' accepts a vector of one or two strings. The first one is executed before chart initialization, the second - after. Chart object 'opts' is exposed in the second script. } \examples{ # basic scatter chart from a data.frame, using presets