Skip to content

Commit

Permalink
tl map
Browse files Browse the repository at this point in the history
  • Loading branch information
helgasoft committed Nov 28, 2023
1 parent ed5bc55 commit 8220ac3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: echarty
Title: Minimal R/Shiny Interface to JavaScript Library 'ECharts'
Date: 2023-11-23
Date: 2023-11-28
Version: 1.6.2.01
Author: Larry Helgason, with initial code from John Coene's library echarts4r
Maintainer: Larry Helgason <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- add default _coordinateSystem_ for 3D charts
- fix _datasetIndex_ for timeline 3D series
- add _encode_ default, improve _ec.init_ docs
- fix _tl.series_ type 'map' encode

## v.1.6.2 on CRAN

Expand Down
20 changes: 12 additions & 8 deletions R/echarty.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ the$.ecv.colnames <- NULL
#' **\href{https://echarts.apache.org/en/option.html#series-line.encode}{Encode}** \cr
#' A series attribute to define which columns to use for the axes, depending on chart type and coordinate system: \cr
#' * set _x_ and _y_ for coordinateSystem _cartesian2d_
#' * set _lng_ and _lat_ for coordinateSystem _geo_
#' * set _lng_ and _lat_ for coordinateSystem _geo_ and _scatter_ series
#' * set _value_ and _name_ for coordinateSystem _geo_ and _map_ series
#' * set _radius_ and _angle_ for coordinateSystem _polar_
#' * set _value_ and _itemName_ for _pie_ chart
#' * set _value_ and _name_ for _map_ chart
#' Example: \code{encode(x='col3', y='col1')} binds xAxis to _df_ column 'col3'.
#'
#' @return A widget to plot, or to save and expand with more features.
Expand Down Expand Up @@ -580,16 +580,20 @@ ec.init <- function( df= NULL, preset= TRUE, ctype= 'scatter', ...,

if (tl.series$coordinateSystem %in% c('geo','leaflet')) {
xtem <- 'lng'; ytem <- 'lat'
center <- c(mean(unlist(df[,tl.series$encode$lng])),
mean(unlist(df[,tl.series$encode$lat])))
if (tl.series$coordinateSystem=='geo')
wt$x$opts$geo$center <- center
if (tl.series$coordinateSystem=='leaflet')
wt$x$opts$leaflet$center <- center
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])))
if (tl.series$coordinateSystem=='geo')
wt$x$opts$geo$center <- center
if (tl.series$coordinateSystem=='leaflet')
wt$x$opts$leaflet$center <- center
}
}

if (tl.series$type == 'map') {
# tl.series type='map' has no encode/dataset API, needs 'data'
xtem <- 'name'; ytem <- 'value'
wt$x$opts$dataset <- NULL
stopifnot("tl.series: encode 'name' is required"= !is.null(unlist(tl.series$encode[xtem])))
stopifnot("tl.series: encode 'value' is required"= !is.null(unlist(tl.series$encode[ytem])))
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
[![Coveralls test coverage](https://coveralls.io/repos/github/helgasoft/echarty/badge.svg)](https://coveralls.io/r/helgasoft/echarty?branch=main)
[![size](https://img.shields.io/github/languages/code-size/helgasoft/echarty)](https://github.com/helgasoft/echarty/releases/)
[![website](https://img.shields.io/badge/Website-Visit-blue)](https://helgasoft.github.io/echarty)
[![website](https://img.shields.io/twitter/follow/echarty.svg?style=social&label=Follow)](https://twitter.com/echarty_R)

<!--
[![CRAN
downloads](https://cranlogs.r-pkg.org/badges/last-day/echarty)](https://cranlogs.r-pkg.org/badges/last-day/echarty) -->
Expand All @@ -25,7 +27,7 @@ interactive charts in R and Shiny with minimal overhead.

Wider connectivity and deployment potential through [crosstalk](https://rpubs.com/echarty/crosstalk).

<details> <summary><strong>Compare to echarts4r</strong></summary>
<details> <summary><strong>Compare to echarts4r 📌</strong></summary>

R package | echarts4r | echarty
--- | --- | ---
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-presets.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ test_that("ec.init presets for timeline groupBy", {
expect_equal(length(p$x$opts$options[[1]]$series), 2)
expect_equal(p$x$opts$options[[4]]$series[[2]]$datasetIndex, 8)
expect_equal(p$x$opts$options[[4]]$series[[2]]$name, 'B')

cns <- data.frame(
country = c('United States','China','Russia'),
val = runif(3, 1, 100)
)
p <- cns |> group_by(country) |>
ec.init(load= 'world',
geo= list(roam=T), tooltip= list(show=T),
tl.series=list(type='map',
encode=list(value='val', name='country')),
visualMap= list(calculable=TRUE)
)
expect_equal(p$x$opts$options[[3]]$series[[1]]$geoIndex,0)
expect_equal(p$x$opts$options[[1]]$series[[1]]$data[[1]]$name, 'China')
expect_equal(p$x$opts$geo$map, 'world')
})

test_that("presets for parallel chart", {
Expand Down

0 comments on commit 8220ac3

Please sign in to comment.