Skip to content

Commit 9221080

Browse files
committed
v.1.5.0
1 parent 5cd79a3 commit 9221080

File tree

10 files changed

+1262
-1135
lines changed

10 files changed

+1262
-1135
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: 2022-11-03
4-
Version: 1.4.7.06
3+
Date: 2022-11-22
4+
Version: 1.5.0
55
Authors@R: c(
66
person("Larry", "Helgason", email = "larry@helgasoft.com", role = c("cre", "aut", "cph")),
77
person("John", "Coene", role = c("aut", "cph"), comment = "echarts4r library")

NEWS.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# history of package _echarty_
22

3-
## v.1.4.7.06 in development
3+
## v.1.5.0 in development
44

55
- upgrade ECharts to v.5.4.0
6+
- built with R v.4.2.2
67
- added vignette with introduction
78
- _ecr.ebars_ fix bug, enhance tooltips
89
- _ec.util_ improvements in sf.series
9-
- _ec.util_ new commands _fullscreen_, _morph_, _rescale_
10+
- _ec.util_ new commands _fullscreen_(multi-charts), _morph_, _rescale_, _level_
1011
- _ec.clmn_ new options 'json' and 'log'
11-
- _ec.init_ added visualMap$dimension counting in R
12+
- _ec.init_ set R-counting for series$encode/xAxisIndex, visualMap$dimension
1213
- fixes to global options theme & font, group legend
1314
- fixed _load='world'_ with series set
14-
- new _load='lottie'_, lotties's support now built-in
15+
- new _load='lottie'_, lotties support now built-in
1516
- reorganize crosstalk code
1617

1718
## v.1.4.7 on CRAN

R/echarty.R

Lines changed: 1028 additions & 955 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ downloads](https://cranlogs.r-pkg.org/badges/last-day/echarty)](https://cranlogs
1818
<a href='https://helgasoft.github.io/echarty'><img src="man/figs/echarty.gallery.png" alt="echarty.gallery" /></a>
1919

2020
This package is a thin R wrapper around Javascript library
21-
[ECharts](https://echarts.apache.org/en/index.html). A few commands use R lists to enclose the entire [ECharts API](https://echarts.apache.org/en/option.html).
21+
[ECharts](https://echarts.apache.org/en/index.html).
22+
Two major commands use R lists to enclose the entire [ECharts API](https://echarts.apache.org/en/option.html).
2223
Users can benefit from ECharts **full functionality** to build
2324
interactive charts in R and Shiny with minimal overhead.
2425

@@ -28,8 +29,8 @@ support](https://helgasoft.github.io/echarty/xtalk.html).
2829

2930
## Installation
3031

31-
<!-- [![Github version](https://img.shields.io/github/v/release/helgasoft/echarty?label=github)](https://github.com/helgasoft/echarty/releases) -->
32-
Latest development build <strong>1.4.7<sup>.06</sup></strong>
32+
<!-- [![Github version](https://img.shields.io/github/v/release/helgasoft/echarty?label=github)](https://github.com/helgasoft/echarty/releases) <sup>.07</sup> -->
33+
Latest development build <strong>1.5.0</strong>
3334

3435
``` r
3536
if (!requireNamespace('remotes')) install.packages('remotes')

inst/htmlwidgets/echarty.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ HTMLWidgets.widget({
3333
{ svg: x.registerMap[map].svg });
3434
}
3535
}
36-
37-
ecfun.hwid = el.id;
38-
if (window.onresize==undefined)
39-
window.onresize = function() {
40-
chart.resize();
41-
ecfun.fs = ecfun.IsFullScreen(); // handle ESC key
42-
}
4336

4437
let eva2 = eva3 = null;
4538
if (x.hasOwnProperty('jcode')) {
@@ -60,7 +53,15 @@ HTMLWidgets.widget({
6053
chart = echarts.init(document.getElementById(el.id), x.theme,
6154
{renderer: x.renderer, locale: x.locale, useDirtyRect: x.useDirtyRect});
6255

56+
if (window.onresize==undefined)
57+
window.onresize = function() {
58+
chart.resize();
59+
ecfun.fs = ecfun.IsFullScreen(); // handle ESC key
60+
}
61+
6362
opts = x.opts;
63+
opts.hwid = el.id; // fullscreen support, multiple charts
64+
window.hwid = el.id; // save for single charts
6465

6566
if (eva2) { // #2 to change opts
6667
try {
@@ -77,7 +78,7 @@ HTMLWidgets.widget({
7778
} catch(err) { console.log('eva3: ' + err.message) }
7879
}
7980

80-
if (opts.graphic && lottieParser) {
81+
if (opts.graphic && typeof lottieParser!=undefined) {
8182
tmp = ecfun.lottieGraphic(opts.graphic);
8283
chart.setOption({graphic: tmp}, { replaceMerge: 'graphic'});
8384
}
@@ -303,7 +304,7 @@ ecfun = {
303304
},
304305

305306
fs: false, // fullscreen flag Y/N
306-
fscreen: function() {
307+
fscreen: function(hwid) {
307308
// see also window.onresize
308309
function GoInFullscreen(element) {
309310
if (element.requestFullscreen)
@@ -331,7 +332,7 @@ ecfun = {
331332
GoOutFullscreen();
332333
}
333334
else {
334-
tmp = document.getElementById(ecfun.hwid);
335+
tmp = document.getElementById(hwid);
335336
GoInFullscreen(tmp)
336337
}
337338
this.fs = !this.fs;

man/Introduction.Rd

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

man/ec.util.Rd

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

tests/testthat/test-ec.clmn.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test_that("ec.clmn tabset", {
7676

7777
test_that("ec.clmn morph", {
7878
setd <- function(type) {
79-
mtcars |> group_by(cyl) |> ec.init(ctype=type) |> ec.upd({
79+
mtcars |> group_by(cyl) |> ec.init(ctype= type) |> ec.upd({
8080
title <- list(subtext='mouseover points to morph')
8181
xAxis <- list(scale=TRUE)
8282
series <- lapply(series, function(ss) {

tests/testthat/test-ec.util.R

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
2+
test_that("serie from ec.util with cartesian3D", {
3+
# usage for LIDAR data
4+
library(sf)
5+
tmp <- st_as_sf(data.frame(x=c(-70,-70,-70), y=c(45, 46, 47), z=c(1,2,3)),
6+
coords= c('x','y','z'), crs= st_crs(4326))
7+
p <- ec.init(load= c('3D'),
8+
series= ec.util(df= tmp,
9+
coordinateSystem= 'cartesian3D', type= 'scatter3D')
10+
#,tooltip= list(formatter= '{b}')
11+
)
12+
expect_equal(p$x$opts$series[[1]]$data[[2]][[2]], 46)
13+
expect_type( p$x$opts$xAxis3D[[1]],'list')
14+
})
15+
16+
test_that("shapefiles with multi-polygons", {
17+
library(sf)
18+
fname <- system.file("shape/nc.shp", package="sf")
19+
nc <- as.data.frame(st_read(fname))
20+
p <- ec.init(load= c('leaflet', 'custom'), # load custom for polygons
21+
js= ec.util(cmd= 'sf.bbox', bbox= st_bbox(nc$geometry)),
22+
series= ec.util(cmd= 'sf.series', df= nc, nid= 'NAME', itemStyle= list(opacity= 0.3)),
23+
tooltip= list(show= TRUE, formatter= '{a}')
24+
)
25+
expect_true(p$x$opts$leaflet$roam)
26+
expect_equal(p$x$opts$series[[108]]$name, 'Brunswick')
27+
expect_equal(p$x$opts$series[[108]]$itemStyle$opacity, 0.3)
28+
})
29+
30+
test_that("shapefile from ZIP", {
31+
if (interactive()) { # creates a subfolder 'railways'
32+
library(sf)
33+
fname <- ec.util(cmd= 'sf.unzip',
34+
url= 'https://mapcruzin.com/sierra-leone-shapefiles/railways.zip')
35+
nc <- as.data.frame(st_read(fname))
36+
p <- ec.init(load= 'leaflet',
37+
js= ec.util(cmd= 'sf.bbox', bbox= st_bbox(nc$geometry)),
38+
series= ec.util(df= nc, nid= 'osm_id', verbose=TRUE,
39+
lineStyle= list(width= 3, color= 'red')),
40+
tooltip= list(formatter= '{a}'), animation= FALSE,
41+
leaflet= list(tiles= list(list(
42+
urlTemplate= 'https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}{r}.{ext}',
43+
options= list(attribution= 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>',
44+
subdomains= 'abcd', maxZoom= 18, ext= 'png'))))
45+
)
46+
expect_equal(p$x$opts$leaflet$tiles[[1]]$options$subdomains, 'abcd')
47+
expect_equal(p$x$opts$series[[6]]$name, '207557821')
48+
expect_equal(p$x$opts$series[[6]]$lineStyle$color, 'red')
49+
50+
}
51+
else expect_equal(1,1)
52+
})
53+
54+
test_that("tabset", {
55+
p1 <- cars |> ec.init(width= 300, height= 300, grid= list(top= 20))
56+
p2 <- mtcars |> ec.init(width= 300, height= 300)
57+
r <- htmltools::browsable(
58+
ec.util(cmd='tabset', cars=p1, mtcars=p2)
59+
)
60+
expect_equal(r[[2]]$children[[5]]$children[[1]]$children[[1]][[1]]$x$opts$dataset[[1]]$source[[1]], c("speed", "dist"))
61+
expect_equal(r[[2]]$children[[5]]$children[[1]]$name, "section")
62+
expect_equal(r[[2]]$children[[2]]$children[[1]], "cars")
63+
})
64+
65+
test_that("tabset with pipe", {
66+
library(dplyr)
67+
r <- htmltools::browsable(
68+
lapply(iris |> group_by(Species) |> group_split(), function(x) {
69+
x |> ec.init(ctype= 'scatter', title= list(text= unique(x$Species)))
70+
}) |> ec.util(cmd='tabset')
71+
)
72+
expect_equal(r[[2]]$children[[7]]$children[[2]]$children[[1]][[1]]$width, 300)
73+
expect_equal(r[[2]]$children[[6]]$children[[1]], "chart3")
74+
})
75+
76+
test_that("morph", {
77+
mc <- mtcars |> filter(cyl<8)
78+
datt <- function(idx) { return(mc[mc$cyl==idx,]$hp) }
79+
colors <- c("blue","red","green","yellow")
80+
81+
oscatter <- list(
82+
xAxis= list(scale=TRUE),
83+
yAxis= list(scale=TRUE), color= colors,
84+
series=list(
85+
list(type='scatter', id=4, dataGroupId=4, data= datt(4),
86+
universalTransition= list(enabled= TRUE)),
87+
list(type='scatter', id=6, dataGroupId=6, data= datt(6),
88+
universalTransition= list(enabled=TRUE))
89+
)
90+
)
91+
obar <- list(
92+
title= list(text= 'Average'),
93+
xAxis= list(type= 'category', data= list('cyl4', 'cyl6')),
94+
yAxis= list(show= TRUE), color= colors,
95+
series= list(list(
96+
type= 'bar', id= 'average', colorBy= 'data',
97+
data= list(
98+
list(value= mean(datt(4)), groupId=4),
99+
list(value= mean(datt(6)), groupId=6)),
100+
universalTransition=list(enabled= TRUE,
101+
seriesKey=c(4, 6))
102+
))
103+
)
104+
105+
auto <- " cnt = 0;
106+
setInterval(() => {
107+
cnt++;
108+
opts= chart.getOption();
109+
optcurr= Object.assign({}, opts.morph[cnt % 2]);
110+
optcurr.morph= opts.morph;
111+
chart.setOption(optcurr, true);
112+
}, 2000);
113+
"
114+
p <- ec.util(cmd='morph', oscatter, obar, js=auto)
115+
expect_equal(p$x$opts$morph[[1]]$series[[1]]$type, 'scatter')
116+
expect_equal(p$x$opts$morph[[2]]$series[[1]]$type, 'bar')
117+
expect_true(grepl('setInterval', p$x$jcode, fixed=TRUE))
118+
p <- ec.util(cmd='morph', oscatter, obar)
119+
expect_equal(p$x$on[[1]]$event, 'mouseover')
120+
})
121+
122+
test_that("fullscreen", {
123+
tbox <- list(right='20%', feature= ec.util(cmd='fullscreen'))
124+
#p <- cars |> ec.init(toolbox= tbox)
125+
#expect_match(p$x$opts$toolbox$feature$myecfs$onclick, 'ecfun.fscreen', fixed=TRUE)
126+
p <- crosstalk::bscols(
127+
cars |> ec.init(toolbox= tbox),
128+
mtcars |> ec.init(toolbox= tbox) |>
129+
htmlwidgets::prependContent(
130+
htmltools::tags$style(
131+
".echarty:fullscreen { background-color: beige; }"
132+
)
133+
)
134+
)
135+
expect_match(p$children[[1]]$children[[1]][[1]]$children[[1]]$x$opts$toolbox$feature$myecfs$onclick, 'ecfun.fscreen(tmp.hwid)', fixed=TRUE)
136+
expect_match(p$children[[1]]$children[[1]][[2]]$children[[1]]$prepend[[1]]$children[[1]], '.echarty:fullscreen', fixed=TRUE)
137+
})
138+
139+
test_that("rescale", {
140+
p <- ec.util(cmd='rescale', t=c(5,25), v=44:64)
141+
expect_equal(p[5], 9)
142+
})
143+
144+
test_that("level", {
145+
tmp <- "id,from,to
146+
1,2020-03-03,2020-05-03
147+
2,2020-01-03,2020-03-13
148+
3,2020-06-03,2020-07-03
149+
"
150+
df <- read.table(text=tmp, header= TRUE, sep=',')
151+
p <- ec.util(cmd='level', df=df)
152+
expect_equal(p, c(1,2,1))
153+
})
154+
155+
test_that("labelsInside", {
156+
p <- ec.init(
157+
xAxis= list(data= list(1,2,3,4,5,6,7)),
158+
yAxis= list(type= 'value'),
159+
series= list(
160+
list(name= 'long text, 20 chars', type='line',
161+
data= c(110, 132, 101, 134, 90, 230, 210),
162+
endLabel= list( show=TRUE, formatter='{a}'),
163+
labelLayout= ec.util(cmd='labelsInside')),
164+
list(name='longer text, this is 35 characters',type='line',
165+
data= c(210, 232, 201,234, 290, 240, 230),
166+
endLabel=list(show=TRUE, formatter='{a}'),
167+
labelLayout= ec.util(cmd='labelsInside'))
168+
)
169+
)
170+
expect_match(p$x$opts$series[[2]]$labelLayout, "get_e_charts(cid)", fixed=TRUE)
171+
})

0 commit comments

Comments
 (0)