﻿---
title: Scene
description: The Scene a chart node resolves to, and the SceneRenderer interface every chart engine implements.
url: https://docs-v3-preview.elastic.dev/isomer/primitives/charts/scene
---

# Scene
A chart node resolves to a **Scene**: what every surface must agree on, decided once. Colors are concrete for one scheme, every string the Scene holds is formatted, legend items and series are in order, and marks are in data space. Axes and series state intent (a scale, a format, where a domain comes from, a stack mode, point visibility), and the chart engine computes ticks, domains, stacks and point density from it, as Elastic Charts does for Lens. Tick labels are the one string the Scene does not hold: the engine formats each tick it chooses from its axis's format through `formatAxisValue`, except on a time axis with `twoRows`, which it draws as Lens's two rows ([Time axis](/isomer/primitives/charts/xy-chart#time-axis)). Text, colors and order are identical in every engine; tick placement may differ.
```ts
import type {
  Scene,
  SceneRenderer,
} from '@elastic/isomer-primitives-charts/scene';
```


## What every Scene holds


| Field                        | What it is                                                                                                                                                                   |
|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `kind`                       | `metric`, `xy`, `table`, `partition`, `heatmap`, `gauge`, `tagCloud` or `legacyMetric`                                                                                       |
| `scheme`                     | `light` or `dark`. Always explicit, so a renderer draws every color without CSS: `light-dark()` is never the only source of a color                                          |
| `size`, `locale`, `timeZone` | What the Scene was resolved for                                                                                                                                              |
| `chrome`                     | Text, axis, grid-line, background and border colors                                                                                                                          |
| `summary`                    | One sentence on what the chart shows                                                                                                                                         |
| `table`                      | The node's data in `data` order. Formatted `cells` serve text surfaces; raw `values` are in matching column order so renderers can raise events without parsing display text |
| `interactions`               | What the node offers, resolved: selection targets, brush column, sync, link and emphasis                                                                                     |

A `MetricScene` has a `layout`, one tile per row, and `empty` when there is no row. A `PartitionScene` has its `layers`, its slices as a tree in draw order (`nodes`), the `total`, its `labels`, `donutHole` and `legend`, and `empty` when there is nothing to draw ([how a partition chart resolves](/isomer/primitives/charts/partition-chart#how-it-resolves)). A `HeatmapScene` has its `x` and `y` axes, each with its positions in order (`categories`), its `cells` with their colors, its ascending `bands`, which its legend lists, and `empty` when there is nothing to draw ([how a heat map resolves](/isomer/primitives/charts/heatmap#how-it-resolves)). A `GaugeScene` has its `shape`, `value` and `valueText`, its scale (`min`, `max` and `format`), its `goal`, `labels`, colored `bands` from `min` to `max`, `ticks` when the node places them, and `empty` when there is nothing to draw ([how a gauge resolves](/isomer/primitives/charts/gauge#how-it-resolves)). A `TagCloudScene` has its `words` in row order, each with its text, `weight` from 0 to 1 and color, the `scale`, `angles` and `fontSize` the engine lays them out by, its `label`, and `empty` when there is nothing to draw ([how a tag cloud resolves](/isomer/primitives/charts/tag-cloud#how-it-resolves)). A `LegacyMetricScene` has its `tiles` in tile order, each with its label, value, colors, type sizes shrunk to fit and estimated box, the `labelPosition`, `textAlign`, `showLabels`, `lineHeight` and `valueWeight` they draw with, the chart's `background`, and `empty` when there is nothing to draw ([how a legacy metric resolves](/isomer/primitives/charts/legacy-metric#how-it-resolves)). A `TableScene` has its `columns`, its `rows`, their starting `order` and every column's sorted `orders`, and, when rows are paged, `paging`: the page size, the page count and the bounded list of entries its pager shows on the first page, never a label per page ([how a table resolves](/isomer/primitives/charts/data-table#how-it-resolves)). An `XyScene` has `axes` (scale, format and domain intent), `categories` (every x position with data), `layers` in exact draw order, a `legend`, and `empty` when no series has a mark with a value. Each layer is a resolved series, reference line or annotation; helper marks are interleaved with series in the order they appear in the chart.

## `resolveChart`

```ts
import { resolveChart } from '@elastic/isomer-primitives-charts/resolve';

const scene = resolveChart(node, {
  scheme: 'dark',
  size: { width: 480, height: 240 },
});
```

`resolveChart(node, { scheme, size?, locale?, timeZone? })` turns a `metric`, `xyChart`, `dataTable`, `partitionChart`, `heatmap`, `gauge`, `tagCloud` or `legacyMetric` node into its Scene ([how a table resolves](/isomer/primitives/charts/data-table#how-it-resolves)). It is pure and synchronous, and the Scene is plain JSON data, so it can be resolved on a server and shipped (`table.rows` is formatted on first read, from the node's data as it is then, which serializing it does); only the ticks an engine chooses are formatted where it runs, through `formatAxisValue`. `locale` defaults to `en` and `timeZone`, for dates whose format names none, to `UTC`. Every string comes from the node: its `display` strings, or its values in their [formats](https://docs-v3-preview.elastic.dev/isomer/primitives/charts/format). No host code takes part, so a node prints the same wherever it is resolved; a host that needs its own text sends `display` strings.
What it decides:
- **Colors** from the node, concrete for the scheme. Chrome and the default categorical palette come from one theme, EUI Borealis tokens. Text, trend strokes and progress fills on a colored metric background use whichever scheme's text color contrasts more after compositing over the chart background.
- **Metric tiles**, one per row: titles from the breakdown, colors by band (a percentage band reads each tile's place from 0 to its own `max`, across the range of tiles, or from 0 to twice a lone value, and a tile in an empty range takes the first band), comparisons (to the primary: the primary minus the secondary, signed; to a baseline: the value, colored by the sign of the secondary minus the baseline), and three tiles per row unless `maxColumns` says otherwise.
- **Xy series** in layer, y-column and first-appearance order of split values, each with its stack group and mode; marks carry unstacked values, their `label` (the value as displayed, for a bar label or a tooltip the engine builds) and their `description` (each dimension and the value, for selections and screen readers). Categories list every x position any series has data at, in axis order, ordinal ones in row order; a series' `source` holds the rows that drew its marks. A mark is `partial` when its bucket crosses an edge of `style.partialBuckets`; the bucket's width is the node's `axes.x.interval`, unless that is wider than the smallest spacing between its layer's x values, which is used then, as it is when the node states none.
- **Axes** as intent: the scale; the format values print in (a percentage stack's axis prints percent); on a time axis, the zone ticks fall on round times in (the x format's `timeZone`, or the Scene's); and the domain, either `custom` bounds or `data` with whether the data's extent is extended to include zero (bars and areas on a `full` y axis, percentage stacks, and a y axis whose node fixes one end, whatever its marks, except on a log axis) and whether it rounds. A y axis whose node fixes one end states it as that `data` domain's `min` or `max`: a fixed `min` replaces the extended extent's lower end and a fixed `max` its upper end, and the other end stays the data's, so a domain with `min: 57` over data up to 210 spans 57 to 210, without zero. That domain does not round at either end. An ordinal axis has no domain: its positions are `categories` in order. A continuous x axis carries the node's `interval`, when it states one, for an engine to size bars by. The engine chooses ticks and labels each with `formatAxisValue(scene, axis, value)`, the only formatting a renderer does, except on a vertical chart's time x axis with `twoRows`, whose two rows it labels as Lens does. The resolver sets `twoRows`, and a `labelRotation` of 0, where Elastic Charts' time rasters can label the axis: its bucket is known and no more than 5% wider than a decade, so a calendar decade fits, and it spans no more than 50 decades, counting one bucket past the last x where bars fill buckets (any stacked bars, or one bar series).
- **Multivalue coordinates** in a `metric` use the first non-null element for values, trend coordinates and bar maxima. Empty arrays are missing. An `xyChart` has none: its x, y and split columns are single-valued. Labels, tables and selection values retain the whole cell.
- **Ranges wider than the largest double** place no value within them: metric and legacy metric take the first band, a gauge's percentage bands draw transparent, a heatmap drops its percentage bands, a table draws no bar and a tag cloud weighs every word 0. A legend statistic past the largest double reads as missing.
- **Selections** for each target the node offers, and none it does not.

Legend statistic names, default reference-line and annotation colors, and style defaults such as area opacity and bar minimum height are Isomer's choices for nodes that do not state them. A materializer states its source's own values; the parity gates compare the result with Elastic Charts and refine them.
The series in `interactions.initial.hiddenSeries` start hidden: their legend items say so, and the summary sentence, which no reader can toggle, leaves them out. Everything else in the Scene holds every series, so an engine shows or hides one without resolving again.
Every data layer shares one x column, so one axis scale and format serve them all. A node that skipped validation and holds an x cell its continuous scale cannot place throws a `RangeError` from `resolveChart`; the pack draws [its failure note](/isomer/primitives/charts/rendering#when-a-chart-cannot-be-drawn) in the chart's place.
Ordinal x positions are opaque keys derived from raw cells; tick and category labels hold their displayed text. Distinct cells remain distinct positions even when their labels match; a date cell is its instant, so date-times for one instant share a position, as they share a split series, whatever their UTC offset.

## Marks carry their rows and columns

Every selectable part of a Scene (a metric tile, an xy mark, a series, a legend item) carries a `source`: the row indexes into `data.rows` and the column ids it represents, built in the same pass as the mark. The table keeps each row's raw `values` alongside its formatted `cells`. A renderer maps a gesture to an event through `source` and those raw values, never through its own indexes or parsed display text, so alignment, helper series and duplicate labels cannot send a click to the wrong row.
Each `XySeries` carries its `series` reference: the index of its data layer and y entry, uniquely identifying the series even when different layers share the same series key.
Helper marks carry no `source` and are never selected: progress bars, trend lines, reference lines, annotations and the current-time marker.

## Selections and events

Where the node offers a selection target, the part a reader selects carries a `selection`: the event it raises, decided by the resolver.
```ts
type SceneSelection = {
  rows: number[];
  columns: string[];
  values: Record<string, Cell>;
  description: string;
} & (
  | {
      target: 'datum' | 'series' | 'legend';
      series: { layer: number; y: number };
      seriesKey: string;
    }
  | {
      target:
        'category' | 'cell' | 'tile' | 'slice' | 'mark' | 'region' | 'tag';
    }
);
```

No Scene of this pack carries a `mark` or `region` selection: those targets are for [packs that build on the chart core](/isomer/primitives/charts/interactions#interactions).

| Target     | Carried by                                                                                                                    |
|------------|-------------------------------------------------------------------------------------------------------------------------------|
| `tile`     | Each metric and legacy metric tile                                                                                            |
| `slice`    | Each partition slice and legend item                                                                                          |
| `tag`      | Each tag cloud word                                                                                                           |
| `cell`     | Each `dimension` cell of a table, and each heat map cell                                                                      |
| `datum`    | Each xy mark                                                                                                                  |
| `series`   | Each xy series                                                                                                                |
| `legend`   | Each legend item                                                                                                              |
| `category` | Each entry of an `XyScene`'s `categories`: every x position with data, in axis order, with its label as the x axis formats it |

`datum`, `series` and `legend` selections also carry the data layer and y-entry reference (`series`) and the encoded `seriesKey` required by `ChartEvent`.
A renderer raises events with two helpers, so every renderer raises the same event for the same gesture:
- `selectEvent(nodeId, selection, negate?)` returns the `chart.select` event for a selection.
- `brushEvent(scene, nodeId, [from, to])` returns the `chart.brush` event for a range along the brush column of an xy or heatmap Scene, or `undefined` when the node offers no brush. Its description names each end by the nearest x position in `categories` (a heat map's `x.categories`); on an ordinal axis, whose positions are not numbers, it names only the column.


## `SceneRenderer`

```ts
interface SceneRenderer<TOutput = unknown> {
  id: string;
  environments: Array<'browser' | 'node'>;
  sized?: boolean;
  fluid?: boolean;
  supports(kind: SceneKind): boolean;
  render(scene: Scene, env: SceneRenderEnv): TOutput;
}
```

This interface describes a renderer. `TOutput` is what the renderer produces, such as a React node. `selectSceneRenderer(preferences, kind, environment)` picks the first renderer in a preference list that runs in the current environment and supports the Scene's kind; [Rendering](https://docs-v3-preview.elastic.dev/isomer/primitives/charts/rendering) covers where the pack takes the list from and its fallback.
A `sized` renderer, such as one that draws an SVG, always gets a Scene with a `size`; in a browser, a `fluid` renderer fills a box shaped by the chart's size spec ([Chart size](/isomer/primitives/charts/rendering#chart-size)). A renderer that is neither sizes itself, as the summary fallback does.
`SceneRenderEnv` carries the `environment`, the node's `id`, `fillWidth` when the Scene's `size.width` is a layout estimate and the container's width is the drawn one (a chart in a [grid](/isomer/primitives/charts/rendering#grid) the host gave no `size`), and the host's `onEvent`, which receives each [`ChartEvent`](/isomer/primitives/charts/interactions#chartevent). Without `onEvent` a renderer offers no interaction. It also carries the render's `resolveClassName`, through which a renderer drawing with the pack's own styles, such as its table, resolves its classes.
`metricSingleValueScene`, `xyTimeSeriesScene` and `xyInteractiveScene` are hand-written Scenes for three schema examples, for building and testing a renderer without the resolver. `xyInteractiveScene`'s selections raise exactly the events in `chartEventExamples`.