Skip to content

zidane-ui/charts

import { … } from 'zidane-ui/charts'ui/src/components/charts/index.ts

Components#

AreaChartComponent#

Renders one filled area per series, from zero or stacked. The pointer or the arrow keys show every series' value at an x with a crosshair; a legend entry hides and shows its series.

TypeScript
const AreaChart: MemoExoticComponent<(__namedParameters: AreaChartProps) => Element>

ui/src/components/charts/AreaChart.tsx:51

BarChartComponent#

Renders a bar chart, grouped or stacked, vertical or horizontal. The pointer or the arrow keys show a row's values; a legend entry hides and shows its series.

TypeScript
const BarChart: MemoExoticComponent<(__namedParameters: BarChartProps) => Element>

ui/src/components/charts/BarChart.tsx:271

LineChartComponent#

Renders one line per series. The pointer or the arrow keys show every series' value at an x with a crosshair; a series' end label or legend entry hides and shows it.

TypeScript
const LineChart: MemoExoticComponent<(__namedParameters: LineChartProps) => Element>

ui/src/components/charts/LineChart.tsx:94

ScatterChartComponent#

Renders one dot per point, colored by series. The pointer shows the nearest point with a crosshair; the arrow keys step through the points in x order; a legend entry hides and shows its series.

TypeScript
const ScatterChart: MemoExoticComponent<(__namedParameters: ScatterChartProps) => Element>

ui/src/components/charts/ScatterChart.tsx:239

SparklineComponent#

Renders a trend line sized to its box, lowest value at the bottom.

TypeScript
const Sparkline: MemoExoticComponent<(__namedParameters: SparklineProps) => Element>

ui/src/components/charts/Sparkline.tsx:45

TrendComponent#

Renders the latest value, its change since the first point, and the chart.

TypeScript
const Trend: MemoExoticComponent<(__namedParameters: TrendProps) => Element>

ui/src/components/charts/Trend.tsx:169

Functions#

fitTextFunction#

text cut with an ellipsis to fit max pixels in font, or whole when it fits.

TypeScript
function fitText(text: string, max: number, font: string): string
Parameters
NameTypeDescription
textstring

The label.

maxnumber

The room, in CSS pixels.

fontstring

The CSS font shorthand it is drawn in.

string

ui/src/components/charts/measure.ts:71

measureTextFunction#

The width of text in font (a CSS font shorthand, such as 10px system-ui), in CSS pixels.

TypeScript
function measureText(text: string, font: string): number
Parameters
NameTypeDescription
textstring

The text to measure.

fontstring

The CSS font shorthand it is drawn in.

number

ui/src/components/charts/measure.ts:39

seriesColorFunction#

The color of series index, as a theme variable.

TypeScript
function seriesColor(index: number, count?: number): string
Parameters
NameTypeDescription
indexnumber

The series index, from 0. Past the last color the colors repeat.

count?number

How many series the chart has. Given: one series is the accent, and with more the first is the muted baseline and the next ones start at the accent. Left out: the plain palette, --zg-chart-1 first.

string

ui/src/components/charts/frame.tsx:35

Constants#

BASELINE_COLORConstant#

The muted color of a baseline series.

TypeScript
const BASELINE_COLOR = 'var(--zg-chart-baseline)'

ui/src/components/charts/frame.tsx:25

SCATTER_LABELS_MAXConstant#

At most this many points carry a label (CH19): the subject, the extremes, the outliers.

TypeScript
const SCATTER_LABELS_MAX = 8

ui/src/components/charts/ScatterChart.tsx:41

SERIES_COLORSConstant#

How many series colors the theme defines (--zg-chart-1 to --zg-chart-6).

TypeScript
const SERIES_COLORS = 6

ui/src/components/charts/frame.tsx:22

Interfaces#

AreaChartPropsInterface#

Props for AreaChart.

TypeScript
interface AreaChartProps extends XYChartProps
AreaChartProps properties
NameTypeDefaultDescription
axisTitles?from XYChartProps{ x?: string; y?: string }

The axis titles, with their units: y above the value axis, x under the plot.

className?from XYChartPropsstring

Extra classes on the root element.

curve?'linear' | 'smooth''linear'

smooth bends each edge through its points without overshoot (monotone).

format?from XYChartProps(value: number) => string

Formats a y value for the axis. Default: the number in full, short past 10,000.

height?from XYChartPropsnumber

Height in pixels. Default: 180.

highlight?from XYChartPropsChartHighlight

One series to emphasize (the others dim) and an x value to mark with a line.

label?from XYChartPropsstring

The chart's accessible name.

marks?from XYChartPropsreadonly ChartMark[]

Rules at an x, lines at a y and shaded x ranges, in data units.

seriesfrom XYChartPropsreadonly ChartSeries[]

The series.

stacked?boolean

Stack the series. The series then share their x values by index: the first series' x values place every layer.

style?from XYChartPropsCSSProperties

Inline styles on the root element.

tickUnit?from XYChartPropsbooleantrue

The unit on the value axis's top tick. Off when the axis title says it.

time?from XYChartPropsboolean

x values are times in milliseconds.

title?from XYChartPropsReactNode

A visible title above the plot, with the legend beside it.

unit?from XYChartPropsstring

The y values' unit, for example ms, % or $ (see withUnit).

width?from XYChartPropsnumber

Width in pixels. Default: the container's width.

xFormat?from XYChartProps(value: number) => string

Formats an x value for the axis. Default: a number, or a short date with time.

zoomable?from XYChartPropsboolean

The wheel, a pinch and + / - zoom the x axis, with a reset (for a chart shown full screen).

ui/src/components/charts/AreaChart.tsx:32

BarChartPropsInterface#

Props for BarChart.

TypeScript
interface BarChartProps
BarChartProps properties
NameTypeDefaultDescription
axisTitles?{ x?: string; y?: string; y2?: string }

The axis titles, with their units: y above the value axis, y2 above the overlay's right axis, x under the plot.

className?string

Extra classes on the root element.

format?(value: number) => string

Formats a value for the axis and the data table. Default: the number in full, short past 10,000.

height?number

Height in pixels. Default: from the rows, at most 240 when vertical.

highlight?ChartHighlight

One series to emphasize (the others dim), and a row (at, its index) tinted behind its bars.

horizontal?boolean

Bars run left to right, categories down the left edge. Default: horizontal when a row label is longer than 12 characters or there are more than 8 rows.

label?string

The chart's accessible name.

marks?readonly ChartMark[]

Rules, reference lines and shaded ranges. x, from and to are row indexes (a range from 2.5 to 4.5 covers rows 3 and 4); y is a value. Horizontal bars draw the value lines only.

overlay?BarOverlay

One series drawn as a line with dots over the bars (an average, a rate), on its own right axis when asked. Vertical bars only.

rowsreadonly BarRow[]

The categories, each with one value per series.

seriesreadonly string[]

The series names, in the order of each row's values.

seriesColors?readonly string[]

Each series' color, as theme variables, in place of the color rule (a Trend's weekdays and weekends).

stacked?boolean

Stack the series in one bar. Default: side by side.

style?CSSProperties

Inline styles on the root element.

tickUnit?booleantrue

The unit on the value axis's top tick. Off when the axis title says it.

title?ReactNode

A visible title above the plot, with the legend beside it.

unit?string

The values' unit, for example ms, % or $ (see withUnit).

values?boolean

The value on each bar. Default: when there are 12 bars or fewer.

width?number

Width in pixels. Default: the container's width.

zoomable?boolean

Vertical bars: the wheel, a pinch and + / - zoom into the rows, with a reset (for a chart shown full screen).

ui/src/components/charts/BarChart.tsx:50

BarOverlayInterface#

A series a BarChart draws as a line over its bars.

TypeScript
interface BarOverlay
BarOverlay properties
NameTypeDefaultDescription
axis?'right' | 'left'

right: its own scale and axis on the right. Default: the bars' axis.

color?string

Its color, as a theme variable. Default: a color apart from the bars'.

dots?booleantrue

Dots on its values while they stay apart.

format?(value: number) => string

Formats its values. Default: the chart's.

seriesnumber

The index of the series in series.

unit?string

Its unit, for the right axis and the tooltip. Default: the chart's.

values?readonly (number | null)[]

Its values per row, with null for a gap. Default: the rows' values.

width?number2

Its stroke width in pixels.

ui/src/components/charts/BarChart.tsx:100

ChartSeriesInterface#

One named series of points.

TypeScript
interface ChartSeries
ChartSeries properties
NameTypeDescription
labelstring

The series name, for the legend.

pointsreadonly ChartPoint[]

The points, in x order for lines and areas.

ui/src/components/charts/xy.tsx:36

LineChartPropsInterface#

Props for LineChart.

TypeScript
interface LineChartProps extends XYChartProps
LineChartProps properties
NameTypeDefaultDescription
axisTitles?from XYChartProps{ x?: string; y?: string }

The axis titles, with their units: y above the value axis, x under the plot.

className?from XYChartPropsstring

Extra classes on the root element.

curve?'linear' | 'smooth''linear'

smooth bends each line through its points without overshoot (monotone).

endLabel?'name' | 'value' | 'none'

What each line's end says. name: the series name (the default with 2 to 4 series, in place of a legend). value: the last value. none: nothing.

format?from XYChartProps(value: number) => string

Formats a y value for the axis. Default: the number in full, short past 10,000.

height?from XYChartPropsnumber

Height in pixels. Default: 180.

highlight?from XYChartPropsChartHighlight

One series to emphasize (the others dim) and an x value to mark with a line.

label?from XYChartPropsstring

The chart's accessible name.

marks?from XYChartPropsreadonly ChartMark[]

Rules at an x, lines at a y and shaded x ranges, in data units.

seriesfrom XYChartPropsreadonly ChartSeries[]

The series.

style?from XYChartPropsCSSProperties

Inline styles on the root element.

tickUnit?from XYChartPropsbooleantrue

The unit on the value axis's top tick. Off when the axis title says it.

time?from XYChartPropsboolean

x values are times in milliseconds.

title?from XYChartPropsReactNode

A visible title above the plot, with the legend beside it.

unit?from XYChartPropsstring

The y values' unit, for example ms, % or $ (see withUnit).

width?from XYChartPropsnumber

Width in pixels. Default: the container's width.

xFormat?from XYChartProps(value: number) => string

Formats an x value for the axis. Default: a number, or a short date with time.

yMax?number

The highest value the y axis shows, at least.

yMin?number

The lowest value the y axis shows, at least.

zero?boolean

Start the y axis at zero. Default: only when a value is below zero or the smallest is under 20% of the largest.

zoomable?from XYChartPropsboolean

The wheel, a pinch and + / - zoom the x axis, with a reset (for a chart shown full screen).

ui/src/components/charts/LineChart.tsx:59

ScatterChartPropsInterface#

Props for ScatterChart.

TypeScript
interface ScatterChartProps extends XYChartProps
ScatterChartProps properties
NameTypeDefaultDescription
axisTitles?from XYChartProps{ x?: string; y?: string }

The axis titles, with their units: y above the value axis, x under the plot.

className?from XYChartPropsstring

Extra classes on the root element.

fit?'none' | 'linear'

linear: a dashed least squares line over every shown point, with r and its equation under the plot.

format?from XYChartProps(value: number) => string

Formats a y value for the axis. Default: the number in full, short past 10,000.

height?from XYChartPropsnumber

Height in pixels. Default: 180.

highlight?from XYChartPropsChartHighlight

One series to emphasize (the others dim) and an x value to mark with a line.

label?from XYChartPropsstring

The chart's accessible name.

marks?from XYChartPropsreadonly ChartMark[]

Rules at an x, lines at a y and shaded x ranges, in data units.

pointLabels?readonly readonly (string | null | undefined)[][]

A name per point, per series (null for none): drawn next to the point when there is room.

pointSizes?readonly readonly (number | null | undefined)[][]

A size per point, per series: the point's area follows it (a bubble chart).

radius?number4.5

Each point's radius in pixels, when no size is given.

seriesfrom XYChartPropsreadonly ChartSeries[]

The series.

sizeFormat?(value: number) => string

Formats a size for the legend and the tooltip. Default: the number with its unit.

sizeLabel?string

What the size means, for the size legend.

style?from XYChartPropsCSSProperties

Inline styles on the root element.

subject?string

The name of the point the question is about: drawn larger in the accent, the others in the baseline color, and always labelled.

tickUnit?from XYChartPropsbooleantrue

The unit on the value axis's top tick. Off when the axis title says it.

time?from XYChartPropsboolean

x values are times in milliseconds.

title?from XYChartPropsReactNode

A visible title above the plot, with the legend beside it.

unit?from XYChartPropsstring

The y values' unit, for example ms, % or $ (see withUnit).

width?from XYChartPropsnumber

Width in pixels. Default: the container's width.

xFormat?from XYChartProps(value: number) => string

Formats an x value for the axis. Default: a number, or a short date with time.

xScale?'log' | 'linear'

log: a log x axis (every x above zero).

yScale?'log' | 'linear'

log: a log y axis (every y above zero).

zoomable?from XYChartPropsboolean

The wheel, a pinch and + / - zoom the x axis, with a reset (for a chart shown full screen).

ui/src/components/charts/ScatterChart.tsx:49

SparklinePropsInterface#

Props for Sparkline.

TypeScript
interface SparklineProps
SparklineProps properties
NameTypeDefaultDescription
className?string

Extra classes on the SVG.

height?number24

Height in pixels.

highlight?'none' | 'min' | 'max' | 'last'

A dot on the last, the lowest or the highest value. Default: none.

label?string

Accessible name. Default: the sparklineLabel label.

style?CSSProperties

Inline styles on the SVG.

tone?SparklineTone'series'

The line's color.

valuesreadonly number[]

The values, oldest first.

width?number96

Width in pixels.

ui/src/components/charts/Sparkline.tsx:21

TrendPropsInterface#

Props for Trend.

TypeScript
interface TrendProps
TrendProps properties
NameTypeDefaultDescription
className?string

Extra classes on the root element.

format?(value: number) => string

Formats a value. Default: the number in full, short past 10,000.

goodWhen?'neutral' | 'up' | 'down''neutral'

Which way is good: it colors the change. neutral: never colored.

height?number270

The chart's height in pixels.

highlight?string

The label of a point to mark on the chart.

marks?readonly ChartMark[]

Rules, reference lines and shaded ranges, x in point indexes (0 is the first point).

mode?TrendMode'auto'

auto: bars for daily counts over 14 to 120 days, else a line. line and bars force one.

pointsreadonly TrendPoint[]

The points, oldest first.

size?'stat' | 'headline''stat'

headline: the latest value at the figure step, for the one number that answers a view.

style?CSSProperties

Inline styles on the root element.

summary?booleantrue

Show the latest value and its change above the chart. Off under a view's own answer (a stat row, a headline), where a second headline competes with it.

title?ReactNode

A title above the value. Also the chart's accessible name.

unit?string

The values' unit, for example ms (see withUnit).

width?number

The chart's width in pixels. Default: the container's width.

zero?boolean

Start the y axis at zero. Default: only when a value is below zero or the smallest is under 20% of the largest. Bars always start at zero.

ui/src/components/charts/Trend.tsx:27

XYChartPropsInterface#

Props every x/y chart takes.

TypeScript
interface XYChartProps
XYChartProps properties
NameTypeDefaultDescription
axisTitles?{ x?: string; y?: string }

The axis titles, with their units: y above the value axis, x under the plot.

className?string

Extra classes on the root element.

format?(value: number) => string

Formats a y value for the axis. Default: the number in full, short past 10,000.

height?number

Height in pixels. Default: 180.

highlight?ChartHighlight

One series to emphasize (the others dim) and an x value to mark with a line.

label?string

The chart's accessible name.

marks?readonly ChartMark[]

Rules at an x, lines at a y and shaded x ranges, in data units.

seriesreadonly ChartSeries[]

The series.

style?CSSProperties

Inline styles on the root element.

tickUnit?booleantrue

The unit on the value axis's top tick. Off when the axis title says it.

time?boolean

x values are times in milliseconds.

title?ReactNode

A visible title above the plot, with the legend beside it.

unit?string

The y values' unit, for example ms, % or $ (see withUnit).

width?number

Width in pixels. Default: the container's width.

xFormat?(value: number) => string

Formats an x value for the axis. Default: a number, or a short date with time.

zoomable?boolean

The wheel, a pinch and + / - zoom the x axis, with a reset (for a chart shown full screen).

ui/src/components/charts/xy.tsx:44

Types#

BarRowType#

One category: its label, then one value per series.

TypeScript
type BarRow = readonly [label: string, values: readonly number[]]

ui/src/components/charts/BarChart.tsx:47

ChartPointType#

One point: x, then y. With time, x is a time in milliseconds.

TypeScript
type ChartPoint = readonly [x: number, y: number]

ui/src/components/charts/xy.tsx:33

SparklineToneType#

The color of a Sparkline.

TypeScript
type SparklineTone = 'series' | 'positive' | 'negative' | 'neutral'

ui/src/components/charts/Sparkline.tsx:11

TrendModeType#

How a Trend draws its points.

TypeScript
type TrendMode = 'auto' | 'line' | 'bars'

ui/src/components/charts/Trend.tsx:24

TrendPointType#

One point: its label (a date, a run) and its value.

TypeScript
type TrendPoint = readonly [label: string, value: number]

ui/src/components/charts/Trend.tsx:21