Skip to content

ADR-0015: Chart interaction reads its scale from the chart root

  • Status: Proposed
  • Date: 2026-11-30

The viewer reads only the SVG and never re-renders (interaction.md). Charts need the same, under the rules in chart-interaction.md:

  • a crosshair that snaps to an x and reads out every series there;
  • a legend that hides series;
  • a brush that reports an x range in data units;
  • crosshairs linked across charts.

The brush must report from and to in the form x.domain accepts, so a host can re-render with them. That form is numbers on a linear axis and ISO instants on a time axis.

The chart SVG carries each drawn value as written, in data-merlion-* attributes, with the item’s geometry (chart.md § SVG). It does not carry the plot box, the axis types or the computed domain. Each attempt to derive them from the items has a gap:

  • Axis type. "2024" is a valid value on both a time axis and a linear axis. A chart whose x values are all bare years therefore has two readings, and the brush must name one to produce a domain that re-renders. Calendar years differ in length only around a leap year, so three evenly spaced years fit both readings exactly.
  • Plot box. On a band x axis, the plot’s height shows only through the y grid lines. When an authored y domain does not end on a tick, no grid line marks the plot’s top.
  • Domain. On a time axis the tick labels are formatted text such as 9 Nov. A computed linear domain is widened to whole tick steps beyond the data. The items give only interpolation anchors, and a chart whose x positions come only from bars or spans has fewer than two of them.
  • Labels. Item labels sit in one merlion-chart-labels group with no series attribute. Hiding a series would leave its labels drawn beside nothing.

The core writes three attributes on a chart’s root <svg>:

  • data-merlion-plot="{x} {y} {w} {h}";
  • data-merlion-axes="{x type} {y type}";
  • data-merlion-x-domain="{min} {max}" when x is linear or time. It holds the domain the chart draws with, in the units x.domain accepts.

The core also writes data-merlion-series on each item label whose item has a series. The viewer’s chart module, interact-chart.js, reads these attributes and the existing item attributes. It is loaded by <merlion-view> for chart SVGs only, so a page of diagrams fetches none of it, and a page of charts fetches none of interact.js.

Option Buys Costs
Derive everything from items and grid lines No change to the core’s output Every gap in Context: the axis type of an all-year axis is a guess; the guide on a band chart can stop short of the plot’s top; a chart without point anchors gets no brush; hidden series leave their labels. Each fallback rule costs bytes in a module with a 3.5 KB budget
Attributes on the root, and series on labels An exact brush and guide from three attribute reads; hiding a series hides its labels; the viewer stays small 75–144 bytes per chart and 25–35 per labelled item, and every recorded chart digest changes once
One JSON object in a <metadata> element Room for any later scale data A second encoding beside data-merlion-*, a JSON parse in the viewer, and an element that sanitisers on some hosts strip
Re-render through WASM in the viewer Exact by construction, and the brush could redraw the chart Breaks the presentation-only rule (ADR-0010). It needs the spec and the WASM module on the page, and changes the SVG under the reader

The criteria were exactness of the brush’s range, the viewer module’s byte budget, and the chart’s own bytes. The brush must be exact, which rules out derivation. The budget rules out both the fallback rules of derivation and a JSON parse. Re-rendering breaks the presentation-only contract. The root attributes cost bytes in the chart and nothing else.

  • Easier: the viewer maps a pointer to data units through one linear function. A hidden series takes its labels with it. Hosts can read the plot box and domain without parsing geometry.
  • Harder: the root attributes are now contract. Changing the plot box’s or the domain’s encoding changes every consumer.
  • Every recorded chart digest changed once (tests/fixtures/chart-digests.txt).
  • A chart SVG without the attributes, rendered before they existed, gets pan, zoom and fullscreen but no chart interaction.
  • On the nine chart fixtures, the attributes add 75–302 bytes, 0.15–2.12% of each SVG before gzip. Their share of charts outside the fixtures is unmeasured.