Documentation / Dashboards
ChartFacets
Small multiples: one chart of the kit repeated over a dimension (a region, a product, a channel), every panel on the same scale. It is not a chart but a layout — and it is the answer ScatterChart (capped at three series) and PieChart (which folds its tail) already give: the rest belongs in separate panels.
The only computation it does is the one that matters: the value domain is measured over the whole dataset (the fields listed in values) then handed to every panel through the render prop. Pass it to the chart (y={{ domain }}): panels on free scales look comparable and are not. Past 12 panels, a warning reminds you to filter.
No hooks: the grid is CSS, the component renders on the server.
Examples
Small multiples of lines
by picks the field that splits the panels, values the fields the shared domain is measured on.
import { ChartFacets, LineChart } from "@synertech/ui";
const revenueByRegion: Record<string, number[]> = {
Québec: [92, 98, 96, 118, 126, 141],
Ontario: [210, 204, 218, 212, 226, 219],
Alberta: [48, 54, 61, 58, 72, 84],
"Colombie-Britannique": [76, 81, 79, 88, 94, 103],
Maritimes: [22, 24, 23, 27, 26, 31],
Manitoba: [34, 33, 38, 41, 39, 44],
};
const months = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin"];
const rows = Object.entries(revenueByRegion).flatMap(([region, values]) =>
values.map((revenue, index) => ({ region, month: months[index], revenue }))
);
const kEuro = (value: number) => `${value} k€`;
export function Basic() {
return (
<ChartFacets data={rows} by="region" values={["revenue"]} minPanelWidth={240}>
{({ data, domain, label }) => (
<LineChart
data={data}
series={[{ key: "revenue", label: "Revenu" }]}
x={{ key: "month" }}
y={{ domain, format: kEuro }}
plotLabel={label}
height={130}
legend={false}
size="sm"
/>
)}
</ChartFacets>
);
}Sorted bars, three columns
A bar is read by its length: includeZero keeps the baseline in the shared domain. sort="desc" orders the panels by decreasing total.
import { BarChart, ChartFacets } from "@synertech/ui";
const revenueByRegion: Record<string, number[]> = {
Québec: [92, 98, 96, 118, 126, 141],
Ontario: [210, 204, 218, 212, 226, 219],
Alberta: [48, 54, 61, 58, 72, 84],
"Colombie-Britannique": [76, 81, 79, 88, 94, 103],
Maritimes: [22, 24, 23, 27, 26, 31],
Manitoba: [34, 33, 38, 41, 39, 44],
};
const months = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin"];
const rows = Object.entries(revenueByRegion).flatMap(([region, values]) =>
values.map((revenue, index) => ({ region, month: months[index], revenue }))
);
const kEuro = (value: number) => `${value} k€`;
export function SortedBars() {
return (
<ChartFacets
data={rows}
by="region"
values={["revenue"]}
includeZero
sort="desc"
columns={3}
title="Revenu par région"
description="Panneaux classés du plus gros au plus petit total"
>
{({ data, domain, label }) => (
<BarChart
data={data}
series={[{ key: "revenue", label: "Revenu" }]}
x={{ key: "month" }}
y={{ domain, format: kEuro }}
plotLabel={label}
height={140}
legend={false}
size="sm"
/>
)}
</ChartFacets>
);
}A row of sparklines
Sparkline and ChartFacets use no hooks: this row renders entirely on the server. The shared domain makes the shapes comparable.
import { ChartFacets, Sparkline } from "@synertech/ui";
const revenueByRegion: Record<string, number[]> = {
Québec: [92, 98, 96, 118, 126, 141],
Ontario: [210, 204, 218, 212, 226, 219],
Alberta: [48, 54, 61, 58, 72, 84],
"Colombie-Britannique": [76, 81, 79, 88, 94, 103],
Maritimes: [22, 24, 23, 27, 26, 31],
Manitoba: [34, 33, 38, 41, 39, 44],
};
const months = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin"];
const rows = Object.entries(revenueByRegion).flatMap(([region, values]) =>
values.map((revenue, index) => ({ region, month: months[index], revenue }))
);
export function SparklineRow() {
return (
<ChartFacets data={rows} by="region" values={["revenue"]} columns={3} minPanelWidth={160}>
{({ data, domain, label }) => (
<Sparkline
data={data.map((row) => Number(row.revenue))}
domain={domain}
ariaLabel={`Revenu, ${label}`}
height={36}
area
/>
)}
</ChartFacets>
);
}Explicit order and fixed bounds
order sets the panels (missing values are ignored), domain replaces the measured bounds and formatLabel rewrites the captions.
import { ChartFacets, LineChart } from "@synertech/ui";
const revenueByRegion: Record<string, number[]> = {
Québec: [92, 98, 96, 118, 126, 141],
Ontario: [210, 204, 218, 212, 226, 219],
Alberta: [48, 54, 61, 58, 72, 84],
"Colombie-Britannique": [76, 81, 79, 88, 94, 103],
Maritimes: [22, 24, 23, 27, 26, 31],
Manitoba: [34, 33, 38, 41, 39, 44],
};
const months = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin"];
const rows = Object.entries(revenueByRegion).flatMap(([region, values]) =>
values.map((revenue, index) => ({ region, month: months[index], revenue }))
);
const kEuro = (value: number) => `${value} k€`;
export function FixedOrderAndDomain() {
return (
<ChartFacets
data={rows}
by="region"
values={["revenue"]}
order={["Ontario", "Québec", "Alberta"]}
domain={[0, 250]}
formatLabel={(value, index) => `${index + 1}. ${String(value)}`}
columns={3}
size="sm"
>
{({ data, domain, label }) => (
<LineChart
data={data}
series={[{ key: "revenue", label: "Revenu" }]}
x={{ key: "month", hidden: true }}
y={{ domain, format: kEuro }}
plotLabel={label}
height={110}
legend={false}
size="sm"
/>
)}
</ChartFacets>
);
}Several series per panel, and the empty state
With two series, list both in values: the domain then covers actual and target. emptyState is shown when no panel is left.
import { ChartFacets, EmptyState, LineChart } from "@synertech/ui";
const revenueByRegion: Record<string, number[]> = {
Québec: [92, 98, 96, 118, 126, 141],
Ontario: [210, 204, 218, 212, 226, 219],
Alberta: [48, 54, 61, 58, 72, 84],
"Colombie-Britannique": [76, 81, 79, 88, 94, 103],
Maritimes: [22, 24, 23, 27, 26, 31],
Manitoba: [34, 33, 38, 41, 39, 44],
};
const months = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin"];
const rows = Object.entries(revenueByRegion).flatMap(([region, values]) =>
values.map((revenue, index) => ({ region, month: months[index], revenue }))
);
const kEuro = (value: number) => `${value} k€`;
export function TargetVsActual() {
const withTarget = rows.map((row) => ({ ...row, target: 100 }));
return (
<ChartFacets
data={withTarget.filter((row) => row.region !== "Ontario")}
by="region"
values={["revenue", "target"]}
title="Réel et objectif"
emptyState={
<EmptyState
size="sm"
title="Aucune région ne correspond aux filtres"
description="Retirez un filtre pour revoir les panneaux."
/>
}
>
{({ data, domain, label }) => (
<LineChart
data={data}
series={[
{ key: "revenue", label: "Réel" },
{ key: "target", label: "Objectif", dashed: true },
]}
x={{ key: "month" }}
y={{ domain, format: kEuro }}
plotLabel={label}
height={130}
legend={false}
size="sm"
/>
)}
</ChartFacets>
);
}API reference
Components
Small multiples: one chart repeated across a dimension, on a shared scale.
Not a chart — a layout. It is the answer two components of the kit already give without it existing: ScatterChart caps itself at three series and PieChart folds its tail, both on the grounds that the rest belongs in separate panels.
What makes it work is the one thing it computes itself: the value domain is measured across the whole set and imposed on every panel. Panels on free scales look comparable and are not, which is worse than not faceting at all.
<ChartFacets data={rows} by="region" values={["revenue"]}>
{({ data, domain, label }) => (
<LineChart
data={data}
series={[{ key: "revenue" }]}
x={{ key: "month" }}
y={{ domain }}
plotLabel={label}
height={140}
/>
)}
</ChartFacets>No hooks: the grid is laid out in CSS, so it renders on the server.
import { ChartFacets } from "@synertech/ui";Props — ChartFacetsProps
| Prop | Type | Default | Description |
|---|---|---|---|
by• |
string |
— | Field the panels are split on. |
children• |
(panel: ChartFacetPanel) => ReactNode |
— | |
data• |
ChartDatum[] |
— | |
values• |
string[] |
— | Fields the shared domain is measured over — the series each panel draws. |
columns |
number |
— | Fixed number of columns. Defaults to as many as |
description |
ReactNode |
— | |
domain |
[number, number] |
— | Fixed bounds instead of the ones measured across the whole set. |
emptyState |
ReactNode |
— | What is drawn when there is no panel, usually an |
formatLabel |
(value: ChartXValue, index: number) => string |
— | |
includeZero |
boolean |
false |
Keeps zero inside the shared domain. Off by default, which suits the lines and sparklines a facet grid usually holds; turn it on for bars, which are read for the length of their mark. |
locale |
string |
— | BCP 47 tag the numbers and the dates are written in. Defaults to the language of the runtime. This component renders on the server and reads no context: the |
minPanelWidth |
number |
220 |
Narrowest a panel may get before the grid drops to fewer columns. |
order |
ChartXValue[] |
— | Explicit panel order. Values missing from the data are skipped. |
showLabels |
boolean |
true |
Hides the panel captions — for a grid whose charts carry their own title. |
size |
ChartSize |
"md" |
|
sort |
"none" | "asc" | "desc" |
"none" |
Orders the panels by their total instead. |
ticks |
number |
5 |
Target tick count, which drives how the shared bounds are rounded. |
title |
ReactNode |
— |
+ 277 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
Functions
resetFacetWarnings
FunctionResets the one-shot panel-count warning. Test helper.
import { resetFacetWarnings } from "@synertech/ui";resetFacetWarnings(): voidTypes
ChartFacetPanel
InterfaceOne panel, ready to be drawn.
interface ChartFacetPanel| Field | Type | Default | Description |
|---|---|---|---|
count• |
number |
— | |
data• |
ChartDatum[] |
— | The rows belonging to this panel, in their original order. |
domain• |
[number, number] |
— | The value domain EVERY panel has to draw against. Hand it straight to the chart: panels on free scales cannot be compared, which is the only reason to put them side by side. |
index• |
number |
— | |
key• |
string |
— | Stable identity of the panel — the raw value of the splitting field. |
label• |
string |
— | That value, formatted. |