Pipe-able function that injects series-level label configuration into
an existing echarts widget, labelling the rectangles drawn for
islands = "box". Uses a JavaScript formatter that shows the
geopt_label text for those rectangles and an empty string for every other
feature.
Usage
box_labels_echarts(
e,
sf_obj,
font_size = 12,
color = "#333",
position = "right",
offset = c(92, 0),
...
)Arguments
- e
An echarts widget created by
echarts4r::e_charts().- sf_obj
An sf object returned by
get_map(). Features are matched by itsnamecolumn (the one the widget was built with), or bygeopt_labelif there is none.- font_size
Font size for labels. Default
12.- color
Color for labels. Default
"#333".- position
Label position relative to the feature bounding box. Default
"right". See echarts label position options.- offset
Numeric vector of length 2 (
c(x, y)) to shift the label in pixels. Defaultc(92, 0).- ...
Additional echarts label properties (e.g.
align,verticalAlign,fontWeight,rotate).
Examples
m <- get_map("nuts3", islands = "box")
m$name <- dplyr::coalesce(m$geopt_label, m$nuts3)
geojson <- geojsonsf::sf_geojson(m)
m |>
echarts4r::e_charts(name) |>
echarts4r::e_map_register("pt", geojson) |>
echarts4r::e_map(area_ha, map = "pt", roam = TRUE) |>
box_labels_echarts(m) |>
echarts4r::e_visual_map(area_ha)
