Elastic Charts engine

@elastic/isomer-charts-elastic draws chart Scenes with Elastic Charts, the library Kibana draws its panels with, so a chart looks like the Kibana panel it came from. Its SceneRenderer for the browser supports the metric, xy, partition, heatmap, gauge and tagCloud kinds, and its SceneRenderer for Node draws all of them but tagCloud as static markup, for an image. Kibana draws a legacyMetric without Elastic Charts, so the charts pack draws that kind itself, as it does a table.

npm install @elastic/isomer-charts-elastic @elastic/charts moment moment-timezone react react-dom zod
		
import { createElasticChartsRenderer } from '@elastic/isomer-charts-elastic';
import '@elastic/charts/dist/theme_light.css';

const renderer = createElasticChartsRenderer();
renderer.render(scene, { environment: 'browser', nodeId: node.id, onEvent });
		

The page needs Elastic Charts' stylesheet for the Scene's scheme, theme_light.css or theme_dark.css; without it a chart measures zero and draws nothing. Kibana always loads it. A chart drawn in a shadow root needs the stylesheet inside that root, and on the document too: Elastic Charts portals its own xy tooltip to document.body, while this engine's secondary-metric tooltip stays in the chart's root.

The few elements this engine draws beside Elastic Charts' own, a metric's secondary text without a badge and its tooltip, the legend's filter buttons, and an empty chart's note, take classes from the charts pack's distillery (chartsElastic-*), with what only the Scene knows in Distillate vars. Through the runtime, the pack's distillery emits their rules; a host that draws the react surface itself ships chartsStylesheet() and elasticChartsStylesheet() beside Elastic Charts' stylesheet. elasticChartsStylesheet() holds this engine's rules alone and needs nothing loaded first, so a host that builds its CSS before it loads the engine, such as one that code-splits it, still gets them.

@elastic/charts, React and React DOM are peer dependencies, so a host shares its own copy. @elastic/charts is supported from 74.0.0, and ELASTIC_CHARTS_VERSION is the release this engine is built and tested against. React and React DOM are peered at ^18.0.0, narrower than the SDK's >=18 <20, because @elastic/charts itself peers React 18: a host on React 19 cannot use this engine until Elastic Charts accepts it. On Node the engine needs 22.13.0 or later.

@elastic/isomer-charts-elastic/node draws on Node, where a server makes an image:

const { readFileSync } = require('node:fs');
const {
  ELASTIC_CHARTS_HOST_RULES,
  createElasticChartsNodeRenderer,
} = require('@elastic/isomer-charts-elastic/node');
const {
  chartsFrame,
  createChartsPack,
} = require('@elastic/isomer-primitives-charts');
const { createIsomerRuntime } = require('@elastic/isomer-runtime');

const runtime = createIsomerRuntime({
  packs: [
    createChartsPack({ sceneRenderers: [createElasticChartsNodeRenderer()] }),
  ],
  frames: { charts: chartsFrame },
});

const elasticChartsCss = readFileSync(
  require.resolve('@elastic/charts/theme_only_light.css'),
  'utf8'
);
const input = runtime.surfaces.snapshot.render(composition, { theme: 'light' });
const page = {
  ...input,
  css: `${elasticChartsCss}\n${ELASTIC_CHARTS_HOST_RULES}\n${input.css}`,
};
		

Node loads the CommonJS builds, so the example uses require; the ESM builds are for bundlers. renderChart and the chart components must come from one copy and one module format of @elastic/charts, which require throughout gives.

createElasticChartsNodeRenderer(options?) is a sized renderer for the node environment. It hands the browser renderer's specs, sceneSpecs, to Elastic Charts' renderChart (@elastic/charts/headless), which draws them at the Scene's size with no DOM: an inline svg, with the legend and a metric's tiles as HTML. A Scene with nothing to draw is its note, as in the browser.

  • Stylesheet. The markup needs Elastic Charts' component styles for the Scene's scheme, theme_only_light.css or theme_only_dark.css, then ELASTIC_CHARTS_HOST_RULES: what that stylesheet expects of its page and EUI's global styles give it in Kibana, as renderChart's docs list. Neither is in the pack's stylesheet, so the host puts both before the snapshot result's css, once for a page.
  • Fonts. Without a DOM, Elastic Charts measures text with Inter's advance widths for printable ASCII, whatever font the theme names, and counts any other character as an average glyph. The rasterizer needs Inter registered; text in another script can overflow or be cut early.
  • Tag clouds. renderChart does not draw a word cloud, so the renderer does not support tagCloud, and the charts pack draws its fallback.
  • Events. Static markup raises none: no tooltips, hover, brushing or legend actions. A metric's secondary label placed in a tooltip is read to a screen reader and not drawn. Elastic Charts' own legend still marks each label as a button that toggles its series (role="button", tabindex="0"), which does nothing in static markup: a gap of renderChart's that matters where the markup is shown as a page, not rasterized.
  • Ids. Elastic Charts prefixes every id in a chart's markup with the chart's, which this renderer derives from the Scene and, through React's useId, the chart's place on the page. Charts on one page keep their own clip paths and labels, two drawings of one Scene included, and a page draws the same markup every time.

Elastic Charts writes its data warnings, such as one for null values in a series, to the console on every render. The work is synchronous. A chart at the charts pack's whole input budget takes about two thirds of a second to validate, resolve and draw on an Apple M4 Pro, so a server draws in a worker or a render service. bench/engine.cjs is this renderer as the benchmarks' charts suite loads an engine, and isomer-bench.config.cjs names it, with the ceilings pnpm check:memory holds it to.

sceneSpecs(scene, env, options?) turns a metric, xy, partition, heatmap, gauge or tagCloud Scene into Elastic Charts spec elements: Settings, axes, series, reference lines and annotations in the Scene's layer order, the metric grid, a Partition of the Scene's slices, a Heatmap of its cells, a gauge's Bullet, or a Wordcloud of its words. The browser renderer wraps them in <Chart> and the Node renderer hands the same elements to Elastic Charts' renderChart, so a chart drawn in a browser and one drawn on a server come from one place. A metric's secondary text without a badge is a React element in every environment, which both draw.

@elastic/isomer-charts-elastic/engine exports sceneSpecs and what else another Elastic Charts drawing of a Scene builds on: kibanaBaseTheme, ariaDescriptionOf, emptyTextOf and its text sizes, seriesOf, slicesOf, and TAG_CLOUD_LABEL, the tag cloud label's type. A drawing that hands the specs to renderChart must build them from the same copy and module format of @elastic/charts.

Colors, text and series are the Scene's, and draw order is as far as Elastic Charts' paint bands allow (see the tolerance table). Ticks, domains, stacks and point density are Elastic Charts', computed from the intent each Scene axis and series states, the way Kibana's xy expression hands them over. A tick label prints through formatAxisValue, so it reads the same in every engine. A time x axis with twoRows is Elastic Charts' multi-layer time axis, as Lens draws it (Time axis): Elastic Charts picks and labels its ticks on two rows from the axis's domain, bucket and time zone and the Scene's locale.

Elastic Charts input From the Scene
Base theme Kibana's charts base theme for the Scene's scheme: Elastic Charts' Borealis theme with the Elastic UI Numeric font first and axis titles in the tick-label color at weight 500, as Kibana's charts plugin builds it
Background, axis, tick, grid-line and title colors chrome
Series colors and names The series layers
Stacking Unstacked y with stackAccessors; a percentage stack sets stackMode: 'percentage'
y domain custom is { min, max }; data is fit: !includeZero, an end the Scene fixes as min or max and the other as NaN, with the axis's reference lines in includeDataFromIds, as Kibana's getAxisDomain builds it
x domain The categories in order on an ordinal axis; custom is { min, max }; otherwise Elastic Charts' own. A stated interval is minInterval, which sizes the bars
Rounding xNice and yNice from each axis's domain.rounding
Points points: auto, visible and hidden are 'auto', 'always' and 'never'
Time zone The x axis's timeZone, else the Scene's
Tick labels A category's label on an ordinal axis; on a time axis with twoRows, Elastic Charts' multi-layer labels (timeAxisLayerCount left at its default, 2); any other value through formatAxisValue
Value labels The mark's label; on a percentage stack, the mark's share through the y axis, as Lens prints it; where marks in one series share a value but carry different labels, that value through the y axis, since the formatter sees only the value. Placed as Lens places them: Kibana's bar displayValueSettings (no alternation, hidden where a label overflows its bar or the chart's edges) and getValueLabelsStyling (10 to 12 px, no text border, centered across the bar and offset 10 px along it)
Tooltip The hovered position's category label (else as its axis labels it), then each hovered series' name, color and mark label
Legend position, layout, size, title and truncation legend
Reference lines and annotations The referenceLine and annotation layers, styled as Kibana's xy chart styles them; a range with fill: 'outside' draws beside the axis. A layer before the first series gets a zIndex that paints it beneath every series; any later one paints above them, except a range, which paints beneath the data wherever it sits, as Kibana's xy chart draws it
Metric tiles, layout and alignment tiles and layout, as Kibana's metric visualization sets them; the value prints the tile's value.text, a comparison badge's glyph is its icon, and secondary text without a badge draws in its color
Partition slices The Scene's leaves, depth first in draw order, as the data, each keyed by its slices' keys and weighed by its value, so Elastic Charts sums each slice as the Scene did; each layer's names, fills and order are the Scene's label, color and sibling order. shape picks the layout: sunburst for a pie or donut (with specialFirstInnermostSector, as Kibana sets it), treemap, mosaic or waffle
Partition labels A slice's valueLabel, through a value getter that names the slice; a legend value is the slice's valueText. labels.categories sets the link labels and the hidden fill text as Kibana's getPartitionTheme does
Partition theme Kibana's getPartitionTheme: font sizes 10 to 16, a 1.5 px sector line in the Scene's background color, donutHole as emptySizeRatio, and a pie, donut or waffle shrunk by 5% per leaf under 2% of the whole, at most 20%, for outside labels
Partition legend legend: visibility, position, size, truncation, nesting (flatLegend and legendMaxDepth), the Scene's item order (legendSort) and values
Partition tooltip The hovered slice's tooltip: it and each slice it sits in, with value and share
Heatmap cells The Scene's cells, each at its x position (its index in x.categories, or its instant on a time axis) and its index in y.categories, then a valueless datum for each position no cell fills, so the axes hold every Scene position; both axes sort numAsc, so positions are in the Scene's order
Heatmap bands bands as a bands color scale, an open bound infinite, with the Scene's labels, so Elastic Charts colors each cell and lists each band as the Scene does
Heatmap axes A time axis is a raster time scale with a fixed interval in milliseconds in its timeZone, over its domain as Settings.xDomain when it has one, as Lens's heat map passes it, its labels through formatAxisValue; any other axis is ordinal, labelled by its categories. title, showLabels and labelRotation, padded 8 px as Kibana pads an axis with a column
Heatmap theme Kibana's heat map theme: gridLines as the grid stroke, cell labels when cellLabels from 8 to 18 px, no cell border, and axis labels in the Scene's subdued text color
Heatmap values A cell's valueText, through a value formatter that finds it by value
Heatmap tooltip The hovered cell's tooltip: its positions and its value in its color
Heatmap legend legend: visibility, position, size and truncation
Gauge A Bullet of the Scene's shape as Kibana's getSubtypeByGaugeType maps it, over min to max, with the value, the goal as its target, labels as title and subtitle, and ticks when the Scene places them
Gauge bands bands as colorBands: their edges as steps and one color each, as Kibana passes them; a lone band as its color twice, so Elastic Charts draws it in that color alone
Gauge text The value and goal print their Scene text; ticks and any other value on the scale print through formatAxisValue. The tooltip names them by tooltipLabels
Tag cloud words words as the Wordcloud's data, each with its text, weight and color and naming its word by index; scale, angles and fontSize as Kibana's tag cloud passes them, in Kibana's font, with 5 px padding on an Archimedean spiral
Tag cloud label label on a line under the cloud, centred, bold, in the Scene's text color, as Kibana draws it: in the browser an element of this engine's, cut with an ellipsis where it overruns the chart's width. sceneSpecs draws the cloud alone, so a host's own static drawing writes label itself on a line of TAG_CLOUD_LABEL's size, line height and weight, and cuts it the same way. The cloud takes the height above it, on the Scene's background
An empty chart empty.text of any Scene that carries one, an xy or metric Scene included, centered in the chart's box in the Scene's subdued text color at EUI's s size, as Lens's VisualizationNoResults draws it, in place of a chart; the title names the image and the note describes it
Accessible label and description title; summary, then description when the node states one

With debugState: true, or when the page sets window._echDebugStateFlag as Kibana's functional tests do, Elastic Charts writes its DebugState to the chart.

With onEvent and a node id, a gesture raises the event of the Scene part it lands on, through the Scene's selections. Elastic Charts' own indexes and values are never used.

Gesture Elastic Charts callback Event
Click a bar, point or area vertex onElementClick (the first element, as Kibana takes it) datum; category when the node offers no datum
Click the plot away from a mark onProjectionClick category: the x position the click falls in
Drag along a continuous x axis onBrushEnd brush
"Filter for" or "Filter out" beside a legend item Legend action legend, with negate for "Filter out"
Click a metric tile onElementClick tile
Click a partition slice onElementClick (the innermost slice of the first element) slice
"Filter for" or "Filter out" beside a partition legend item Legend action slice, with negate for "Filter out"
Click a heat map cell onElementClick (the first cell, by its datum) cell
Drag across a heat map's time axis onBrushEnd brush
Click a tag cloud word onElementClick (the word, by its datum) tag

A click on the plot falls in an x position when Elastic Charts projects it to that position's x, or, on an axis stating an interval, to an x from there to less than one bucket after it. The bucket is the stated interval, or the smallest spacing between x positions when that is narrower, as Elastic Charts' minInterval is. Elastic Charts projects a click on a histogram to the start of the bucket under the pointer, so a click on a bucket with no data, or past the last one, raises nothing.

Clicking a legend item's label shows or hides series, as Elastic Charts' legend does, and raises nothing: with every series showing, it hides all the others; on a hidden series, it shows that series again; on the only series still showing, it shows every series; otherwise it hides that series. A click with Command held, or Control off Apple devices, hides or shows that series alone. Elastic Charts keeps the series a reader hides by spec id, and a series' spec id is its node's data layer, y entry and series key (series-<layer>-<y>-<key>), so a hidden series stays hidden when new data adds, removes or reorders the series around it.

src/parity.test.ts holds the engine to this table over every example the charts pack has, nested in a grid or not: each gesture above, built from what Elastic Charts reports for it and sent to the callbacks and legend action the specs install on Settings, raises the event of the Scene part it lands on, through selectEvent and brushEvent, and nothing where the node offers no target. No metric example offers tile, so each is also checked offering it.

@elastic/isomer-charts-elastic/testing holds what any static drawing with Elastic Charts checks beside the charts pack's static renderer checks:

  • debugStateProblems(scene, state) compares the DebugState Elastic Charts reports for a drawing with its Scene: every tick label is the category's label or the value through formatAxisValue, except on a time axis with twoRows, which Elastic Charts labels itself; the series drawn and the legend items are the Scene's with their colors, a partition draws each slice by key with its color and value, and a heat map draws each cell in its band's color with its value text, and no value without cellLabels, its positions' labels, its axis titles and its bands as the legend, and a gauge draws its bullet with the Scene's labels, value, goal, scale, bands and ticks. A metric or tag cloud has no DebugState, so it is checked by its text alone. debugStateTexts and debugStateColors read what it reports as drawn, for an engine whose output holds no text or paint to read.
  • defineLookSuite({ test, expect, drawn, script, stylesheet, sameScene, looser?, unlike }) declares the look check in Chromium, given Playwright's test and expect: this engine's browser drawing of each Scene is the static drawing's size and scores a mean SSIM, on luminance at an eighth of their size (LOOK_SCALE) with every pixel counted, of at least sameScene[kind] against the static drawing of the same Scene, and below it against the static drawing of each of the unlike pairs, examples established to differ in layout. script is a bundle that calls installLookPage(), which draws Scenes with this engine and scores pictures in the page. onScore, when given, receives every score with its tolerance, for an engine to record. The page gives the browser drawing what EUI's global styles give it in Kibana; the static drawing gets stylesheet alone, so a rule its host must load is missed when it is missing.

The Node renderer runs both: src/node.test.ts holds every example's DebugState to its Scene, and e2e/look.spec.ts, part of pnpm test:browser, runs the look suite on its markup laid out by Chromium in Inter. A same-Scene drawing scores at least 0.93 for an xy or partition chart and 0.95 for a metric, gauge or heat map, against at most 0.834 for the unlike pairs. One heat map example is held to 0.85: renderChart measures % narrower than Chromium draws it, so a legend of percentage bands fits on Node where the browser cuts it.

src/testing/testing.test.ts holds debugStateProblems to what this engine draws for every xy, partition, heat map and gauge example in jsdom, and to mutations of it: a changed tick label, a series in another color, a slice missing, a cell in another color or with another value, a gauge with another value or band.

Content (strings, colors, order) is the Scene's. Where Elastic Charts cannot take a value from the Scene, its layout or a feature differs from the Scene:

Kind Gap Effect
xy Series stack by axis: Elastic Charts has no stack group, so two stacked layers on one axis stack together Matches Kibana; differs from the Scene's stack.group
xy Bars on a continuous x axis use histogram mode when stacked or the chart's only bar series. Kibana's rule (enableHistogramMode in expression_xy/public/helpers/data_layers.tsx) also requires the layer's x to be a date or number histogram (isHistogram), which the Scene does not state, turns it off for an unstacked layer with a breakdown even when one series results, and turns it on for a histogram's lines and areas Bars on a continuous x that Lens would not call a histogram draw in histogram mode here and not in Kibana; a line or area alone over a histogram draws in histogram mode in Kibana and not here
xy A bar's value label is hidden where it overflows the bar or the chart's edges, as Kibana's overflowConstraints hide it; the Scene gives every mark of a valueLabels series a label Matches Kibana; some marks of a valueLabels series draw no label
xy legend.items[].statistics are not drawn Legend statistics missing
xy legend.items[].hidden is not applied: Elastic Charts has no public initial deselection Hidden series draw until a reader toggles them
xy Annotation and reference-line icons and text markers are not drawn Lines and fills only
xy currentTime is not drawn: the Scene gives it no color No current-time marker
xy interactions.emphasis and sync are not drawn No static highlight or synced cursor
xy No gesture raises the series select target; legend actions raise legend A node offering series raises nothing for it
xy partial marks are not shaded No end-zone shading
xy Elastic Charts paints in fixed bands: annotations beneath the series, then bars, areas and lines, then annotations above. A reference line or point annotation between two series paints above both, a range after a series paints beneath it, and series of different marks paint bars first, then areas, then lines, whatever their order in layers Overlap between layers can differ from the Scene's order
metric layout.icon is not drawn: Elastic Charts takes an icon component, and this engine maps no ChartGlyph to one No tile icon
metric trend.xDomain and trend.yDomain are not applied: Elastic Charts fits the trend to its points Trend line scale may differ
metric Title and subtitle colors are Elastic Charts' contrast choice against the tile background Title color may differ from the Scene's chrome.text
metric A progress bar draws progress.fraction against a domain of 1 Bar length matches; Elastic Charts' accessible progress text reads the fraction
partition Slice label text color is Elastic Charts' contrast choice against each fill Label color may differ from the Scene's chrome.text
partition A legend value is found by the slice's sum alone, so where legend items with one sum carry different valueTexts (several metrics in different formats), none of them shows a legend value Those legend values are missing rather than another slice's
partition interactions.emphasis is not drawn No static highlight
heatmap Cell label text color is Elastic Charts' contrast choice against each fill Label color may differ from the Scene's chrome.text
heatmap A cell label's formatter sees only the value, so where cells share a value but carry different valueTexts, none of them is labelled Those cell labels are missing rather than another cell's
heatmap A time axis is drawn from the first instant to the last bucket's end, a column per interval, with ticks Elastic Charts chooses Columns with no row draw empty; tick placement may differ
heatmap interactions.emphasis and sync are not drawn No static highlight or synced cursor
gauge The value bar, tick and text colors are Kibana's bullet theme's, not the Scene's chrome Matches Kibana; differs from chrome.text
gauge A circle's last tick lies on its first, and Elastic Charts draws only the first The max tick label is missing on a circle
tagCloud Elastic Charts places words by pixel sprites each engine measures its own way, so words land in different places, and a word that fits in one may not in the other Word placement differs; the look gate compares colors' mass, not layout, and holds a cloud of many small turned words to 0.6
tagCloud Words that do not fit are left out with no note: Kibana shows a warning icon No out-of-room warning
tagCloud interactions.emphasis is not drawn No static highlight
all The charts pack keeps a Scene for one task, so each host render hands this engine a new, equal Scene, env and onEvent for the same node, and Elastic Charts takes the specs built from them as changed. In jsdom (src/rerender.test.ts) each re-render repaints an xy chart and lays a tag cloud out again; one element rendered twice draws once An unchanged chart recomputes and repaints whenever its host renders, as on each ChartEvent a host keeps in state
all Pixel layout (margins, label placement, legend width) Geometry compared within tolerance, not exactly

link is drawn by the primitive around the renderer, not inside the chart.