Skip to contents

draw() is the single low-level entry point for every rendering backend in rtemis.draw. It is an S7 generic that dispatches on the option object – the complete, validated render spec for one backend – so the right JS binding is selected purely by type, with no ambiguity:

Usage

draw(
  option,
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL,
  filename = NULL,
  animation = NULL,
  ...
)

Arguments

option

EChartsOption, SigmaOption, or named list: Render spec to draw.

theme

Optional Theme, list, or NA: Theme override. NULL enables light/dark auto-detection; NA disables theming. Applied to every backend.

width

Optional Character or Numeric: Widget width.

height

Optional Character or Numeric: Widget height.

element_id

Optional Character: Explicit element ID.

filename

Optional Character: If provided, the widget is also written to this file via save_drawing() (ECharts only; other backends reject static export requests). Extension determines the format (currently only .svg).

animation

Optional Logical: Whether ECharts animates the chart. NULL (default) leaves ECharts' own default in place. FALSE disables animation, which matters for charts with many points, where animating every interactive update is expensive. Ignored by the Sigma and MapLibre backends, which have no ECharts animation to disable.

...

Backend-specific arguments, which must be named. ECharts accepts renderer (Character {"canvas", "svg"}) and meta (named list of extra payload fields, used internally e.g. by draw_heatmap()). Any other name is an error rather than a silent no-op, so a typo cannot quietly change what is drawn.

Two meta fields are read by the ECharts JS binding and are part of its contract, because they need the container width, which only the browser knows:

  • squareCells: see draw_heatmap().

  • aspect: a named list with ratio (required grid height / grid width), widthPx (preferred grid width; the box shrinks below this only when the container is too narrow), and leftPx, rightPx, topPx, botPx (padding to reserve outside the grid). The binding solves for the grid box on render and on resize, and sets the container height to match. Use it for charts whose pixel geometry carries meaning – most often equal axis scaling, where one data unit must be the same number of pixels on both axes and ratio is therefore the y range over the x range. ECharts has no equal-aspect option, and R cannot know the container width, so neither side can enforce this alone.

Value

htmlwidget: Widget object.

Details

A plain named list is treated as a raw ECharts option (back-compatible with the original draw()).

Theme handling is uniform across backends and lives on draw(), not on the option object: pass NULL (default) for light/dark auto-detection (from VS Code, RStudio, or the browser's prefers-color-scheme), NA for no theme (raw backend defaults), or a Theme / list to force one.

Examples

option <- EChartsOption(
  x_axis = Axis(type = "category", data = c("Mon", "Tue", "Wed")),
  y_axis = Axis(type = "value"),
  series = BarSeries(data = c(120, 200, 150))
)
draw(option)