Skip to content

Commit 7e5f794

Browse files
committed
minor fixes
1 parent bb81198 commit 7e5f794

File tree

11 files changed

+102
-91
lines changed

11 files changed

+102
-91
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: echarty
22
Title: Minimal R/Shiny Interface to JavaScript Library 'ECharts'
3-
Date: 2021-07-21
4-
Version: 0.3.0
3+
Date: 2021-07-29
4+
Version: 0.3.1
55
Authors@R: c(
66
person("Larry", "Helgason", email = "larry@helgasoft.com", role = c("aut", "cre", "cph")),
77
person("John", "Coene", email = "jcoenep@gmail.com", role = c("aut", "cph"))

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# history of echarty package development
22

3+
## v. 0.3.1
4+
5+
- _ec.init_ param _timeline_ renamed to _tl.series_
6+
- tweaks in docs, examples and _echarty.js_
7+
38
## v. 0.3.0
49

510
- _ec.timegrp_ merged into _ec.init_ and removed
611
- _ec.init_ can now build timeline, parameters simplified
712
- _ecr.ebars_ now supports dataset, has default tooltip
8-
- _ecr.band_ changed parameter to 'type', improved tooltip support
13+
- _ecr.band_ changed parameter 'two' to 'type', improved tooltip support
914
- _ec.inspect_ expanded with new parameter 'data'
1015
- _eshiny_ demo updated: brush parameters, new zoom capture
1116
- new _ec.clmn_ to reference data column(s) in formatter,color,symbolSize,etc.

R/echarty.R

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,16 @@
1111
#' If the grouping is on multiple columns, only the first one is used.
1212
#' @param preset Disable(FALSE) or enable (TRUE, default) presets xAxis,yAxis,serie for 2D, or grid3D,xAxis3D,yAxis3D,zAxis3D for 3D.
1313
#' @param load Name(s) of plugin(s) to load. Could be a character vector or comma-delimited string. default NULL.\cr
14-
#' [ec.plugjs] will be called internally for each entry, popup prompts controlled by parameter \emph{ask}. \cr
15-
#' Built-in plugins: \cr \itemize{
16-
#' \item leaflet - Leaflet maps with customizable tiles, see \href{https://github.com/gnijuohz/echarts-leaflet#readme}{source}\cr
17-
#' \item custom - renderers for [ecr.band] and [ecr.ebars] \cr
18-
#' } Plugins with one-time installation: \cr \itemize{
19-
#' \item 3D - 3D charts and WebGL acceleration, see \href{https://github.com/ecomfe/echarts-gl}{source} and \href{https://echarts.apache.org/en/option-gl.html#series}{docs} \cr
20-
#' \item world - world map with country boundaries, see \href{https://github.com/apache/echarts/tree/master/test/data/map/js}{source} \cr
21-
#' \item liquid - liquid fill, see \href{https://github.com/ecomfe/echarts-liquidfill}{source} \cr
22-
#' \item gmodular - graph modularity, see \href{https://github.com/ecomfe/echarts-graph-modularity}{source} \cr
23-
#' \item wordcloud - cloud of words, see \href{https://github.com/ecomfe/echarts-wordcloud}{source} \cr
24-
#' } or install you own third-party plugins.
2514
#' @param width,height A valid CSS unit (like \code{'100\%'},
2615
#' \code{'500px'}, \code{'auto'}) or a number, which will be coerced to a
2716
#' string and have \code{'px'} appended.
28-
#' @param timeline A list to build a timeline or NULL(default). The list defines timeline series and their \href{https://echarts.apache.org/en/option.html#series}{parameters}. \cr
29-
#' The only required series parameter is \href{https://echarts.apache.org/en/option.html#series-line.encode}{encode}.
17+
#' @param tl.series A list to build a timeline or NULL(default). The list defines options \href{https://echarts.apache.org/en/option.html#series}{series} and their attributes. \cr
18+
#' The only required attribute is \href{https://echarts.apache.org/en/option.html#series-line.encode}{encode}.
3019
#' \emph{encode} defines which data columns names(not indexes) to use for axes X and Y: \cr
3120
#' Set \emph{x} and \emph{y} when coordinateSystem is \emph{'cartesian2d'}, \cr
3221
#' Set \emph{lng} and \emph{lat} when coordinateSystem is \emph{'geo'}, \cr
3322
#' Set \emph{radius} and \emph{angle} when coordinateSystem is \emph{'polar'}.\cr
34-
#' Parameter \emph{coordinateSystem} is set to \emph{'cartesian2d'} by default.
23+
#' 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.
3524
#' @param ... other arguments to pass to the widget. \cr
3625
#' Custom widget arguments include: \cr \itemize{
3726
#' \item js - a string with a Javascript expression to evaluate
@@ -47,14 +36,26 @@
4736
#' Plugin '3D' presets will not work for 'scatterGL'. Instead, use \emph{preset=FALSE} and set explicitly \emph{xAxis,yAxis}. \cr
4837
#' Plugins 'leaflet' and 'world' preset zoom=6 and center to the mean of all coordinates. \cr
4938
#' Users can delete or overwrite any presets as needed. \cr
39+
#' [ec.plugjs] will be called internally for each \emph{load} entry, popup prompts controlled by parameter \emph{ask}. \cr
40+
#' Built-in plugins: \cr \itemize{
41+
#' \item leaflet - Leaflet maps with customizable tiles, see \href{https://github.com/gnijuohz/echarts-leaflet#readme}{source}\cr
42+
#' \item custom - renderers for [ecr.band] and [ecr.ebars] \cr
43+
#' } Plugins with one-time installation: \cr \itemize{
44+
#' \item 3D - 3D charts and WebGL acceleration, see \href{https://github.com/ecomfe/echarts-gl}{source} and \href{https://echarts.apache.org/en/option-gl.html#series}{docs} \cr
45+
#' \item world - world map with country boundaries, see \href{https://github.com/apache/echarts/tree/master/test/data/map/js}{source} \cr
46+
#' \item liquid - liquid fill, see \href{https://github.com/ecomfe/echarts-liquidfill}{source} \cr
47+
#' \item gmodular - graph modularity, see \href{https://github.com/ecomfe/echarts-graph-modularity}{source} \cr
48+
#' \item wordcloud - cloud of words, see \href{https://github.com/ecomfe/echarts-wordcloud}{source} \cr
49+
#' } or install you own third-party plugins.
50+
#' 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.
5051
#'
5152
#' @examples
5253
#' # basic scatter chart from a data.frame, using presets
5354
#' cars %>% ec.init()
5455
#'
5556
#' # a timeline with two series and autoPlay
5657
#' p <- iris %>% dplyr::group_by(Species) %>% ec.init(
57-
#' timeline=list(
58+
#' tl.series=list(
5859
#' encode=list(x=NULL, y=c('Sepal.Width', 'Petal.Length')),
5960
#' markPoint = list(data=list(list(type='max'), list(type='min')))
6061
#' )
@@ -68,7 +69,7 @@
6869
#'
6970
#' @export
7071
ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL,
71-
timeline=NULL,
72+
tl.series=NULL,
7273
width=NULL, height=NULL, ...) {
7374

7475
opts <- list(...)
@@ -201,7 +202,7 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL,
201202
#rlo <- range(df[,1])
202203
#rla <- range(df[,2])
203204
#wt$x$opts$leaflet$center= c(sum(rlo)/2, sum(rla)/2)
204-
wt$x$opts$leaflet$center= c(mean(df[,1]), mean(df[,2]))
205+
wt$x$opts$leaflet$center= c(mean(unlist(df[,1])), mean(unlist(df[,2])))
205206
wt$x$opts$leaflet$zoom <- 6
206207
}
207208
}
@@ -259,27 +260,30 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL,
259260
}
260261

261262
# timeline is last to execute
262-
if (!is.null(timeline)) {
263+
if (!is.null(tl.series)) {
263264
if (!is.grouped_df(df))
264-
stop('timeline requires a grouped data.frame', call. = FALSE)
265+
stop('tl.series requires a grouped data.frame', call. = FALSE)
265266

266-
if (is.null(timeline$encode))
267-
stop('encode is required for timeline', call. = FALSE)
267+
if (is.null(tl.series$encode))
268+
stop('encode is required for tl.series', call. = FALSE)
268269

269270
# add missing defaults
270-
if (is.null(timeline$type)) timeline$type <- 'line'
271-
if (is.null(timeline$coordinateSystem)) timeline$coordinateSystem <- 'cartesian2d'
272-
if (timeline$coordinateSystem=='cartesian2d') { xtem <-'x'; ytem <- 'y' }
273-
if (timeline$coordinateSystem=='polar') { xtem <-'radius'; ytem <- 'angle' }
274-
if (timeline$coordinateSystem=='geo') {
271+
if (is.null(tl.series$type)) tl.series$type <- 'line'
272+
#if (is.null(tl.series$coordinateSystem)) tl.series$coordinateSystem <- 'cartesian2d' # not for gauge
273+
if (is.null(tl.series$coordinateSystem) ||
274+
tl.series$coordinateSystem=='cartesian2d') { xtem <-'x'; ytem <- 'y' }
275+
else if (tl.series$coordinateSystem=='polar') { xtem <-'radius'; ytem <- 'angle' }
276+
else if (tl.series$coordinateSystem %in% c('geo','leaflet')) {
275277
xtem <-'lng'; ytem <- 'lat'
276-
wt$x$opts$geo$center <- c(mean(unlist(df[,timeline$encode$lng])),
277-
mean(unlist(df[,timeline$encode$lat])))
278+
center <- c(mean(unlist(df[,tl.series$encode$lng])),
279+
mean(unlist(df[,tl.series$encode$lat])))
280+
if (tl.series$coordinateSystem=='geo') wt$x$opts$geo$center <- center
281+
if (tl.series$coordinateSystem=='leaflet') wt$x$opts$leaflet$center <- center
278282
}
279-
if (is.null(unlist(timeline$encode[xtem]))) {
283+
if (is.null(unlist(tl.series$encode[xtem]))) {
280284
# append col XcolX 1:max for each group
281285
df <- df %>% group_modify(~ { .x %>% mutate(XcolX = 1:nrow(.)) })
282-
timeline$encode[xtem] <- 'XcolX' # instead of relocate(XcolX)
286+
tl.series$encode[xtem] <- 'XcolX' # instead of relocate(XcolX)
283287
# replace only source, transforms stay
284288
wt$x$opts$dataset[[1]] <- list(source=ec.data(df))
285289
}
@@ -299,8 +303,8 @@ ec.init <- function( df=NULL, preset=TRUE, group1='scatter', load=NULL,
299303
#if (!is.null(xcol)) gp <- gp %>% arrange(across(all_of(xcol)))
300304

301305
# multiple series for each Y
302-
series <- lapply(unname(unlist(timeline$encode[ytem])), function(sname) {
303-
append(list(datasetIndex=di, name=sname), timeline)
306+
series <- lapply(unname(unlist(tl.series$encode[ytem])), function(sname) {
307+
append(list(datasetIndex=di, name=sname), tl.series)
304308
})
305309
series <- lapply(series, function(s) {
306310
s$encode[ytem] <- s$name # replace multiple with one
@@ -355,6 +359,7 @@ ec.plugjs <- function(wt=NULL, source=NULL, ask=FALSE) {
355359
if (!startsWith(source, 'http') && !startsWith(source, 'file://'))
356360
stop('ec.plugjs expecting source as URL or file://', call. = FALSE)
357361
fname <- basename(source)
362+
fname <- unlist(strsplit(fname, '?', fixed=TRUE))[1] # when 'X.js?key=Y'
358363
# if (!endsWith(fname, '.js'))
359364
# stop('ec.plugjs expecting .js suffix', call. = FALSE)
360365
path <- system.file('js', package = 'echarty')
@@ -389,7 +394,7 @@ ec.plugjs <- function(wt=NULL, source=NULL, ask=FALSE) {
389394

390395
#' Data helper
391396
#'
392-
#' Make ECharts data from a data.frame
397+
#' Make data lists from a data.frame
393398
#'
394399
#' @param df Chart data in data.frame format, required.
395400
#' @param format A key on how to format the output list \cr \itemize{
@@ -400,6 +405,7 @@ ec.plugjs <- function(wt=NULL, source=NULL, ask=FALSE) {
400405
#' @param header Whether the data will have a header with column names or not, default TRUE. Set this to FALSE when used in \href{https://echarts.apache.org/en/option.html#series-scatter.data}{series.data}.
401406
#' @return A list for \emph{dataset.source}, \emph{series.data} or a list of named lists.
402407
#'
408+
#' @seealso some live \href{https://rpubs.com/echarty/data-models}{code samples}
403409
#' @export
404410
ec.data <- function(df, format='dataset', header=TRUE) {
405411
if (missing(df))
@@ -449,10 +455,10 @@ ec.data <- function(df, format='dataset', header=TRUE) {
449455
#' df <- iris %>% dplyr::inner_join(tmp) # add 6th column 'emoji'
450456
#' p <- df %>% dplyr::group_by(Species) %>% ec.init()
451457
#' p$x$opts$series <- list(list(
452-
#' type='scatter', label=list(show=TRUE, formatter=ec.clmn(6))
458+
#' type='scatter', label=list(show=TRUE, formatter = ec.clmn(6)) # 6th column
453459
#' ))
454-
#' p$x$opts$tooltip <- list(
455-
#' formatter=ec.clmn('species <b>%d</b><br>s.len <b>%d</b><br>s.wid <b>%d</b>',5,1,2))
460+
#' p$x$opts$tooltip <- list(formatter=
461+
#' ec.clmn('species <b>%d</b><br>s.len <b>%d</b><br>s.wid <b>%d</b>', 5,1,2))
456462
#' p
457463
#'
458464
#' @export
@@ -475,18 +481,17 @@ ec.clmn <- function(col=NULL, ...) {
475481
else { # multiple numeric, they could be in x, x.data, x.value
476482
tmp <- paste(tmp, collapse=',')
477483
ret <- paste0(sub('@','%d',spf),
478-
"let ss=[",tmp,"], isd=x.data.length>0, isv=x.value!=null; ",
479-
"ss=ss.map(e => isd ? x.data[e] : isv ? x.value[e] : x[e]);",
480-
"let c = sprintf(`",col,"`, ss); return c; ")
484+
"let ss=[",tmp,"]; ",
485+
"ss=ss.map(e => x.value!=null ? x.value[e] : x.data!=null ? x.data[e] : x[e]);",
486+
"let c = sprintf(`",col,"`, ss); return c; ")
481487
}
482488
}
483489
}
484490
else { # col is numeric thus solitary parameter
485491
if (length(args) > 0) # { cat(length(args));
486492
warning('col is numeric, others are ignored', call.=FALSE)
487493
col <- as.numeric(col) - 1 # from R to JavaScript counting
488-
ret <- paste0('let c = (x.data.length>0) ? x.data[',col,
489-
'] : x[',col,']; return c;')
494+
ret <- paste0('let c = (x.data) ? x.data[',col,'] : x[',col,']; return c;')
490495
}
491496
#cat(ret)
492497
htmlwidgets::JS(paste0('function(x) {', ret, '}'))

R/examples.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,14 @@
203203
#'
204204
#'
205205
#' #------ Timeline animation
206-
#' orng <- Orange
207206
#' p <- Orange %>% dplyr::group_by(age) %>% ec.init(
208-
#' timeline=list(type='bar', encode=list(x='Tree', y='circumference'))
207+
#' tl.series=list(type='bar', encode=list(x='Tree', y='circumference'))
209208
#' )
210209
#' p$x$opts$timeline <- append(p$x$opts$timeline, list(autoPlay=TRUE))
211210
#' p$x$opts$options <- lapply(p$x$opts$options,
212211
#' function(o) { o$title$text <- paste('age',o$title$text,'days'); o })
213212
#' p$x$opts$xAxis <- list(type='category', name='tree')
214-
#' p$x$opts$yAxis <- list(max=max(orng$circumference))
213+
#' p$x$opts$yAxis <- list(max=max(Orange$circumference))
215214
#' p
216215
#'
217216
#'

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@
55

66
<!-- badges: start -->
77

8-
98
[![R-CMD-check](https://github.com/helgasoft/echarty/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/helgasoft/echarty/actions/workflows/R-CMD-check.yaml)
109
[![size](https://img.shields.io/github/languages/code-size/helgasoft/echarty)](https://github.com/helgasoft/echarty/releases/)
1110
<!--
1211
[![CRAN
1312
downloads](https://cranlogs.r-pkg.org/badges/last-day/echarty)](https://cranlogs.r-pkg.org/badges/last-day/echarty) -->
1413
<!-- badges: end -->
1514

15+
<a href='https://helgasoft.github.io/echarty'><img src="man/figs/echarty.gallery.png" alt="echarty.gallery" /></a>
16+
1617
This package is a thin R wrapper around Javascript library
17-
[ECharts](https://echarts.apache.org/en/index.html). The R list
18-
parameters come directly from [ECharts’
18+
[ECharts](https://echarts.apache.org/en/index.html). The list
19+
parameters in R replicate [ECharts’
1920
documentation](https://echarts.apache.org/en/option.html). There are
20-
just a few extra commands.
21-
Users can benefit from the **full functionality** of ECharts to build
22-
interactive charts in R and Shiny with minimal coding.
21+
just a few additional commands.
22+
Users can benefit from ECharts' **full functionality** to build
23+
interactive charts in R and Shiny with minimal overhead.
24+
2325
Wider connectivity and deployment potential through [crosstalk
24-
support](https://helgasoft.github.io/echarty/xtalk.html).
26+
support](https://helgasoft.github.io/echarty/xtalk.html).
27+
2528

2629
## Installation
2730

@@ -55,22 +58,18 @@ iris %>% ec.init(load='3D')
5558

5659
## Get started
5760

58-
<br />
59-
60-
The [**WEBSITE**](https://helgasoft.github.io/echarty) has detailed
61-
tutorials and tips.
62-
<br /> There are plenty of [**code
61+
The [**WEBSITE**](https://helgasoft.github.io/echarty) has a gallery with code and tutorials.
62+
<br /> The package has plenty of [**code
6363
examples**](https://github.com/helgasoft/echarty/blob/main/R/examples.R)
64-
included. The easiest way to run them in RStudio is to type
65-
**?ec.examples** in the Console, then copy/paste any code from Help to
64+
included. Type
65+
**?ec.examples** in the RStudio Console, then copy/paste any code from Help to
6666
see the result.
67-
Or run all examples at once with **example(‘ec.examples’)** and they
68-
will show in the Viewer.
69-
67+
<!--
7068
Do not hesitate to ask questions in
7169
[Discussions](https://github.com/helgasoft/echarty/discussions) or
7270
report problems in
7371
[Issues](https://github.com/helgasoft/echarty/issues).
72+
-->
7473

7574
Now you can start building [**beautiful
7675
charts**](https://echarts.apache.org/examples/en/index.html) (and

inst/htmlwidgets/echarty.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ HTMLWidgets.widget({
7373

7474
opts = evalFun(x.opts);
7575

76-
if(x.draw === true)
77-
chart.setOption(opts);
78-
7976
if (eva2) {
8077
try {
8178
eval(eva2);
8279
} catch(err) { console.log('eva2:' + err.message) }
8380
}
8481

82+
if(x.draw === true)
83+
chart.setOption(opts);
84+
8585
// shiny callbacks
8686
if (HTMLWidgets.shinyMode) {
8787

man/ec.clmn.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ec.data.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ec.examples.Rd

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)