Documentation / Dashboards
ChartSyncProvider
Several panels that read as one object rather than as a row of pictures. ChartFilterBar makes a dashboard a frame; ChartSyncProvider makes it an object: the pointer lands on a moment in one panel and every other panel marks the same moment (dotted crosshair), and a range dragged on one (brush) becomes the window of all of them. Only one tooltip shows at a time: four tooltips are four things to read and no answer.
The provider draws nothing: it holds the two shared states — the hovered position and the selected range (controlled with brush + onBrushChange, or uncontrolled with defaultBrush). A chart leaves the group with sync={false}; hover={false} shares only the range. useChartSync() lets a panel that is not a chart (a figure, a table) stay in step, and brushToPeriod turns a range dragged on a date axis into a ChartPeriod for a ChartPeriodPicker.
A "use client" component (React context). Outside a provider, useChartSync() returns null.
Examples
A non-chart panel in step with the group
useChartSync() exposes hovered (the hovered x value) and brush: here a key figure follows the month under the pointer.
import { AreaChart, ChartSyncProvider, useChartSync } from "@synertech/ui";
const monthly = [
{ month: "Jan", visits: 18200, signups: 640, revenue: 38400 },
{ month: "Fév", visits: 21400, signups: 710, revenue: 41200 },
{ month: "Mar", visits: 19800, signups: 690, revenue: 39800 },
{ month: "Avr", visits: 24600, signups: 820, revenue: 46500 },
{ month: "Mai", visits: 27100, signups: 905, revenue: 48900 },
{ month: "Juin", visits: 30300, signups: 990, revenue: 52300 },
];
function HoveredRevenue() {
const sync = useChartSync();
const row = monthly.find((entry) => entry.month === sync?.hovered) ?? monthly[monthly.length - 1];
return (
<p className="text-sm text-gray-700 dark:text-gray-200">
Revenu {row?.month} : <strong>{row?.revenue.toLocaleString("fr-CA")} $</strong>
</p>
);
}
export function SyncedReadout() {
return (
<ChartSyncProvider>
<div className="flex flex-col gap-3">
<HoveredRevenue />
<AreaChart
data={monthly}
series={[{ key: "visits", label: "Visites" }]}
x={{ key: "month" }}
height={180}
/>
</div>
</ChartSyncProvider>
);
}Controlled range
With brush and onBrushChange, the application holds the range. It carries the values (from, to) and the row indexes (fromIndex, toIndex).
import { useState } from "react";
import { ChartSyncProvider, LineChart, type ChartBrushRange } from "@synertech/ui";
const monthly = [
{ month: "Jan", visits: 18200, signups: 640, revenue: 38400 },
{ month: "Fév", visits: 21400, signups: 710, revenue: 41200 },
{ month: "Mar", visits: 19800, signups: 690, revenue: 39800 },
{ month: "Avr", visits: 24600, signups: 820, revenue: 46500 },
{ month: "Mai", visits: 27100, signups: 905, revenue: 48900 },
{ month: "Juin", visits: 30300, signups: 990, revenue: 52300 },
];
export function ControlledBrush() {
const [brush, setBrush] = useState<ChartBrushRange | null>(null);
return (
<div className="flex flex-col gap-3">
<ChartSyncProvider brush={brush} onBrushChange={setBrush}>
<LineChart
title="Visites"
data={monthly}
series={[{ key: "visits", label: "Visites" }]}
x={{ key: "month" }}
brush
height={200}
/>
</ChartSyncProvider>
<p className="text-sm text-gray-600 dark:text-gray-300">
{brush
? `Plage : ${String(brush.from)} → ${String(brush.to)} (${brush.toIndex - brush.fromIndex + 1} mois)`
: "Aucune plage — glissez sur la courbe, ou Maj + flèches au clavier."}
</p>
</div>
);
}Brushing to reframe the dashboard
brushToPeriod widens the dragged range to whole days and returns it as a period; brush={null} drops the band once it has become the period.
import { useMemo, useState } from "react";
import { AreaChart, ChartFilterBar, ChartPeriodPicker, ChartSyncProvider, LineChart, brushToPeriod, createPeriod, formatPeriodRange, type ChartBrushRange, type ChartPeriod } from "@synertech/ui";
const today = new Date(2026, 7, 29);
const days = Array.from({ length: 90 }, (_, index) => ({
day: new Date(2026, 5, 1 + index),
visits: Math.round(1200 + Math.sin(index / 6) * 180 + index * 9),
signups: Math.round(90 + Math.sin(index / 6) * 45 + index * 0.8),
}));
export function BrushToPeriod() {
const [period, setPeriod] = useState<ChartPeriod>(() => createPeriod("30d", today));
const rows = useMemo(
() => days.filter((row) => row.day >= period.from && row.day <= period.to),
[period]
);
const takeBrush = (range: ChartBrushRange | null) => {
const next = range ? brushToPeriod(range) : null;
if (next) setPeriod(next);
};
return (
<ChartSyncProvider brush={null} onBrushChange={takeBrush}>
<div className="flex flex-col gap-6">
<ChartFilterBar>
<ChartPeriodPicker value={period} onChange={setPeriod} now={today} size="sm" />
<span className="text-xs text-gray-500 dark:text-gray-400">
{formatPeriodRange(period.from, period.to, "fr-CA")}
</span>
</ChartFilterBar>
<LineChart
title="Visites"
description="Glissez une plage pour recadrer tout le tableau de bord."
data={rows}
series={[{ key: "visits", label: "Visites" }]}
x={{ key: "day", scale: "time" }}
brush
height={200}
locale="fr-CA"
/>
<AreaChart
title="Inscriptions"
data={rows}
series={[{ key: "signups", label: "Inscriptions" }]}
x={{ key: "day", scale: "time" }}
height={160}
locale="fr-CA"
/>
</div>
</ChartSyncProvider>
);
}Leaving the group
sync={false} takes out a panel whose axis does not carry the same values; hover={false} on the provider shares only the range.
import { BarChart, ChartSyncProvider, LineChart } from "@synertech/ui";
const monthly = [
{ month: "Jan", visits: 18200, signups: 640, revenue: 38400 },
{ month: "Fév", visits: 21400, signups: 710, revenue: 41200 },
{ month: "Mar", visits: 19800, signups: 690, revenue: 39800 },
{ month: "Avr", visits: 24600, signups: 820, revenue: 46500 },
{ month: "Mai", visits: 27100, signups: 905, revenue: 48900 },
{ month: "Juin", visits: 30300, signups: 990, revenue: 52300 },
];
export function OptOut() {
return (
<ChartSyncProvider hover={false}>
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
<LineChart
title="Visites — dans le groupe"
data={monthly}
series={[{ key: "visits", label: "Visites" }]}
x={{ key: "month" }}
brush
height={180}
/>
<BarChart
title="Revenu par région — hors du groupe"
data={[
{ region: "Québec", revenue: 128000 },
{ region: "Ontario", revenue: 96400 },
]}
series={[{ key: "revenue", label: "Revenu" }]}
x={{ key: "region" }}
sync={false}
height={180}
/>
</div>
</ChartSyncProvider>
);
}API reference
Components
Several charts read as one object rather than as a row of pictures.
ChartFilterBar made a dashboard a frame: one row of filters above panels that therefore answer the same question. This makes it an object: the pointer lands on a moment in one panel and every other panel marks the same moment, and a window dragged on one is the window all of them show.
Nothing is drawn here. The provider holds the two pieces of state a group shares and hands them to whichever panels are inside it; a chart opts out with sync={false}.
const [period, setPeriod] = useState(() => createPeriod("30d"));
<ChartSyncProvider onBrushChange={(range) => range && setPeriod(brushToPeriod(range))}>
<ChartFilterBar>
<ChartPeriodPicker value={period} onChange={setPeriod} />
</ChartFilterBar>
<LineChart brush data={rows} … />
<BarChart data={rows} … />
</ChartSyncProvider>import { ChartSyncProvider } from "@synertech/ui";Props — ChartSyncProviderProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
brush |
ChartBrushRange | null |
— | Controlled selection. Leave unset to let the group hold its own. |
defaultBrush |
ChartBrushRange | null |
null |
Starting selection of an uncontrolled group. |
hover |
boolean |
true |
Shares the hovered position between the panels. The pointer draws a crosshair in every panel and a tooltip in one: four tooltips at once is four things to read and no answer. |
onBrushChange |
(range: ChartBrushRange | null) => void |
— | Called whenever a panel commits a dragged window, or clears it with |
Hooks
The group a chart belongs to, or null when it stands alone.
Public because the two things a group carries — where the pointer is, and what window is selected — are exactly what a panel that is not a chart needs to stay in step: a legend, a figure beside the row, a table.
import { useChartSync } from "@synertech/ui";useChartSync(): ChartSyncContextValue | nullFunctions
brushToPeriod
FunctionA dragged window, as the period a filter row is set to.
The point of brushing: a reader drags a fortnight on the line and the dashboard is now read over that fortnight. Both ends are widened to whole days, the way ChartPeriodPicker resolves its own presets — a window ending at midnight drops its own last day. And the last row counts whole: on monthly rows, a window from January to March runs to the 31st of March, where the interval that row stands for ends, rather than stopping on the 1st.
Answers null when the axis that was brushed carries no date at all. It cannot tell a timestamp from any other number, though — a time axis stores its values as numbers, and so does a linear one. Call it on a chart whose x axis carries dates; on any other the window it returns is arithmetic rather than a period.
import { brushToPeriod } from "@synertech/ui";brushToPeriod(range: ChartBrushRange): ChartPeriod | nullTypes
ChartSyncContextValue
InterfaceWhat every panel of a synchronised group can see and change.
interface ChartSyncContextValue| Field | Type | Default | Description |
|---|---|---|---|
brush• |
ChartBrushRange | null |
— | The window dragged on any panel of the group. |
hovered• |
ChartXValue | null |
— | The position under the pointer, in whichever panel the pointer is in. |
hoverShared• |
boolean |
— |
|
setBrush• |
(range: ChartBrushRange | null) => void |
— | |
setHovered• |
(value: ChartXValue | null) => void |
— |