Add keyboard navigation to an echarts4r chart
ro_e_keyboard_nav.Rdro_e_keyboard_nav() attaches JavaScript keyboard event listeners
to an echarts4r chart, enabling keyboard-only users to navigate data points
and toggle legend series. It is designed to follow ro_e_theme() at the end
of an echarts4r pipeline.
Arguments
- e
An echarts4r object.
- series_keys
Named character vector mapping single-letter key codes to series names, e.g.
c(w = "Women", m = "Men", t = "Total"). Names must be single letters (case-insensitive); values must exactly match the series names as used in the chart. Set toNULL(default) to omit legend controls.- axis
Character. Arrow-key direction for tooltip navigation. One of
"horizontal"(ArrowLeft / ArrowRight),"vertical"(ArrowUp / ArrowDown), or"both". DefaultNULLauto-detects from the chart orientation.
Value
The modified echarts4r object, with keyboard navigation attached via
htmlwidgets::onRender().
Keyboard controls
Arrow keys: move the tooltip across data points. Direction is
auto-detected from chart orientation (left/right for column and line
charts; up/down for bar charts), or set explicitly via axis.
Letter keys: toggle individual legend series. Controlled by
series_keys; nothing is hardcoded. Pass NULL to omit legend controls.
Axis auto-detection
The function inspects the echarts4r object to determine whether
echarts4r::e_flip_coords() was applied, and assigns arrow keys
accordingly. Override this with the axis argument.
See also
ro_e_theme()to apply the RO visual theme.echarts4r::e_flip_coords()which determines axis orientation.
Other echarts4r:
ro_e_build_keyboard_nav_js(),
ro_e_build_onrender_js(),
ro_e_detect_axis_orientation(),
ro_e_keyboard_nav_axis_js(),
ro_e_keyboard_nav_legend_js(),
ro_e_theme(),
ro_e_theme_list()