Description Usage Arguments Details Value Examples
View source: R/add_minicharts.R
these functions add or update minicharts in a leaflet map at given coordinates: they can be bar charts, pie charts or polar charts where chartdata is encoded either by area or by radius.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | addMinicharts(
map,
lng,
lat,
chartdata = 1,
time = NULL,
maxValues = NULL,
type = "auto",
fillColor = d3.schemeCategory10[1],
colorPalette = d3.schemeCategory10,
width = 30,
height = 30,
opacity = 1,
showLabels = FALSE,
labelText = NULL,
labelMinSize = 8,
labelMaxSize = 24,
labelStyle = NULL,
transitionTime = 750,
popup = popupArgs(),
layerId = NULL,
legend = TRUE,
legendPosition = "topright",
timeFormat = NULL,
initialTime = NULL,
onChange = NULL,
popupOptions = NULL
)
updateMinicharts(
map,
layerId,
chartdata = NULL,
time = NULL,
maxValues = NULL,
type = NULL,
fillColor = NULL,
colorPalette = d3.schemeCategory10,
width = NULL,
height = NULL,
opacity = NULL,
showLabels = NULL,
labelText = NULL,
labelMinSize = NULL,
labelMaxSize = NULL,
labelStyle = NULL,
transitionTime = NULL,
popup = NULL,
legend = TRUE,
legendPosition = NULL,
timeFormat = NULL,
initialTime = NULL,
onChange = NULL,
popupOptions = NULL
)
removeMinicharts(map, layerId)
clearMinicharts(map)
|
map |
A leaflet map object created with |
lng |
Longitude where to place the charts. |
lat |
Latitude where to place the charts. |
chartdata |
A numeric matrix with number of rows equal to the number of
elements in |
time |
A vector with length equal to the number of rows in |
maxValues |
maximal absolute values of the variables to represent.
It can be a vector with one value per column of |
type |
Type of chart. Possible values are |
fillColor |
Used only if data contains only one column. It is the color used to fill the circles. |
colorPalette |
Color palette to use when |
width |
maximal width of the created elements. |
height |
maximal height of the created elements. |
opacity |
Opacity of the chart. |
showLabels |
Should values be displayed above chart elements. |
labelText |
character vector containing the text content of the charts.
Used only if |
labelMinSize |
Minimal height of labels in pixels. When there is not enough space for labels, they are hidden. |
labelMaxSize |
Maximal height of labels in pixels. |
labelStyle |
Character string containing CSS properties to apply to the labels. |
transitionTime |
Duration in milliseconds of the transitions when a property of a chart is updated. |
popup |
Options that control popup generation. |
layerId |
An ID variable. It is mandatory when one wants to update some
chart with |
legend |
If TRUE and if data has column names, then a legend is automatically added to the map. |
legendPosition |
Where should legend be placed? |
timeFormat |
Character string used to format dates and times when
argument |
initialTime |
This argument can be used to set the initial time step
shown when the map is created. It is used only when argument |
onChange |
(For power users who know javascript) A character string containing javascript code that is executed each time a chart is updated. See the details section to understand why and how to use this parameter. |
popupOptions |
Change default popupOptions (ex : autoClose, maxHeight, closeButton ...)
See |
Since version 0.5, the parameter onChange
can be used to execute
some arbitrary javascript code each time a chart is updated (with
updateMinicharts()
or when time step changes). A typical use case
would be to change the color of a polygon added with
addPolygons
based on the data of the chart. It is even
possible to create an invisible chart and use it to manage the color and the
popup of a polygon. Here is a sample code that do that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | leaflet() %>% addTiles() %>%
addPolygons(data = myPolygons, layerId = myPolygons$myIds) %>%
addMinicharts(
mydata$lon, mydata$lat,
time = mydata$time
fillColor = mydata$color,
layerId = mydata$myIds,
width = 0, height = 0,
onChange = "
var s = this._map.layerManager.getLayer("shape", this.layerId);
s.bindPopup(popup);
if (opts.fillColor) {
d3.select(s._path)
.transition()
.duration(750)
.attr("fill", opts.fillColor);
}"
)
|
The following objects are available when executing the javascript code:
The current minichart object. See https://rte-antares-rpackage.github.io/leaflet.minichart/-_L.Minichart_.html for more information.
The current options passed to the current minichart object.
Popup html.
The D3 module.
Here is a toy example
The modified leaflet map object. addMinicharts
add new minicharts to
the map. updateMinicharts
updates minicharts that have already been
added to the map. removeMinicharts
removes some specific charts from
the map and clearMinicharts
removes all charts from the map and
if necessary the legend that has been automatically created.
1 2 3 4 5 6 7 8 9 10 11 12 13 | require(leaflet)
mymap <- leaflet() %>% addTiles() %>% addMinicharts(0, 0, chartdata = 1:3, layerId = "c1")
mymap
mymap %>% updateMinicharts("c1", maxValues = 6)
mymap %>% updateMinicharts("c1", type="pie")
# popupOptions
mymap <- leaflet() %>% addTiles() %>%
addMinicharts(0, 0, chartdata = 1:3, layerId = "c1", popupOptions = list(closeButton = FALSE))
mymap
mymap %>% updateMinicharts("c1", maxValues = 6, popupOptions = list(closeButton = TRUE))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.