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.
const AreaChart: MemoExoticComponent<(__namedParameters: AreaChartProps) => Element>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.
const BarChart: MemoExoticComponent<(__namedParameters: BarChartProps) => Element>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.
const LineChart: MemoExoticComponent<(__namedParameters: LineChartProps) => Element>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.
const ScatterChart: MemoExoticComponent<(__namedParameters: ScatterChartProps) => Element>SparklineComponent#
Renders a trend line sized to its box, lowest value at the bottom.
const Sparkline: MemoExoticComponent<(__namedParameters: SparklineProps) => Element>TrendComponent#
Renders the latest value, its change since the first point, and the chart.
const Trend: MemoExoticComponent<(__namedParameters: TrendProps) => Element>Functions#
fitTextFunction#
text cut with an ellipsis to fit max pixels in font, or whole when it fits.
function fitText(text: string, max: number, font: string): stringParameters
| Name | Type | Description |
|---|---|---|
| text | string | The label. |
| max | number | The room, in CSS pixels. |
| font | string | The CSS font shorthand it is drawn in. |
Returns
stringmeasureTextFunction#
The width of text in font (a CSS font shorthand, such as 10px system-ui), in CSS pixels.
function measureText(text: string, font: string): numberParameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to measure. |
| font | string | The CSS font shorthand it is drawn in. |
Returns
numberseriesColorFunction#
The color of series index, as a theme variable.
function seriesColor(index: number, count?: number): stringParameters
| Name | Type | Description |
|---|---|---|
| index | number | 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, |
Returns
stringConstants#
BASELINE_COLORConstant#
The muted color of a baseline series.
const BASELINE_COLOR = 'var(--zg-chart-baseline)'SCATTER_LABELS_MAXConstant#
At most this many points carry a label (CH19): the subject, the extremes, the outliers.
const SCATTER_LABELS_MAX = 8SERIES_COLORSConstant#
How many series colors the theme defines (--zg-chart-1 to --zg-chart-6).
const SERIES_COLORS = 6Interfaces#
AreaChartPropsInterface#
Props for AreaChart.
interface AreaChartProps extends XYChartPropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
axisTitles?from XYChartProps | { x?: string; y?: string } | The axis titles, with their units: | |
className?from XYChartProps | string | Extra classes on the root element. | |
| curve? | 'linear' | 'smooth' | 'linear' |
|
format?from XYChartProps | (value: number) => string | Formats a y value for the axis. Default: the number in full, short past 10,000. | |
height?from XYChartProps | number | Height in pixels. Default: 180. | |
highlight?from XYChartProps | ChartHighlight | One series to emphasize (the others dim) and an x value to mark with a line. | |
label?from XYChartProps | string | The chart's accessible name. | |
marks?from XYChartProps | readonly ChartMark[] | Rules at an x, lines at a y and shaded x ranges, in data units. | |
seriesfrom XYChartProps | readonly 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 XYChartProps | CSSProperties | Inline styles on the root element. | |
tickUnit?from XYChartProps | boolean | true | The unit on the value axis's top tick. Off when the axis title says it. |
time?from XYChartProps | boolean | x values are times in milliseconds. | |
title?from XYChartProps | ReactNode | A visible title above the plot, with the legend beside it. | |
unit?from XYChartProps | string | The y values' unit, for example | |
width?from XYChartProps | number | 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 | |
zoomable?from XYChartProps | boolean | The wheel, a pinch and |
BarChartPropsInterface#
Props for BarChart.
interface BarChartPropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| axisTitles? | { x?: string; y?: string; y2?: string } | The axis titles, with their units: | |
| 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 ( | |
| 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. | |
| 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. | |
| rows | readonly BarRow[] | The categories, each with one value per series. | |
| series | readonly 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? | boolean | true | 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 | |
| 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 |
BarOverlayInterface#
A series a BarChart draws as a line over its bars.
interface BarOverlayProperties
| Name | Type | Default | Description |
|---|---|---|---|
| axis? | 'right' | 'left' |
| |
| color? | string | Its color, as a theme variable. Default: a color apart from the bars'. | |
| dots? | boolean | true | Dots on its values while they stay apart. |
| format? | (value: number) => string | Formats its values. Default: the chart's. | |
| series | number | The index of the series in | |
| unit? | string | Its unit, for the right axis and the tooltip. Default: the chart's. | |
| values? | readonly (number | null)[] | Its values per row, with | |
| width? | number | 2 | Its stroke width in pixels. |
ChartSeriesInterface#
One named series of points.
interface ChartSeriesProperties
| Name | Type | Description |
|---|---|---|
| label | string | The series name, for the legend. |
| points | readonly ChartPoint[] | The points, in x order for lines and areas. |
LineChartPropsInterface#
Props for LineChart.
interface LineChartProps extends XYChartPropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
axisTitles?from XYChartProps | { x?: string; y?: string } | The axis titles, with their units: | |
className?from XYChartProps | string | Extra classes on the root element. | |
| curve? | 'linear' | 'smooth' | 'linear' |
|
| endLabel? | 'name' | 'value' | 'none' | What each line's end says. | |
format?from XYChartProps | (value: number) => string | Formats a y value for the axis. Default: the number in full, short past 10,000. | |
height?from XYChartProps | number | Height in pixels. Default: 180. | |
highlight?from XYChartProps | ChartHighlight | One series to emphasize (the others dim) and an x value to mark with a line. | |
label?from XYChartProps | string | The chart's accessible name. | |
marks?from XYChartProps | readonly ChartMark[] | Rules at an x, lines at a y and shaded x ranges, in data units. | |
seriesfrom XYChartProps | readonly ChartSeries[] | The series. | |
style?from XYChartProps | CSSProperties | Inline styles on the root element. | |
tickUnit?from XYChartProps | boolean | true | The unit on the value axis's top tick. Off when the axis title says it. |
time?from XYChartProps | boolean | x values are times in milliseconds. | |
title?from XYChartProps | ReactNode | A visible title above the plot, with the legend beside it. | |
unit?from XYChartProps | string | The y values' unit, for example | |
width?from XYChartProps | number | 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 | |
| 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 XYChartProps | boolean | The wheel, a pinch and |
ScatterChartPropsInterface#
Props for ScatterChart.
interface ScatterChartProps extends XYChartPropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
axisTitles?from XYChartProps | { x?: string; y?: string } | The axis titles, with their units: | |
className?from XYChartProps | string | Extra classes on the root element. | |
| fit? | 'none' | 'linear' |
| |
format?from XYChartProps | (value: number) => string | Formats a y value for the axis. Default: the number in full, short past 10,000. | |
height?from XYChartProps | number | Height in pixels. Default: 180. | |
highlight?from XYChartProps | ChartHighlight | One series to emphasize (the others dim) and an x value to mark with a line. | |
label?from XYChartProps | string | The chart's accessible name. | |
marks?from XYChartProps | readonly 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 ( | |
| pointSizes? | readonly readonly (number | null | undefined)[][] | A size per point, per series: the point's area follows it (a bubble chart). | |
| radius? | number | 4.5 | Each point's radius in pixels, when no size is given. |
seriesfrom XYChartProps | readonly 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 XYChartProps | CSSProperties | 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 XYChartProps | boolean | true | The unit on the value axis's top tick. Off when the axis title says it. |
time?from XYChartProps | boolean | x values are times in milliseconds. | |
title?from XYChartProps | ReactNode | A visible title above the plot, with the legend beside it. | |
unit?from XYChartProps | string | The y values' unit, for example | |
width?from XYChartProps | number | 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 | |
| xScale? | 'log' | 'linear' |
| |
| yScale? | 'log' | 'linear' |
| |
zoomable?from XYChartProps | boolean | The wheel, a pinch and |
SparklinePropsInterface#
Props for Sparkline.
interface SparklinePropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| className? | string | Extra classes on the SVG. | |
| height? | number | 24 | 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 | |
| style? | CSSProperties | Inline styles on the SVG. | |
| tone? | SparklineTone | 'series' | The line's color. |
| values | readonly number[] | The values, oldest first. | |
| width? | number | 96 | Width in pixels. |
TrendPropsInterface#
Props for Trend.
interface TrendPropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| 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. |
| height? | number | 270 | 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' |
|
| points | readonly TrendPoint[] | The points, oldest first. | |
| size? | 'stat' | 'headline' | 'stat' |
|
| style? | CSSProperties | Inline styles on the root element. | |
| summary? | boolean | true | 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 | |
| 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. |
XYChartPropsInterface#
Props every x/y chart takes.
interface XYChartPropsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| axisTitles? | { x?: string; y?: string } | The axis titles, with their units: | |
| 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. | |
| series | readonly ChartSeries[] | The series. | |
| style? | CSSProperties | Inline styles on the root element. | |
| tickUnit? | boolean | true | 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 | |
| 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 | |
| zoomable? | boolean | The wheel, a pinch and |
Types#
BarRowType#
One category: its label, then one value per series.
type BarRow = readonly [label: string, values: readonly number[]]ChartPointType#
One point: x, then y. With time, x is a time in milliseconds.
type ChartPoint = readonly [x: number, y: number]SparklineToneType#
The color of a Sparkline.
type SparklineTone = 'series' | 'positive' | 'negative' | 'neutral'TrendModeType#
How a Trend draws its points.
type TrendMode = 'auto' | 'line' | 'bars'TrendPointType#
One point: its label (a date, a run) and its value.
type TrendPoint = readonly [label: string, value: number]