Skip to content

Commit

Permalink
dev 1.6.3.02
Browse files Browse the repository at this point in the history
  • Loading branch information
helgasoft committed May 3, 2024
1 parent f4c1d98 commit ca9f273
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 126 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: 2024-02-24
Version: 1.6.3.01
Version: 1.6.3.02
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 @@ -19,10 +19,10 @@ Suggests:
sf,
knitr,
rmarkdown
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
License: Apache License (>= 2.0)
URL: https://github.com/helgasoft/echarty, https://helgasoft.github.io/echarty/
URL: https://helgasoft.github.io/echarty/
BugReports: https://github.com/helgasoft/echarty/issues/
Encoding: UTF-8
Language: en-US
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# history of package _echarty_

## v.1.6.3.01 latest in development
## v.1.6.3.02 latest in development

- upgrade ECharts to v.5.5.0, built with R v.4.3.2
- 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_

## v.1.6.3 on CRAN

Expand Down
120 changes: 66 additions & 54 deletions R/echarty.R
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,14 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,

}

#wt$dependencies <- append(wt$dependencies, htmlwidgets::getDependency('leaflet')) # working with leaflet <=v.2.1.0
wt$dependencies <- append(wt$dependencies, list( htmltools::htmlDependency(
name= "leaflet", version= "1.3.1", package= "leaflet", src= "htmlwidgets/lib/leaflet",
script= "leaflet.js", stylesheet= "leaflet.css") )
)
dep <- htmltools::htmlDependency(
name = 'echarts-leaflet',
version = '1.0.0', src = c(file = path),
script='echarts-leaflet.js')
wt$dependencies <- append(wt$dependencies, htmlwidgets::getDependency('leaflet'))
name= 'echarts-leaflet', version= '1.0.0', src= c(file= path),
script= 'echarts-leaflet.js')
wt$dependencies <- append(wt$dependencies, list(dep))
}
if ('custom' %in% load) {
Expand Down Expand Up @@ -625,17 +628,19 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,
}


# ------------- timeline -----------------
# ------------- timeline is last -----------------
if (is.null(tl.series) && is.null(opt1$timeline)) return(wt)
if (!preset) return(wt)
# timeline is evaluated last
if (!is.null(opt1$options) && !is.null(opt1$timeline))
return(wt) # both set manually

if (is.null(tl.series) &&
!is.null(opt1$timeline) &&
!is.null(series.param))
tl.series <- series.param

if (is.null(df) || !is.grouped_df(df))
stop('ec.init: tl.series requires a grouped data.frame df')
stop('ec.init: timeline requires a grouped data.frame df')

if (is.null(tl.series$encode))
tl.series$encode <- list(x=1, y=2, z=3) # set default for non-map series
Expand Down Expand Up @@ -706,7 +711,6 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,

#wt$x$opts$xAxis <- list(type='category') # geo,leaf do not like
wt$x$opts$series <- NULL # otherwise legend + scatter series may stay behind
# wt$x$opts$legend <- NULL
wt$x$opts$options <- .merlis(optl, wt$x$opts$options)

if (!is.null(tl.series$groupBy)) {
Expand Down Expand Up @@ -759,25 +763,28 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,

#' Update option lists
#'
#' And improve readability by chaining commands after ec.init
#' Chain commands after ec.init to add or update chart items
#'
#' @param wt An echarty widget
#' @param ... R commands to update chart option lists
#' @param ... R commands to add/update chart option lists
#'
#' @details ec.upd makes changes to chart elements already set by ec.init.\cr
#' It should be always piped after ec.init.\cr
#' All numerical indexes for series,visualMap,etc. are JS-counted (start at 0)\cr
#' Replaces syntax\cr
#' \verb{ }p <- ec.init(...)\cr
#' \verb{ }p$x$opts$series <- ...\cr
#' with\cr
#' \verb{ }ec.init(...) |> \verb{ } # set or preset chart params\cr
#' \verb{ }ec.upd(\{series <- ...\}) # update params thru R commands
#' @details \emph{ec.upd} makes changes to a chart already set by [ec.init].\cr
#' It should be always piped(chained) after [ec.init].\cr
#' All numerical indexes for series,visualMap,etc. are JS-counted and start at 0.\cr
#' @examples
#' Orange |> dplyr::group_by(Tree) |>
#' ec.init(series.param= list(universalTransition= list(enabled=TRUE))) |>
#' ec.upd({
#' series <- lapply(series, function(ss) { ss$groupId <- ss$name; ss })
#' library(dplyr)
#' df <- data.frame(x= 1:30, y= runif(30, 5, 10), cat= sample(LETTERS[1:3],size=30,replace=TRUE)) |>
#' mutate(lwr= y-runif(30, 1, 3), upr= y+runif(30, 2, 4))
#' band.df <- df |> group_by(cat) |> group_split()
#'
#' df |> group_by(cat) |>
#' ec.init(load='custom', ctype='line',
#' xAxis=list(data=c(0,unique(df$x)), boundaryGap=FALSE) ) |>
#' ec.upd({
#' for(ii in 1:length(band.df)) # add bands to their respective groups
#' series <- append(series,
#' ecr.band(band.df[[ii]], 'lwr', 'upr', type='stack', smooth=FALSE,
#' name= unique(band.df[[ii]]$cat), areaStyle= list(color=c('blue','green','yellow')[ii])) )
#' })
#' @export
ec.upd <- function(wt, ...) {
Expand Down Expand Up @@ -805,37 +812,32 @@ ec.upd <- function(wt, ...) {
#'
#' @details
#' \itemize{
#' \item type='polygon': coordinates of the two boundaries are chained into one polygon. Tooltips do not show upper band values.\cr
#' _xAxis type_ could be 'category' or 'value'.\cr
#' Set fill color with attribute _color_.\cr
#' \item type='stack': two _stacked_ lines are drawn, the lower with customizable areaStyle.\cr
#' _xAxis type_ should be 'category'! Tooltips could include upper band values.\cr
#' Set fill color with attribute _areaStyle$color_.\cr
#' \item type='polygon': coordinates of the two boundaries are chained into one polygon.\cr
#' \verb{ }_xAxis type_ could be 'category' or 'value'.\cr
#' \verb{ }Set fill color with attribute _color_.
#' \item type='stack': two _stacked_ lines are drawn, the lower with customizable areaStyle.\cr
#' \verb{ }_xAxis type_ should be 'category' ! \cr
#' \verb{ }Set fill color with attribute _areaStyle$color_.\cr
#' \verb{ }Optional tooltip formatter available in _band\[\[1\]\]$tipFmt_.
#' }
#' Optional parameter _name_, if given, will show up in legend. Legend merges all series with same name into one item.
#'
#' @examples
#' df <- airquality |> dplyr::mutate(
#' lwr= round(Temp-Wind*2),
#' upr= round(Temp+Wind*2),
#' x= paste0(Month,'-',Day) ) |>
#' dplyr::relocate(x, Temp)
#' bands <- ecr.band(df, 'lwr', 'upr', type='stack',
#' name= 'stak', areaStyle= list(opacity=0.4))
#' df |> ec.init( load= 'custom',
#' legend= list(show= TRUE),
#' dataZoom= list(type= 'slider'),
#' toolbox= list(feature= list(dataZoom= list(show= TRUE))),
#' xAxis= list(type= 'category', boundaryGap= FALSE),
#' series= list(
#' list(type='line', color='blue', name='line'),
#' bands[[1]], bands[[2]]
#' ),
#' tooltip= list( trigger= 'axis',
#' formatter= ec.clmn(
#' 'high <b>%@</b><br>line <b>%@</b><br>low <b>%@</b>',
#' 3.3, 1.2, 2.2)
#' ) # 3.3= upper_serie_index +.+ index_of_column_inside
#' set.seed(222)
#' df <- data.frame( x = 1:10, y = round(runif(10, 5, 10),2)) |>
#' dplyr::mutate(lwr= round(y-runif(10, 1, 3),2), upr= round(y+runif(10, 2, 4),2) )
#' banda <- ecr.band(df, 'lwr', 'upr', type='stack', name='stak', areaStyle= list(color='green'))
#' #banda <- ecr.band(df, 'lwr', 'upr', type='polygon', name='poly1')
#'
#' df |> ec.init( load='custom', # polygon only
#' legend= list(show= TRUE),
#' xAxis= list(type='category', boundaryGap=FALSE), # stack
#' #xAxis= list(scale=T, min='dataMin'), # polygon
#' series= append(
#' list(list(type='line', color='blue', name='line1')),
#' banda
#' ),
#' tooltip= list(trigger='axis', formatter= banda[[1]]$tipFmt)
#' )
#'
#' @importFrom stats na.omit
Expand All @@ -851,9 +853,15 @@ ecr.band <- function(df=NULL, lower=NULL, upper=NULL, type='polygon', ...) {
df <- na.omit(df)

if (type=='stack') {
tipFmt <- "(ss) => { lo=''; hi=''; lin='';
ss.map(o => { nn = o.dimensionNames[1]; vv= o.value[1];
if (nn==='.s.lo') lo= vv;
else if (nn==='.s.hi') hi= vv;
else lin= '<br>line <b>'+vv+'</b>'; });
str='high <b>'+(lo+hi)+'</b>'+lin+'<br>low <b>'+lo+'</b>'; return str;}" # stack only
colr <- paste("new echarts.graphic.LinearGradient(0, 0, 0, 1, [",
"{offset: 0, color: 'rgba(255, 0, 135)'},",
"{offset: 1, color: 'rgba(135, 0, 157)'}]);")
"{offset: 0, color: 'rgba(255, 0, 135)'},",
"{offset: 1, color: 'rgba(135, 0, 157)'}]);")
defStyle <- list(opacity = 0.8, color = htmlwidgets::JS(colr))

slow <- list(type='line', ...)
Expand All @@ -867,10 +875,13 @@ ecr.band <- function(df=NULL, lower=NULL, upper=NULL, type='polygon', ...) {
if (is.null(supr$areaStyle)) supr$areaStyle <- defStyle
# save upper data for tooltip, 'hi' values are just differences
tmp <- data.frame(x = df[fstc][[1]], lo=df[lower][[1]],
hi = df[upper][[1]] - df[lower][[1]],
hi = df[upper][[1]] - df[lower][[1]], # for stacked line
ttip = df[upper][[1]] )
slow$data <- ec.data(tmp[,c('x','lo')])
supr$data <- ec.data(tmp[,c('x','hi','ttip')])
supr$dimensions <- c('x','.s.hi','.s.tip')
slow$tipFmt <- ec.clmn(tipFmt) # simple optional tooltip
slow$dimensions <- c('x','.s.lo')
serios <- list(slow, supr)
}
else { # polygon
Expand All @@ -885,6 +896,7 @@ ecr.band <- function(df=NULL, lower=NULL, upper=NULL, type='polygon', ...) {
if (is.null(serios$itemStyle)) serios$itemStyle <- list(borderWidth = 0.5)
if (is.null(serios$boundaryGap)) serios$boundaryGap <- FALSE
serios <- list(serios) # keep consistent with stack type
serios$tipFmt <- NULL
}
serios
}
Expand Down Expand Up @@ -1307,7 +1319,7 @@ ec.plugjs <- function(wt=NULL, source=NULL, ask=FALSE) {
#'
#' Original work Copyright 2018 John Coene
#'
#' Modified work Copyright 2021 Larry Helgason
#' Modified work Copyright 2021-2024 Larry Helgason
#'
#' Licensed under the Apache License, Version 2.0 (the "License");
#' you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ body { padding: 10px; }
#' * _layout_ = 'h' for horizontal(default) or 'v' for vertical layout\cr
#' * _outliers_ boolean to add outlier points (default FALSE)\cr
#' * _jitter_ value for \link[base]{jitter} of numerical values in second column, default 0 (no scatter). Adds scatter series on top of boxplot.\cr
#'
#' Optional parameter for **names**:\cr
#' * _nasep_ = single character name separator for nested lists, see Examples. \cr
#' Purpose is to facilitate conversion from _data.frame_ to nested named lists.\cr
Expand Down Expand Up @@ -1307,7 +1308,7 @@ ec.fromJson <- function(txt, ...) {

#' ------------- Licence -----------------
#'
#' Original work Copyright 2023 Larry Helgason
#' Original work Copyright 2021-2024 Larry Helgason
#'
#' Licensed under the Apache License, Version 2.0 (the "License");
#' you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ lines of code | 1,202,623 [![link](man/figs/external-link-16.png)](https://api.c
API design <sup>(1)</sup>| own commands with parameters | mostly [ECharts option](https://echarts.apache.org/en/option.html) lists
number of commands | over [200](https://echarts4r.john-coene.com/reference/) | **one** command + optional utilities
data storage support | series data | **[datasets](https://echarts.apache.org/en/option.html#dataset)**, series data
dependencies | 175 | 48
[crosstalk](https://rstudio.github.io/crosstalk/) support | no | **yes**
[WebR](https://docs.r-wasm.org/webr/latest/) support | no | **yes**
utilities | bezier, correlations, histogram, density, loess, flip, nesting, more | extended boxplots, tabsets, layouts, shapefiles, lotties, more
Expand All @@ -53,7 +54,7 @@ Please consider granting a Github star ⭐ to show your support.
## Installation

<!-- [![Github version](https://img.shields.io/github/v/release/helgasoft/echarty?label=github)](https://github.com/helgasoft/echarty/releases) <sup>.02</sup> -->
Latest development build <strong>1.6.3.01</strong>
Latest development build <strong>1.6.3.02</strong>

``` r
if (!requireNamespace('remotes')) install.packages('remotes')
Expand Down Expand Up @@ -93,7 +94,7 @@ ec.init(
)
)

# show a remote chart
# show a remote map chart, needs leaflet package (>=v.2.2) installed
echarty::ec.fromJson('https://helgasoft.github.io/echarty/test/pfull.json')

```
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/echarty.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ if (HTMLWidgets.shinyMode) {
---------------------------------------
Original work Copyright 2018 John Coene
Modified work Copyright 2021 Larry Helgason
Modified work Copyright 2021-2024 Larry Helgason
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion inst/js/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function riOutliers(params, api) {
/*
------------- Licence -----------------
Original work Copyright 2023 Larry Helgason
Original work Copyright 2021-2024 Larry Helgason
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions inst/themes/dark-mushroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
},

gauge: {
title: { color: '#aaa'},
axisLine: {
lineStyle: {
color: [
Expand Down
3 changes: 3 additions & 0 deletions man/ec.data.Rd

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

33 changes: 18 additions & 15 deletions man/ec.upd.Rd

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

Loading

0 comments on commit ca9f273

Please sign in to comment.