Skip to contents

draw() renders chart configurations and backend option objects as interactive visualizations. It is an 'S7' generic that dispatches on the class of option:

Usage

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

Arguments

option

ChartConfig subclass, EChartsOption, SigmaOption, MapLibreOption, PeleOption, or named list: Chart configuration or render spec to draw. All concrete chart configuration classes listed below are supported.

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(). 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, MapLibre, and Pele backends, which have no ECharts animation to disable.

...

Named arguments for the selected method. For ChartConfig subclasses, data supplies the data to plot; its required structure depends on the configuration class. If data is omitted or NULL, the config's dat_path is read instead.

Additional arguments are passed to the rendering backend. 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

  • ChartConfig subclasses -> compile the configuration with its data, then render using the corresponding backend.

  • EChartsOption -> 'ECharts' (rtemis-draw widget).

  • SigmaOption -> 'Sigma.js' (rtemis-graph widget).

  • MapLibreOption -> 'MapLibre' (rtemis-map widget).

  • PeleOption -> 'Pele' (rtemis-diagram widget).

A plain named list is treated as a raw 'ECharts' option.

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.

Chart configurations

Supported ChartConfig subclasses are A3Config, BarConfig, BoxplotConfig, CalibrationConfig, ChoroplethConfig, ConfusionConfig, DensityConfig, GanttConfig, HeatmapConfig, HistogramConfig, LineConfig, MermaidConfig, NetworkConfig, PieConfig, PRConfig, ROCConfig, SankeyConfig, ScatterConfig, Scatter3DConfig, SignificanceConfig, SpectrogramConfig, SurvivalConfig, and TimeSeriesConfig. Use their setup_*() functions to create configurations, then pass the data to draw() with data = or set dat_path on the configuration. See compile() to obtain the backend option without rendering it.

Examples

# Render a chart configuration with data.
config <- setup_ScatterConfig(x = "wt", y = "mpg")
draw(config, data = mtcars)

# Render a backend option directly.
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)