| ec.util {echarty} | R Documentation | 
Utility functions
Description
tabset, table layout, support for GIS shapefiles through library 'sf'
Usage
ec.util(..., cmd = "sf.series", js = NULL)
Arguments
| ... | Optional parameters for the command  | 
| cmd | utility command, see Details | 
| js | optional JavaScript function, default is NULL. | 
Details
cmd = 'sf.series'
 Build leaflet or geo map series from shapefiles.
 Supported types: POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON 
 Coordinate system is leaflet(default), geo or cartesian3D (for POINT(xyz))
 Limitations:
     polygons can have only their name in tooltip,  
     assumes Geodetic CRS is WGS 84, for conversion use st_transform with crs=4326.
 Parameters:
   df - value from st_read
   nid - optional column name for name-id used in tooltips
   cs - optional coordinateSystem value, default 'leaflet'
   verbose - optional, print shapefile item names in console
 Returns a list of chart series
cmd = 'sf.bbox'
 Returns JavaScript code to position a map inside a bounding box from st_bbox, for leaflet only.
cmd = 'sf.unzip'
 Unzips a remote file and returns local file name of the unzipped .shp file
   url - URL of remote zipped shapefile
   shp - optional name of .shp file inside ZIP file if multiple exist. Do not add file extension. 
cmd = 'geojson' 
 Custom series list from geoJson objects
   geojson - object from fromJSON
   cs - optional coordinateSystem value, default 'leaflet'
   ppfill - optional fill color like '#F00', OR NULL for no-fill, for all Points and Polygons
   nid - optional feature property for item name used in tooltips
   ... - optional custom series attributes like itemStyle
 Can display also geoJson feature properties: color; lwidth, ldash (lines); ppfill, radius (points)
cmd = 'layout' 
 Multiple charts in table-like rows/columns format
   ... - List of charts
   title - optional title for the set, rows= Number of rows, cols= Number of columns
 Returns a container div in rmarkdown, otherwise browsable.
 For 3-4 charts one would use multiple series within a grid. 
 For greater number of charts ec.util(cmd='layout') comes in handy
cmd = 'tabset' 
   ... - a list name/chart pairs like n1=chart1, n2=chart2, each tab may contain a chart.
   tabStyle - tab style string, see default tabStyle variable in the code
 Returns A) tagList of tabs when in a pipe without '...' params, see example
 Returns B) browsable when '...' params are provided by user
cmd = 'button' 
 UI button to execute a JS function,
   text - the button label
   js - the JS function string
   ... - optional parameters for the rect element
 Returns a graphic.elements-rect element.
cmd = 'morph' 
   ... - a list of charts or chart options
   js - optional JS function for switching charts. Default function is on mouseover. Disable with FALSE.
 Returns a chart with ability to morph into other charts
cmd = 'fullscreen' 
 A toolbox feature to toggle fullscreen on/off. Works in a browser, not in RStudio.
cmd = 'rescale' 
   v - input vector of numeric values to rescale
   t - target range c(min,max), numeric vector of two
cmd = 'level' 
 Calculate vertical levels for timeline line charts, returns a numeric vector
   df - data.frame with from and to columns
   from - name of 'from' column
   to - name of 'to' column
Examples
if (interactive()) {  # comm.out: Fedora errors about some 'browser'
  library(sf)
  fname <- system.file("shape/nc.shp", package="sf")
  nc <- as.data.frame(st_read(fname))
  ec.init(load= c('leaflet', 'custom'),  # load custom for polygons
     js= ec.util(cmd= 'sf.bbox', bbox= st_bbox(nc$geometry)),
     series= ec.util(cmd= 'sf.series', df= nc, nid= 'NAME', itemStyle= list(opacity=0.3)),
     tooltip= list(formatter= '{a}')
  )
  htmltools::browsable(
    lapply(iris |> dplyr::group_by(Species) |> dplyr::group_split(), 
           function(x) {
     x |> ec.init(ctype= 'scatter', title= list(text= unique(x$Species)))
           }) |> 
    ec.util(cmd= 'tabset')
  )
  p1 <- cars |> ec.init(grid= list(top= 20))  # move chart up
  p2 <- mtcars |> ec.init()
  ec.util(cmd= 'tabset', cars= p1, mtcars= p2, width= 333, height= 333)
  lapply(list('dark','macarons','gray','jazz','dark-mushroom'),
                \(x) cars |> ec.init() |> ec.theme(x) ) |>
  ec.util(cmd='layout', cols= 2, title= 'my layout')
  
  setd <- \(type) {
	   mtcars |> group_by(cyl) |> 
	 ec.init(ctype= type,
		  title= list(subtext= 'mouseover points to morph'),
		  xAxis= list(scale= TRUE))
  }
  oscatter <- setd('scatter')
  obar <- setd('bar')
  ec.util(cmd='morph', oscatter, obar)
}