Skip to content

Commit

Permalink
add parameters locale and useDirtyRect to ec.init
Browse files Browse the repository at this point in the history
  • Loading branch information
helgasoft committed Sep 16, 2021
1 parent d4ec1c4 commit fb0b8f0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre", "cph")),
person("John", "Coene", email = "[email protected]", role = c("aut", "cph"))
Expand All @@ -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/
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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_
Expand Down
23 changes: 14 additions & 9 deletions R/echarty.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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/[email protected].6/dist/echarts-gl.min.js', ask)
wt <- ec.plugjs(wt, 'https://cdn.jsdelivr.net/npm/[email protected].8/dist/echarts-gl.min.js', ask)
}
if ('world' %in% load) {
wt <- ec.plugjs(wt, 'https://cdn.jsdelivr.net/npm/[email protected]/map/js/world.js', ask)
Expand Down Expand Up @@ -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.
#'
Expand Down
6 changes: 3 additions & 3 deletions inst/htmlwidgets/echarty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions man/ec.clmn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/ec.examples.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions man/ec.init.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb0b8f0

Please sign in to comment.