legacyMetric
Large values with a label above or below each, on the chart core. Lens's legacy metric and the aggregation-based metric visualization (expression_legacy_metric) materialize into it. Each metrics column of each row is one tile; the tiles are centered in the chart and wrap onto more rows when they do not fit across it.
It is its own primitive, not a metric variant. Kibana draws it without Elastic Charts, as plain text with no tile frame, sized by fixed type steps and shrunk to fit; it shows several columns at once, and has none of metric's secondary value, progress bar, trend or icon. A host that shows a Lens legacy metric builds a legacyMetric; one that shows a Lens metric builds a metric.
| Field | What it is |
|---|---|
metrics |
One or more { column }: the values, in tile order, every row of the first column then of the next |
breakdown |
column: one tile per row, its label led by the row's cell as displayed and " - ", as Kibana's split group labels it |
size |
xs to xxl, default m: the label at EUI's font size for the step (12, 14, 16, 20, 24 or 32 px) and the value at Lens's (24, 40, 50, 60, 80 or 96 px), as Lens's toExpression sets them |
labelPosition |
top (default, as Lens's) or bottom |
textAlign |
How the value and label align with each other within a tile: left (default, as Lens's), center or right |
showLabels |
Whether labels show. Default true |
applyColorTo |
What a colors.bands color paints: background (default) or the value's text |
bandsRange |
absolute (default): band bounds are values. percentage: they are percentages of the range a column's values span, as Kibana's getLegacyMetricDataBounds gives it: its least to its greatest, or for a lone value from 0 to twice it (twice it to 0 when negative, and -50 to 100 for 0) |
interactions, emphasis |
Selectable tiles, a link and static highlights: Interactions |
With colors.bands, a tile of a number column is colored by the band its value falls in; a tile of any other column, or with no value, is not, as Lens colors only numbers. A lone tile's background color fills the whole chart, as Lens's colorFullBackground does; several tiles each fill their own box. On a colored background the value and label are in the panel's text color, as Kibana leaves them, unless EUI's isColorDark finds the color dark, as Kibana's needsLightText does: then they are in EUI's emptyShade, the chrome background (white in light, and #111C2C in dark, as Kibana writes it). colors.byKey is not read. A chart with no rows says "No results found".
The fewest fields that validate and draw, one value from one row:
import type { LegacyMetricNode } from '@elastic/isomer-primitives-charts/schema';
const requests: LegacyMetricNode = {
type: 'legacyMetric',
data: {
columns: [
{
id: 'count',
label: 'Count of records',
type: 'number',
role: 'metric',
},
],
rows: [[14074]],
},
metrics: [{ column: 'count' }],
};
A typical panel, one tile per host with each value's text colored by where it falls between the least and the greatest:
import type { LegacyMetricNode } from '@elastic/isomer-primitives-charts/schema';
const memoryByHost: LegacyMetricNode = {
type: 'legacyMetric',
title: 'Memory used by host',
data: {
columns: [
{ id: 'host', label: 'host.name', type: 'string', role: 'dimension' },
{
id: 'used',
label: 'Memory used',
type: 'number',
role: 'metric',
format: { kind: 'bytes', maximumFractionDigits: 1 },
},
],
rows: [
['web-01', 412000000000],
['web-02', 98000000000],
['Other', 1250000000000],
],
},
metrics: [{ column: 'used' }],
breakdown: { column: 'host' },
size: 's',
applyColorTo: 'value',
bandsRange: 'percentage',
colors: {
bands: [
{ to: 33, color: { light: '#209280', dark: '#209280' } },
{ from: 33, to: 66, color: { light: '#D6BF57', dark: '#D6BF57' } },
{ from: 66, color: { light: '#CC5642', dark: '#CC5642' } },
],
},
interactions: { select: ['tile'] },
};
Rules:
- Every column reference names a column in
data.columns. - Each
metricscolumn is named once, and thebreakdowncolumn is not one of them. - Without a
breakdown,dataholds at most one row. - A
bandsRangeneedscolors.bands. - Emphasis rows are indexes into
data.rows.
The Scene's kind is legacyMetric. Expected values come from Kibana's legacy metric (MetricVisComponent, MetricVisValue and withAutoScale) and Lens's toExpression:
- Tiles, metric by metric and row by row: each tile's value is its cell as displayed (its
displaystring, else its format), and its label the column's label, after the breakdown cell and " - " with abreakdown. - Colors: a band's color on the tile's background (or the chart's, for a lone tile), or on the value's text; else the chrome text color on the chrome background.
- Type: the value's and label's font sizes for
size, 1.5 times as tall in line height, the value at weight 600, and 16 px of padding around them: Lens'sfontarguments and the container'seuiTheme.size.base. - Fit: with a
size, each tile shrinks aswithAutoScaleshrinks it, by the smaller of the chart's width and height over the tile's, no further than three tenths and never grown, so its type sizes and padding in the Scene are the shrunk ones. When the tiles, wrapped into rows across the chart, would still overrun its height less the emphasis notes', they shrink further together, each to the largest common scale at which they fit and no further than three tenths. A tile's box is estimated from Inter's character widths, a full-width CJK character at an em, rounded up so a tile shrinks rather than clips; the renderer lays each tile out from its box's width, growing to text the host's font sets wider, and the drawn text still truncates with an ellipsis where it meets the chart's edge. - Emphasis: an emphasized tile carries its note, and one no band colors, its own or the chart's, is shaded in the table's emphasis color; each note is a line under the tiles.
- Text: each tile's description names its breakdown cell, if any, and its value; the summary sentence states one tile's label and value, lists every tile's, or says the columns have no data.
- Selections: each tile carries a
tileselection when the node offers it: its row, and its breakdown column and cell, if any.
No chart engine draws it: Kibana draws a legacy metric as plain DOM, so the pack's own legacy metric renderer does, the same in the browser and on Node, as the table renderer draws a dataTable. It draws the Scene as a wrapping, centered flex row of tiles that scrolls where it overruns the chart, as Kibana's container does, with the pack's Distillate classes, every per-tile color and length through CSS custom properties, and takumi rasterizes that markup on snapshot. The renderer is sized: without a host size the chart resolves for a 16:9 box at the width the surface lays out in, taller when its tiles and notes wrap to more rows than that holds, and snapshotHeight reports it. Its accessible label is the summary and the description. A selectable tile is a focusable button that raises its selection on click, Enter or Space. Text and Markdown write the summary, the description, each emphasis note and the data table. On Slack it is a picture asset, as the other charts are.
legacyMetricExamples covers one value, a lone value whose band fills the chart, values colored by percentage bands across a breakdown with the Other and missing buckets, several columns of one row, several columns by a breakdown with banded backgrounds, a string, a date and a missing number, a long value shrunk to fit with labels hidden, no rows, and selectable tiles with pre-rendered names, emphasis, a link and provenance.