Skip to content

Commit

Permalink
build 1.6.3.03
Browse files Browse the repository at this point in the history
  • Loading branch information
helgasoft committed May 16, 2024
1 parent ca9f273 commit 2ca110f
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 370 deletions.
7 changes: 4 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: 2024-02-24
Version: 1.6.3.02
Date: 2024-05-16
Version: 1.6.3.03
Author: Larry Helgason, with initial code from John Coene's library echarts4r
Maintainer: Larry Helgason <[email protected]>
Description: Deliver the full functionality of 'ECharts' with minimal overhead. 'echarty' users build R lists for 'ECharts' API. Lean set of powerful commands.
Expand All @@ -16,7 +16,8 @@ Suggests:
jsonlite,
crosstalk,
testthat (>= 3.0.0),
sf,
sf,
leaflet (>= 2.2.0),
knitr,
rmarkdown
RoxygenNote: 7.3.1
Expand Down
37 changes: 20 additions & 17 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# history of package _echarty_

## v.1.6.3.02 latest in development
## v. 1.6.3.03 latest in development

- upgrade ECharts to v.5.5.0, built with R v.4.4.0
- added _nasep_ parameter to ec.data('names') for easier setting of nested lists from a _data.frame_
- tested web freedom [with WebR](https://helgasoft.github.io/echarty/test/coder.html)
- added explicit _leaflet_ dependency, not provided since leaflet v.2.2.0
- added optional tooltip formatter (tipFmt) in _ecr.band_
- refactoring (leaflet, geo, geoJson, tests)

## v.1.6.3 on CRAN
## v. 1.6.3 on CRAN

- added coder.R demo
- correct gridIndex numbering for xAxis/yAxis
- deprecate _tl.series_, replace with _timeline_ and _series.param_

## v.1.6.2.01
## v. 1.6.2.01

- make crosstalk work with improved _ec.clmn_
- add _ecStat_ to built-in plugins
Expand All @@ -28,48 +29,48 @@
- removed width/height from 'tabset', handled by _ec.init_
- _ecr.band_ replaced default type from 'stack' to 'polygon'

## v.1.6.2
## v. 1.6.2

- allow axis rename (fix)
- _ec.data_ grouped boxplots: outliers are custom series
- _ec.clmn_ expanded usage of column names

## v.1.6.0
## v. 1.6.0

- _ec.paxis_ could be chained now
- _ec.data_ format='boxplot' with optional outliers
- _ecr.bars_ with better alignment and horizontal layout

## v.1.5.4.03
## v. 1.5.4.03

- upgrade ECharts to v.5.4.3, built with R v.4.3.1
- breaking change in _ec.init_ signature
- improved _ec.inspect_ and _ec.fromJson_
- fixed small bugs and improved code
- added more tests

## v.1.5.4
## v. 1.5.4

- _ec.util_ command 'layout' updated
- changes in axis names preset, _ec.clmn_ for empty values
- problem running Shiny in R console: _No handler registered for mouseover_

## v.1.5.3
## v. 1.5.3

- upgrade ECharts to v.5.4.2
- _ec.util_ support for map GeoJSON objects, see test-renderers.R
- _ec.init_ new parameter _xtKey_ for crosstalk (ID-column name)
- code cleanup in _ecr.band_
- expand auto-generated axes names to multiple

## v.1.5.2
## v. 1.5.2

- _ec.init_ to set default xAxis/yAxis names from _df_
- _ec.clmn_ accepts JS functions in parameter _col_
- _ec.util_ new command 'button' to run JS function
- fix _tabset_ bug introduced in v.1.5.1

## v.1.5.1
## v. 1.5.1

- upgrade ECharts to v.5.4.1
- remove redundant dependencies, only 3 used now
Expand All @@ -81,7 +82,7 @@
- set _visualMap_ default min/max values from df
- _echarty.js_: add built-in 'mouseout' event

## v.1.5.0 on CRAN
## v. 1.5.0 on CRAN

- upgrade ECharts to v.5.4.0
- built with R v.4.2.2
Expand All @@ -96,7 +97,7 @@
- new _load='lottie'_, lotties support now built-in
- reorganize crosstalk code

## v.1.4.7
## v. 1.4.7

- _ec.util_: add POLYGON/MULTIPOINT, rename param 'type' to 'cmd', new _sf.unzip_
- _ec.util_: new cmd='tabset' to show multiple charts in tabs
Expand All @@ -106,7 +107,7 @@
- support for _lotties_ in _graphic_, see web gallery for sample
- grouping column in 2D charts now could be at any position

## v.1.4.6
## v. 1.4.6

- upgrade ECharts to v.5.3.3
- expand docs for _ec.init_
Expand All @@ -118,7 +119,7 @@
- fixes in _ec.clmn_ and allow empty _col_ parameter for pie,sunburst,etc.
- add _ec.util_ to support map shapefiles thru library 'sf'

## v.1.4.5
## v. 1.4.5

- upgrade ECharts to v.5.3.1, GL to v.2.0.9
- _ec.init_ timeline (_tl.series_) to support 3D
Expand All @@ -133,19 +134,19 @@
- added new brush/click events to demo(_eshiny_)
- cleanup `echarty.js` code for events

## v.1.4.3
## v. 1.4.3

- upgrade ECharts to v.5.2.2, graph-modularity to v.2.1.0

## v.1.4.2
## v. 1.4.2

- replaced magrittr %>% dependency with R native pipe |>
- added _ec.snip_ as option for better code readability
- removed _ec.global_, use options('echarty.xxx') instead
- added _shiny_ dependency to avoid CRAN warnings
- added more unit tests

## v.1.4.0
## v. 1.4.0

- _ec.init_: renamed 'group1' to 'ctype', add presets for parallel chart, improved presets for xAxis
- _ec.paxis_ new helper for parallelAxis
Expand Down Expand Up @@ -240,3 +241,5 @@

## v. 0.1.0
- initial release, approved by CRAN Feb 16, 2021


66 changes: 35 additions & 31 deletions R/echarty.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ NULL
the <- new.env(parent = emptyenv())
the$.ecv.colnames <- NULL
noAxis <- c('radar','parallel','themeRiver','map','gauge','pie','funnel','polar',
'sunburst','tree','treemap','sankey','lines')
'sunburst','tree','treemap','sankey','lines', 'liquidFill','wordCloud')
noCoord <- c('polar','radar','singleAxis','parallelAxis','calendar')
# using list(show=TRUE) or list(list()) is to create empty object{} in JS

#' Initialize command
#'
#' Required to build a chart. In most cases this will be the only command necessary.
#'
#' @param df A data.frame to be preset as \href{https://echarts.apache.org/en/option.html#dataset}{dataset}, default NULL \cr
#' @param df Optional data.frame to be preset as \href{https://echarts.apache.org/en/option.html#dataset}{dataset}, default NULL \cr
#' By default the first column is for X values, second column is for Y, and third is for Z when in 3D.\cr
#' Best practice is to have the grouping column placed last. Grouping column cannot be used as axis.\cr
#' Timeline requires a _grouped data.frame_ to build its \href{https://echarts.apache.org/en/option.html#options}{options}.\cr
Expand All @@ -42,10 +42,10 @@ noCoord <- c('polar','radar','singleAxis','parallelAxis','calendar')
#' Numerical indexes for series,visualMap,etc. are R-counted (1,2...)\cr
#'
#' **Presets**: \cr
#' When a data.frame is chained to _ec.init_, a \href{https://echarts.apache.org/en/option.html#dataset}{dataset} is preset. \cr
#' When data.frame df is chained to _ec.init_, a \href{https://echarts.apache.org/en/option.html#dataset}{dataset} is preset. \cr
#' When the data.frame is grouped and _ctype_ is not null, more datasets with legend and series are also preset. \cr
#' Plugin '3D' is required for 2D series 'scatterGL'. Use _preset=FALSE_ and set explicitly _xAxis_ and _yAxis_. \cr
#' Plugins 'leaflet' and 'world' preset _zoom=6_ and _center_ to the mean of all coordinates. \cr
#' Plugins 'leaflet' and 'world' preset _center_ to the mean of all coordinates from df. \cr
#' Users can delete or overwrite any presets as needed. \cr
#'
#' **Widget attributes**: \cr
Expand Down Expand Up @@ -159,7 +159,7 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
# remove the above attributes since they are not valid ECharts options
opt1$ask <- opt1$js <- opt1$renderer <- opt1$locale <- NULL
opt1$useDirtyRect <- opt1$elementId <- opt1$xtKey <- NULL
axis2d <- c('pictorialBar','candlestick','boxplot','custom','scatterGL')
axis2d <- c('pictorialBar','candlestick','boxplot','scatterGL') #'custom',

# forward widget options using x
x <- list(
Expand Down Expand Up @@ -251,11 +251,15 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
if (!is.null(opt1$geo3D)) ser$coordinateSystem <- 'geo3D'
if (!is.null(opt1$globe)) ser$coordinateSystem <- 'globe'
}
if (!is.null(opt1$geo) && ser$type %in% c('scatter','scatterGL','lines'))
ser$coordinateSystem <- 'geo'
if (ser$type %in% c('scatter','scatterGL','lines')) {
if (!is.null(opt1$geo)) ser$coordinateSystem <- 'geo'
if ('world' %in% opt1$load) ser$coordinateSystem <- 'geo'
if ('leaflet' %in% opt1$load) ser$coordinateSystem <- 'leaflet'
}
#if (!is.null(opt1$leaflet)) ser$coordinateSystem <- 'leaflet'

if (!is.null(opt1$calendar) && ser$type %in% c('heatmap','scatter','effectScatter'))
ser$coordinateSystem <- 'calendar'
if (!is.null(opt1$leaflet)) ser$coordinateSystem <- 'leaflet'
#if (!is.null(opt1$radar)) series?$type <- 'radar'
if (ser$type == 'parallel') {
if (is.null(opt1$parallelAxis) && !is.null(df))
Expand Down Expand Up @@ -288,25 +292,19 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
is.null(vm$min) && is.null(vm$max) &&
(is.null(vm$type) || (vm$type == 'continuous')) ) {

if (any(names(df) == 'value') && (
(!is.null(tl.series) && tl.series$type=='map') ||
(!is.null(series.param) && series.param$type=='map'))
)
# get min/max from df, despite conversion df to series.data
out <- list( # for tl.series 'map'
min= min(na.omit(df$value)),
max= max(na.omit(df$value)),
calculable= TRUE
)
else {
xx <- length(colnames(df)) # last column by default in ECharts
xx <- length(colnames(df)) # last numeric column by default
for(xx in xx:1) if (is.numeric(df[,xx])) break
if (any(names(df) == 'value') && (
(!is.null(tl.series) && tl.series$type=='map') ||
(!is.null(series.param) && series.param$type=='map'))
) xx <- 'value'
if (!is.null(vm$dimension)) xx <- vm$dimension
out <- list(
#dimension= xx,
min= min(na.omit(df[,xx])),
max= max(na.omit(df[,xx])),
calculable= TRUE
)
}
}
out
}
Expand Down Expand Up @@ -506,16 +504,17 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
# WARN: duplicate maps if series have map='world' too
if (!'geo' %in% names(opt1))
wt$x$opts$geo = list(map='world', roam=TRUE)
else
wt$x$opts$geo = .merlis(wt$x$opts$geo, list(map='world'))
if (is.null(wt$x$opts$geo$roam))
wt$x$opts$geo$roam <- TRUE
# else {
# wt$x$opts$geo = .merlis(wt$x$opts$geo, list(map='world'))
# if (is.null(wt$x$opts$geo$roam)) wt$x$opts$geo$roam <- TRUE
# }
# if (!is.null(df)) # cancelled: don't know if df first 2 cols are 'lng','lat'
# wt$x$opts$geo$center= c(mean(unlist(df[,1])), mean(unlist(df[,2])))
}
}

if ('leaflet' %in% load) {
stopifnot("ec.init: library 'leaflet' not installed"= file.exists(file.path(.libPaths(), 'leaflet')[[1]]))
if (preset) {
# customizations for leaflet
wt$x$opts$xAxis <- wt$x$opts$yAxis <- NULL
Expand Down Expand Up @@ -605,7 +604,7 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,

if ('wordcloud' %in% load)
wt <- ec.plugjs(wt,
paste0(cdn,'echarts-wordcloud@2.0.0/dist/echarts-wordcloud.min.js'), ask)
paste0(cdn,'echarts-wordcloud@latest/dist/echarts-wordcloud.min.js'), ask)

# load unknown plugins
unk <- load[! load %in% c('leaflet','custom','world','lottie','ecStat',
Expand Down Expand Up @@ -654,11 +653,16 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
if (!is.null(tmp$c)) tl.series$coordinateSystem <- tmp$c

if (any(c('geo','leaflet') %in% tl.series$coordinateSystem)) {
xtem <- 'lng'; ytem <- 'lat'
if (!is.null(unlist(tl.series$encode[xtem])) &&
!is.null(unlist(tl.series$encode[ytem])) ) {
center <- c(mean(unlist(df[,tl.series$encode$lng])),
mean(unlist(df[,tl.series$encode$lat])))
klo <- 'lng'; kla <- 'lat'
if (!is.null(tl.series$encode)) {
klo <- unlist(tl.series$encode[klo]);
kla <- unlist(tl.series$encode[kla]);
if (is.numeric(klo)) klo <- colnames(df)[[klo]]
if (is.numeric(kla)) kla <- colnames(df)[[kla]]
}
if (all(c(klo,kla) %in% colnames(df))) {
center <- c(mean(unlist(df[,klo])),
mean(unlist(df[,kla])))
if (tl.series$coordinateSystem=='geo')
wt$x$opts$geo$center <- center
if (tl.series$coordinateSystem=='leaflet')
Expand Down
Loading

0 comments on commit 2ca110f

Please sign in to comment.