@gntik-ai/charts 0.5.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +60 -5
- package/dist/index.js +149 -35
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import { TooltipContentProps } from "recharts";
|
|
3
2
|
import { FocusEvent, ReactNode, Ref, SVGAttributes } from "react";
|
|
3
|
+
import { TooltipContentProps } from "recharts";
|
|
4
4
|
import { Theme } from "@gntik-ai/tokens/runtime";
|
|
5
5
|
//#region src/theme.d.ts
|
|
6
6
|
/** Series colour name → brand token. Green primary is the hero; the rest are categorical accents. */
|
|
@@ -104,7 +104,7 @@ interface ChartLoadingProps {
|
|
|
104
104
|
className?: string;
|
|
105
105
|
}
|
|
106
106
|
/** Skeleton plot (bars over a baseline); the pulse stops under prefers-reduced-motion. */
|
|
107
|
-
export declare function ChartLoading({ height, label, className }: ChartLoadingProps): import("react").JSX.Element;
|
|
107
|
+
export declare function ChartLoading({ height, label: labelProp, className }: ChartLoadingProps): import("react").JSX.Element;
|
|
108
108
|
interface ChartErrorProps {
|
|
109
109
|
height?: number;
|
|
110
110
|
children?: ReactNode;
|
|
@@ -177,7 +177,7 @@ interface ChartBrushProps {
|
|
|
177
177
|
* Range brush under a time-series chart: two keyboard-accessible handles (`role="slider"`,
|
|
178
178
|
* Arrow keys ±1, PageUp/PageDown ±10%, Home/End) and a draggable window to pan.
|
|
179
179
|
*/
|
|
180
|
-
export declare function ChartBrush({ length, range, onRangeChange, labelOf, preview, label, className }: ChartBrushProps): import("react").JSX.Element | null;
|
|
180
|
+
export declare function ChartBrush({ length, range, onRangeChange, labelOf, preview, label: labelProp, className }: ChartBrushProps): import("react").JSX.Element | null;
|
|
181
181
|
//#endregion
|
|
182
182
|
//#region src/overlays.d.ts
|
|
183
183
|
/** Semantic tone of a threshold or annotation (maps to a brand token, never a raw colour). */
|
|
@@ -252,6 +252,61 @@ interface AreaChartProps<T extends object> extends CartesianExtrasProps, BaseCha
|
|
|
252
252
|
/** Area chart: flat fills (no gradient), no entry animation, interactive legend. */
|
|
253
253
|
export declare function AreaChart<T extends object>({ data, index, categories, colors, valueFormatter, stacked, showLegend, showGrid, showYAxis, curve, height, title, description, className, 'aria-label': ariaLabel, state, emptyMessage, errorMessage, onRetry, dataTable, thresholds, annotations, brush, range, defaultRange, onRangeChange, animate }: AreaChartProps<T>): import("react").JSX.Element;
|
|
254
254
|
//#endregion
|
|
255
|
+
//#region src/i18n.d.ts
|
|
256
|
+
/** Strings rendered by charts; series names and number/date formatting belong to the caller. */
|
|
257
|
+
interface ChartLabels {
|
|
258
|
+
loading: string;
|
|
259
|
+
empty: string;
|
|
260
|
+
error: string;
|
|
261
|
+
retry: string;
|
|
262
|
+
zoomRange: string;
|
|
263
|
+
rangeStart: string;
|
|
264
|
+
rangeEnd: string;
|
|
265
|
+
resetZoom: string;
|
|
266
|
+
markers: string;
|
|
267
|
+
threshold: string;
|
|
268
|
+
/** Prefix with an `{x}` placeholder for the annotation's x value. */
|
|
269
|
+
markerAt: string;
|
|
270
|
+
stages: string;
|
|
271
|
+
stage: string;
|
|
272
|
+
conversion: string;
|
|
273
|
+
dropOff: string;
|
|
274
|
+
dropOffPrefix: string;
|
|
275
|
+
from: string;
|
|
276
|
+
to: string;
|
|
277
|
+
value: string;
|
|
278
|
+
barChart: string;
|
|
279
|
+
lineChart: string;
|
|
280
|
+
areaChart: string;
|
|
281
|
+
comboChart: string;
|
|
282
|
+
donutChart: string;
|
|
283
|
+
pieChart: string;
|
|
284
|
+
funnelChart: string;
|
|
285
|
+
sankeyChart: string;
|
|
286
|
+
heatmap: string;
|
|
287
|
+
colourGrid: string;
|
|
288
|
+
radarChart: string;
|
|
289
|
+
barList: string;
|
|
290
|
+
bars: string;
|
|
291
|
+
}
|
|
292
|
+
export declare const en: Readonly<ChartLabels>;
|
|
293
|
+
export declare const es: Readonly<ChartLabels>;
|
|
294
|
+
export declare const chartLabelSets: {
|
|
295
|
+
en: Readonly<ChartLabels>;
|
|
296
|
+
es: Readonly<ChartLabels>;
|
|
297
|
+
};
|
|
298
|
+
interface ChartLocaleProviderProps {
|
|
299
|
+
/** Language subtag selects en/es; unknown locales fall back to English. */
|
|
300
|
+
locale?: string;
|
|
301
|
+
/** Per-key overrides, after selecting the built-in language. Explicit chart props still win. */
|
|
302
|
+
labels?: Partial<ChartLabels>;
|
|
303
|
+
children?: ReactNode;
|
|
304
|
+
}
|
|
305
|
+
/** Strings-only locale provider for standalone charts, independent of @gntik-ai/ui. */
|
|
306
|
+
export declare function ChartLocaleProvider({ locale, labels, children }: ChartLocaleProviderProps): import("react").JSX.Element;
|
|
307
|
+
/** Active chart labels, or English outside a ChartLocaleProvider. */
|
|
308
|
+
export declare function useChartLabels(): Readonly<ChartLabels>;
|
|
309
|
+
//#endregion
|
|
255
310
|
//#region src/BarChart.d.ts
|
|
256
311
|
interface BarChartProps<T extends object> extends CartesianExtrasProps, BaseChartProps<T> {
|
|
257
312
|
categories: ReadonlyArray<DataKey<T>>;
|
|
@@ -330,7 +385,7 @@ interface BarListProps<T extends object> extends Omit<ChartStateProps, 'dataTabl
|
|
|
330
385
|
className?: string;
|
|
331
386
|
}
|
|
332
387
|
/** Axis-less ranked list: label inside a token-tinted bar, value on the right. */
|
|
333
|
-
export declare function BarList<T extends object>({ data, index, category, valueFormatter, color, sortOrder, className, 'aria-label':
|
|
388
|
+
export declare function BarList<T extends object>({ data, index, category, valueFormatter, color, sortOrder, className, 'aria-label': ariaLabelProp, state, emptyMessage, errorMessage, onRetry }: BarListProps<T>): import("react").JSX.Element;
|
|
334
389
|
//#endregion
|
|
335
390
|
//#region src/ChartTooltip.d.ts
|
|
336
391
|
/** The subset of a Recharts tooltip payload entry the brand tooltip reads. */
|
|
@@ -638,5 +693,5 @@ interface LiveSeries<T> {
|
|
|
638
693
|
*/
|
|
639
694
|
export declare function useLiveSeries<T>({ initial, windowSize, pauseOnInteraction }?: UseLiveSeriesOptions<T>): LiveSeries<T>;
|
|
640
695
|
//#endregion
|
|
641
|
-
export type { AreaChartProps, BarChartProps, BarListProps, BaseChartProps, CartesianExtrasProps, ChartAnnotation, ChartBrushProps, ChartColor, ChartDataTableProps, ChartEmptyProps, ChartErrorProps, ChartLegendItem, ChartLegendProps, ChartLoadingProps, ChartMarkersProps, ChartRange, ChartState, ChartStateProps, ChartTheme, ChartThreshold, ChartTone, ChartTooltipEntry, ChartTooltipProps, ComboChartProps, DivergingRampOptions, DonutChartProps, FunnelChartProps, FunnelStage, HeatmapProps, LineChartProps, LiveSeries, LiveSeriesPauseProps, MiniBarProps, MiniBarTone, RadarChartProps, SankeyChartProps, SankeyLinkDatum, SankeyNodeDatum, SequentialRampOptions, TokenName, UseChartRangeOptions, UseChartThemeOptions, UseLiveSeriesOptions, ValueFormatter };
|
|
696
|
+
export type { AreaChartProps, BarChartProps, BarListProps, BaseChartProps, CartesianExtrasProps, ChartAnnotation, ChartBrushProps, ChartColor, ChartDataTableProps, ChartEmptyProps, ChartErrorProps, ChartLabels, ChartLegendItem, ChartLegendProps, ChartLoadingProps, ChartLocaleProviderProps, ChartMarkersProps, ChartRange, ChartState, ChartStateProps, ChartTheme, ChartThreshold, ChartTone, ChartTooltipEntry, ChartTooltipProps, ComboChartProps, DivergingRampOptions, DonutChartProps, FunnelChartProps, FunnelStage, HeatmapProps, LineChartProps, LiveSeries, LiveSeriesPauseProps, MiniBarProps, MiniBarTone, RadarChartProps, SankeyChartProps, SankeyLinkDatum, SankeyNodeDatum, SequentialRampOptions, TokenName, UseChartRangeOptions, UseChartThemeOptions, UseLiveSeriesOptions, ValueFormatter };
|
|
642
697
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,101 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import { useCallback, useId, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { createContext, useCallback, useContext, useId, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
4
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, CartesianGrid, ComposedChart, Funnel, FunnelChart as FunnelChart$1, Line, LineChart as LineChart$1, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Radar, RadarChart as RadarChart$1, ReferenceLine, ResponsiveContainer, Sankey, Tooltip, XAxis, YAxis } from "recharts";
|
|
5
5
|
import { currentTheme, observeTheme, tokenColor } from "@gntik-ai/tokens/runtime";
|
|
6
|
+
//#region src/i18n.tsx
|
|
7
|
+
const en = {
|
|
8
|
+
loading: "Loading chart",
|
|
9
|
+
empty: "No data for this period",
|
|
10
|
+
error: "The chart could not be loaded.",
|
|
11
|
+
retry: "Retry",
|
|
12
|
+
zoomRange: "Zoom range",
|
|
13
|
+
rangeStart: "Range start",
|
|
14
|
+
rangeEnd: "Range end",
|
|
15
|
+
resetZoom: "Reset zoom",
|
|
16
|
+
markers: "Chart markers",
|
|
17
|
+
threshold: "Threshold:",
|
|
18
|
+
markerAt: "Marker at {x}:",
|
|
19
|
+
stages: "Stages",
|
|
20
|
+
stage: "Stage",
|
|
21
|
+
conversion: "Conversion",
|
|
22
|
+
dropOff: "Drop-off",
|
|
23
|
+
dropOffPrefix: "drop-off ",
|
|
24
|
+
from: "From",
|
|
25
|
+
to: "To",
|
|
26
|
+
value: "Value",
|
|
27
|
+
barChart: "Bar chart",
|
|
28
|
+
lineChart: "Line chart",
|
|
29
|
+
areaChart: "Area chart",
|
|
30
|
+
comboChart: "Combo chart",
|
|
31
|
+
donutChart: "Donut chart",
|
|
32
|
+
pieChart: "Pie chart",
|
|
33
|
+
funnelChart: "Funnel chart",
|
|
34
|
+
sankeyChart: "Sankey chart",
|
|
35
|
+
heatmap: "Heatmap",
|
|
36
|
+
colourGrid: "colour grid, use the arrow keys to read cells",
|
|
37
|
+
radarChart: "Radar chart",
|
|
38
|
+
barList: "Bar list",
|
|
39
|
+
bars: "Bars"
|
|
40
|
+
};
|
|
41
|
+
const es = {
|
|
42
|
+
loading: "Cargando gráfico",
|
|
43
|
+
empty: "Sin datos para este periodo",
|
|
44
|
+
error: "No se pudo cargar el gráfico.",
|
|
45
|
+
retry: "Reintentar",
|
|
46
|
+
zoomRange: "Rango de zoom",
|
|
47
|
+
rangeStart: "Inicio del rango",
|
|
48
|
+
rangeEnd: "Fin del rango",
|
|
49
|
+
resetZoom: "Restablecer zoom",
|
|
50
|
+
markers: "Marcadores del gráfico",
|
|
51
|
+
threshold: "Umbral:",
|
|
52
|
+
markerAt: "Marcador en {x}:",
|
|
53
|
+
stages: "Etapas",
|
|
54
|
+
stage: "Etapa",
|
|
55
|
+
conversion: "Conversión",
|
|
56
|
+
dropOff: "Abandono",
|
|
57
|
+
dropOffPrefix: "abandono ",
|
|
58
|
+
from: "Origen",
|
|
59
|
+
to: "Destino",
|
|
60
|
+
value: "Valor",
|
|
61
|
+
barChart: "Gráfico de barras",
|
|
62
|
+
lineChart: "Gráfico de líneas",
|
|
63
|
+
areaChart: "Gráfico de áreas",
|
|
64
|
+
comboChart: "Gráfico combinado",
|
|
65
|
+
donutChart: "Gráfico de anillo",
|
|
66
|
+
pieChart: "Gráfico circular",
|
|
67
|
+
funnelChart: "Gráfico de embudo",
|
|
68
|
+
sankeyChart: "Diagrama de Sankey",
|
|
69
|
+
heatmap: "Mapa de calor",
|
|
70
|
+
colourGrid: "cuadrícula de colores, usa las flechas para leer las celdas",
|
|
71
|
+
radarChart: "Gráfico de radar",
|
|
72
|
+
barList: "Lista de barras",
|
|
73
|
+
bars: "Barras"
|
|
74
|
+
};
|
|
75
|
+
const chartLabelSets = {
|
|
76
|
+
en,
|
|
77
|
+
es
|
|
78
|
+
};
|
|
79
|
+
const ChartLabelsContext = createContext(en);
|
|
80
|
+
/** Strings-only locale provider for standalone charts, independent of @gntik-ai/ui. */
|
|
81
|
+
function ChartLocaleProvider({ locale = "en", labels, children }) {
|
|
82
|
+
const value = useMemo(() => {
|
|
83
|
+
const language = locale.split(/[-_]/)[0]?.toLowerCase() ?? "";
|
|
84
|
+
return {
|
|
85
|
+
...Object.hasOwn(chartLabelSets, language) ? chartLabelSets[language] : en,
|
|
86
|
+
...labels
|
|
87
|
+
};
|
|
88
|
+
}, [locale, labels]);
|
|
89
|
+
return /* @__PURE__ */ jsx(ChartLabelsContext.Provider, {
|
|
90
|
+
value,
|
|
91
|
+
children
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** Active chart labels, or English outside a ChartLocaleProvider. */
|
|
95
|
+
function useChartLabels() {
|
|
96
|
+
return useContext(ChartLabelsContext);
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
6
99
|
//#region src/format.ts
|
|
7
100
|
const nf = (opts) => new Intl.NumberFormat("en-US", opts);
|
|
8
101
|
/** Ready-made value formatters (en-US). */
|
|
@@ -81,6 +174,13 @@ function formatBytes(bytes) {
|
|
|
81
174
|
v /= 1e3;
|
|
82
175
|
u += 1;
|
|
83
176
|
}
|
|
177
|
+
if (Number(nf({
|
|
178
|
+
maximumFractionDigits: u === 0 ? 0 : 1,
|
|
179
|
+
useGrouping: false
|
|
180
|
+
}).format(v)) >= 1e3 && u < BYTE_UNITS.length - 1) {
|
|
181
|
+
v /= 1e3;
|
|
182
|
+
u += 1;
|
|
183
|
+
}
|
|
84
184
|
return `${sign}${nf({ maximumFractionDigits: u === 0 ? 0 : 1 }).format(v)} ${BYTE_UNITS[u]}`;
|
|
85
185
|
}
|
|
86
186
|
const identity = (n) => String(n);
|
|
@@ -191,7 +291,8 @@ function tooltipContent(options) {
|
|
|
191
291
|
//#region src/states.tsx
|
|
192
292
|
const stateBox = "flex w-full flex-col items-center justify-center gap-2 rounded-md border border-dashed border-border px-4 text-center";
|
|
193
293
|
/** Placeholder for a chart without data. */
|
|
194
|
-
function ChartEmpty({ height = 240, children
|
|
294
|
+
function ChartEmpty({ height = 240, children, className }) {
|
|
295
|
+
const { empty } = useChartLabels();
|
|
195
296
|
return /* @__PURE__ */ jsxs("div", {
|
|
196
297
|
"data-chart-state": "empty",
|
|
197
298
|
className: cx(stateBox, className),
|
|
@@ -207,7 +308,7 @@ function ChartEmpty({ height = 240, children = "No data for this period", classN
|
|
|
207
308
|
})]
|
|
208
309
|
}), /* @__PURE__ */ jsx("p", {
|
|
209
310
|
className: "text-[13px] text-muted-foreground",
|
|
210
|
-
children
|
|
311
|
+
children: children === void 0 ? empty : children
|
|
211
312
|
})]
|
|
212
313
|
});
|
|
213
314
|
}
|
|
@@ -222,7 +323,9 @@ const SKELETON_BARS = [
|
|
|
222
323
|
54
|
|
223
324
|
];
|
|
224
325
|
/** Skeleton plot (bars over a baseline); the pulse stops under prefers-reduced-motion. */
|
|
225
|
-
function ChartLoading({ height = 240, label
|
|
326
|
+
function ChartLoading({ height = 240, label: labelProp, className }) {
|
|
327
|
+
const { loading } = useChartLabels();
|
|
328
|
+
const label = labelProp ?? loading;
|
|
226
329
|
return /* @__PURE__ */ jsxs("div", {
|
|
227
330
|
role: "status",
|
|
228
331
|
"aria-label": label,
|
|
@@ -240,7 +343,8 @@ function ChartLoading({ height = 240, label = "Loading chart", className }) {
|
|
|
240
343
|
});
|
|
241
344
|
}
|
|
242
345
|
/** Error placeholder with an optional retry action. */
|
|
243
|
-
function ChartError({ height = 240, children
|
|
346
|
+
function ChartError({ height = 240, children, onRetry, className }) {
|
|
347
|
+
const { error, retry } = useChartLabels();
|
|
244
348
|
return /* @__PURE__ */ jsxs("div", {
|
|
245
349
|
role: "alert",
|
|
246
350
|
"data-chart-state": "error",
|
|
@@ -248,12 +352,12 @@ function ChartError({ height = 240, children = "The chart could not be loaded.",
|
|
|
248
352
|
style: { height },
|
|
249
353
|
children: [/* @__PURE__ */ jsx("p", {
|
|
250
354
|
className: "text-[13px] text-destructive-text",
|
|
251
|
-
children
|
|
355
|
+
children: children === void 0 ? error : children
|
|
252
356
|
}), onRetry && /* @__PURE__ */ jsx("button", {
|
|
253
357
|
type: "button",
|
|
254
358
|
onClick: onRetry,
|
|
255
359
|
className: "h-8 rounded-md border border-border bg-card px-3 text-[12.5px] font-medium text-foreground transition-colors hover:bg-secondary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring motion-reduce:transition-none",
|
|
256
|
-
children:
|
|
360
|
+
children: retry
|
|
257
361
|
})]
|
|
258
362
|
});
|
|
259
363
|
}
|
|
@@ -410,7 +514,9 @@ function previewPath(values) {
|
|
|
410
514
|
* Range brush under a time-series chart: two keyboard-accessible handles (`role="slider"`,
|
|
411
515
|
* Arrow keys ±1, PageUp/PageDown ±10%, Home/End) and a draggable window to pan.
|
|
412
516
|
*/
|
|
413
|
-
function ChartBrush({ length, range, onRangeChange, labelOf, preview, label
|
|
517
|
+
function ChartBrush({ length, range, onRangeChange, labelOf, preview, label: labelProp, className }) {
|
|
518
|
+
const labels = useChartLabels();
|
|
519
|
+
const label = labelProp ?? labels.zoomRange;
|
|
414
520
|
const track = useRef(null);
|
|
415
521
|
const drag = useRef(null);
|
|
416
522
|
const last = Math.max(1, length - 1);
|
|
@@ -472,7 +578,7 @@ function ChartBrush({ length, range, onRangeChange, labelOf, preview, label = "Z
|
|
|
472
578
|
return /* @__PURE__ */ jsx("div", {
|
|
473
579
|
role: "slider",
|
|
474
580
|
tabIndex: 0,
|
|
475
|
-
"aria-label": which === "start" ?
|
|
581
|
+
"aria-label": which === "start" ? labels.rangeStart : labels.rangeEnd,
|
|
476
582
|
"aria-orientation": "horizontal",
|
|
477
583
|
"aria-valuemin": which === "start" ? 0 : start + 1,
|
|
478
584
|
"aria-valuemax": which === "start" ? end - 1 : length - 1,
|
|
@@ -541,7 +647,7 @@ function ChartBrush({ length, range, onRangeChange, labelOf, preview, label = "Z
|
|
|
541
647
|
type: "button",
|
|
542
648
|
onClick: () => onRangeChange([0, length - 1]),
|
|
543
649
|
className: cx("px-1 font-medium text-foreground underline-offset-2 hover:underline", "rounded-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring"),
|
|
544
|
-
children:
|
|
650
|
+
children: labels.resetZoom
|
|
545
651
|
})]
|
|
546
652
|
})]
|
|
547
653
|
});
|
|
@@ -866,11 +972,12 @@ function referenceElements({ thresholds = [], annotations = [], vertical = false
|
|
|
866
972
|
* highlights its marker and opens its tooltip in the plot.
|
|
867
973
|
*/
|
|
868
974
|
function ChartMarkers({ thresholds = [], annotations = [], valueFormatter, active = null, onActiveChange, className }) {
|
|
975
|
+
const labels = useChartLabels();
|
|
869
976
|
const id = useId();
|
|
870
977
|
if (thresholds.length === 0 && annotations.length === 0) return null;
|
|
871
978
|
const fmt = (n) => valueFormatter ? valueFormatter(n) : String(n);
|
|
872
979
|
return /* @__PURE__ */ jsxs("ul", {
|
|
873
|
-
"aria-label":
|
|
980
|
+
"aria-label": labels.markers,
|
|
874
981
|
className: cx("mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 px-1 text-[12px] text-muted-foreground", className),
|
|
875
982
|
children: [thresholds.map((th, i) => /* @__PURE__ */ jsxs("li", {
|
|
876
983
|
className: "flex items-center gap-1.5",
|
|
@@ -892,7 +999,7 @@ function ChartMarkers({ thresholds = [], annotations = [], valueFormatter, activ
|
|
|
892
999
|
}), /* @__PURE__ */ jsxs("span", { children: [
|
|
893
1000
|
/* @__PURE__ */ jsx("span", {
|
|
894
1001
|
className: "sr-only",
|
|
895
|
-
children:
|
|
1002
|
+
children: labels.threshold
|
|
896
1003
|
}),
|
|
897
1004
|
" ",
|
|
898
1005
|
th.label,
|
|
@@ -935,7 +1042,7 @@ function ChartMarkers({ thresholds = [], annotations = [], valueFormatter, activ
|
|
|
935
1042
|
}), /* @__PURE__ */ jsxs("span", { children: [
|
|
936
1043
|
/* @__PURE__ */ jsx("span", {
|
|
937
1044
|
className: "sr-only",
|
|
938
|
-
children:
|
|
1045
|
+
children: labels.markerAt.replace("{x}", String(a.x))
|
|
939
1046
|
}),
|
|
940
1047
|
" ",
|
|
941
1048
|
a.label
|
|
@@ -1102,7 +1209,7 @@ function AreaChart({ data, index, categories, colors = CHART_COLORS, valueFormat
|
|
|
1102
1209
|
label: c,
|
|
1103
1210
|
color: col(i)
|
|
1104
1211
|
}));
|
|
1105
|
-
const name = accessibleName(
|
|
1212
|
+
const name = accessibleName(useChartLabels().areaChart, ariaLabel, title, categories);
|
|
1106
1213
|
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
1107
1214
|
label: name,
|
|
1108
1215
|
state: resolveState(state, data.length),
|
|
@@ -1209,7 +1316,7 @@ function BarChart({ data, index, categories, colors = CHART_COLORS, valueFormatt
|
|
|
1209
1316
|
0,
|
|
1210
1317
|
0
|
|
1211
1318
|
];
|
|
1212
|
-
const name = accessibleName(
|
|
1319
|
+
const name = accessibleName(useChartLabels().barChart, ariaLabel, title, categories);
|
|
1213
1320
|
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
1214
1321
|
label: name,
|
|
1215
1322
|
state: resolveState(state, data.length),
|
|
@@ -1308,7 +1415,7 @@ function LineChart({ data, index, categories, colors = CHART_COLORS, valueFormat
|
|
|
1308
1415
|
const first = x.view[0];
|
|
1309
1416
|
const last = x.view[x.view.length - 1];
|
|
1310
1417
|
const xTicks = startEndOnly && first && last ? [asTick(field(first, index)), asTick(field(last, index))] : void 0;
|
|
1311
|
-
const name = accessibleName(
|
|
1418
|
+
const name = accessibleName(useChartLabels().lineChart, ariaLabel, title, categories);
|
|
1312
1419
|
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
1313
1420
|
label: name,
|
|
1314
1421
|
state: resolveState(state, data.length),
|
|
@@ -1408,7 +1515,7 @@ function ComboChart({ data, index, barSeries, lineSeries, barColor = "primary",
|
|
|
1408
1515
|
color: lc
|
|
1409
1516
|
}];
|
|
1410
1517
|
const fmtSeries = (v, name) => formatAny(v, name === lineSeries ? lineFormatter : barFormatter);
|
|
1411
|
-
const name = accessibleName(
|
|
1518
|
+
const name = accessibleName(useChartLabels().comboChart, ariaLabel, title, [barSeries, lineSeries]);
|
|
1412
1519
|
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
1413
1520
|
label: name,
|
|
1414
1521
|
state: resolveState(state, data.length),
|
|
@@ -1516,7 +1623,8 @@ function DonutChart({ data, index, category, colors = CHART_COLORS, valueFormatt
|
|
|
1516
1623
|
const shown = slices.filter((s) => !hidden.has(s.name));
|
|
1517
1624
|
const total = shown.reduce((sum, s) => sum + s.value, 0);
|
|
1518
1625
|
const isDonut = variant === "donut";
|
|
1519
|
-
const
|
|
1626
|
+
const labels = useChartLabels();
|
|
1627
|
+
const name = accessibleName(isDonut ? labels.donutChart : labels.pieChart, ariaLabel, title, slices.map((s) => s.name));
|
|
1520
1628
|
const effective = resolveState(state, slices.length);
|
|
1521
1629
|
const placeholder = chartStateView(effective, {
|
|
1522
1630
|
height,
|
|
@@ -1621,7 +1729,9 @@ const BAR_LIST_BG = {
|
|
|
1621
1729
|
rose: "bg-category-rose/20"
|
|
1622
1730
|
};
|
|
1623
1731
|
/** Axis-less ranked list: label inside a token-tinted bar, value on the right. */
|
|
1624
|
-
function BarList({ data, index, category, valueFormatter = identity, color = "primary", sortOrder = "desc", className, "aria-label":
|
|
1732
|
+
function BarList({ data, index, category, valueFormatter = identity, color = "primary", sortOrder = "desc", className, "aria-label": ariaLabelProp, state, emptyMessage, errorMessage, onRetry }) {
|
|
1733
|
+
const labels = useChartLabels();
|
|
1734
|
+
const ariaLabel = ariaLabelProp ?? labels.barList;
|
|
1625
1735
|
const effective = resolveState(state, data.length);
|
|
1626
1736
|
const placeholder = chartStateView(effective, {
|
|
1627
1737
|
height: 160,
|
|
@@ -1778,7 +1888,8 @@ function FunnelChart({ data, index, category, color = "primary", valueFormatter
|
|
|
1778
1888
|
name: String(field(d, index)),
|
|
1779
1889
|
value: numField(d, category)
|
|
1780
1890
|
})), ramp);
|
|
1781
|
-
const
|
|
1891
|
+
const labels = useChartLabels();
|
|
1892
|
+
const name = accessibleName(labels.funnelChart, ariaLabel, title, stages.map((s) => s.name));
|
|
1782
1893
|
const effective = resolveState(state, data.length);
|
|
1783
1894
|
const placeholder = chartStateView(effective, {
|
|
1784
1895
|
height,
|
|
@@ -1832,7 +1943,7 @@ function FunnelChart({ data, index, category, color = "primary", valueFormatter
|
|
|
1832
1943
|
})
|
|
1833
1944
|
}),
|
|
1834
1945
|
showStages && /* @__PURE__ */ jsx("ol", {
|
|
1835
|
-
"aria-label":
|
|
1946
|
+
"aria-label": labels.stages,
|
|
1836
1947
|
className: "flex w-full flex-col gap-2 sm:w-64",
|
|
1837
1948
|
children: stages.map((s, i) => /* @__PURE__ */ jsxs("li", {
|
|
1838
1949
|
className: "flex items-center justify-between gap-3 border-b border-border pb-2 last:border-b-0",
|
|
@@ -1862,7 +1973,7 @@ function FunnelChart({ data, index, category, color = "primary", valueFormatter
|
|
|
1862
1973
|
children: [
|
|
1863
1974
|
/* @__PURE__ */ jsx("span", {
|
|
1864
1975
|
className: "sr-only",
|
|
1865
|
-
children:
|
|
1976
|
+
children: labels.dropOffPrefix
|
|
1866
1977
|
}),
|
|
1867
1978
|
"−",
|
|
1868
1979
|
chartFmt.percent(s.dropOff)
|
|
@@ -1875,10 +1986,10 @@ function FunnelChart({ data, index, category, color = "primary", valueFormatter
|
|
|
1875
1986
|
dataTable && /* @__PURE__ */ jsx(ChartDataTable, {
|
|
1876
1987
|
caption: name,
|
|
1877
1988
|
columns: [
|
|
1878
|
-
|
|
1989
|
+
labels.stage,
|
|
1879
1990
|
category,
|
|
1880
|
-
|
|
1881
|
-
|
|
1991
|
+
labels.conversion,
|
|
1992
|
+
labels.dropOff
|
|
1882
1993
|
],
|
|
1883
1994
|
rows: stages.map((s) => [
|
|
1884
1995
|
s.name,
|
|
@@ -1916,7 +2027,8 @@ function SankeyChart({ nodes, links, colors = SAFE_CHART_COLORS, valueFormatter
|
|
|
1916
2027
|
const resolved = resolveSankeyLinks(nodes, links);
|
|
1917
2028
|
const fills = nodes.map((n, i) => n.color ? t.color(n.color) : seriesColor(t, colors, i));
|
|
1918
2029
|
const sources = new Set(resolved.map((l) => l.source));
|
|
1919
|
-
const
|
|
2030
|
+
const labels = useChartLabels();
|
|
2031
|
+
const name = accessibleName(labels.sankeyChart, ariaLabel, title, nodes.map((n) => n.name));
|
|
1920
2032
|
const data = {
|
|
1921
2033
|
nodes: nodes.map((n, i) => ({
|
|
1922
2034
|
name: n.name,
|
|
@@ -1964,9 +2076,9 @@ function SankeyChart({ nodes, links, colors = SAFE_CHART_COLORS, valueFormatter
|
|
|
1964
2076
|
table: dataTable && /* @__PURE__ */ jsx(ChartDataTable, {
|
|
1965
2077
|
caption: name,
|
|
1966
2078
|
columns: [
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
2079
|
+
labels.from,
|
|
2080
|
+
labels.to,
|
|
2081
|
+
labels.value
|
|
1970
2082
|
],
|
|
1971
2083
|
rows: resolved.map((l) => [
|
|
1972
2084
|
nodes[l.source]?.name ?? "",
|
|
@@ -2009,7 +2121,7 @@ function RadarChart({ data, index, categories, colors = SAFE_CHART_COLORS, value
|
|
|
2009
2121
|
label: c,
|
|
2010
2122
|
color: col(i)
|
|
2011
2123
|
}));
|
|
2012
|
-
const name = accessibleName(
|
|
2124
|
+
const name = accessibleName(useChartLabels().radarChart, ariaLabel, title, categories);
|
|
2013
2125
|
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
2014
2126
|
label: name,
|
|
2015
2127
|
state: resolveState(state, data.length),
|
|
@@ -2098,7 +2210,8 @@ function Heatmap({ data, index, categories, scale = "sequential", domain, steps,
|
|
|
2098
2210
|
const id = useId();
|
|
2099
2211
|
const cellHeight = cellHeightFor(height, data.length) ?? cellHeightProp;
|
|
2100
2212
|
const [active, setActive] = useState(null);
|
|
2101
|
-
const
|
|
2213
|
+
const labels = useChartLabels();
|
|
2214
|
+
const name = accessibleName(labels.heatmap, ariaLabel, title, []);
|
|
2102
2215
|
const diverging = scale === "diverging";
|
|
2103
2216
|
const count = steps ?? (diverging ? 7 : 6);
|
|
2104
2217
|
const ramp = diverging ? divergingRamp(count) : sequentialRamp(count, { color });
|
|
@@ -2165,7 +2278,7 @@ function Heatmap({ data, index, categories, scale = "sequential", domain, steps,
|
|
|
2165
2278
|
/* @__PURE__ */ jsx("div", {
|
|
2166
2279
|
role: "group",
|
|
2167
2280
|
tabIndex: 0,
|
|
2168
|
-
"aria-label": `${name}:
|
|
2281
|
+
"aria-label": `${name}: ${labels.colourGrid}`,
|
|
2169
2282
|
onKeyDown,
|
|
2170
2283
|
onFocus: () => setActive((a) => a ?? [0, 0]),
|
|
2171
2284
|
onBlur: () => setActive(null),
|
|
@@ -2278,7 +2391,8 @@ function highlightIndex(data, h) {
|
|
|
2278
2391
|
* with a highlighted bar, per-bar hover titles and a generated `role="img"` summary.
|
|
2279
2392
|
*/
|
|
2280
2393
|
function MiniBar({ data, labels, tone = "primary", highlight = "last", width = 120, height = 32, label, formatValue = fmtDefault, className, ...props }) {
|
|
2281
|
-
const
|
|
2394
|
+
const chartLabels = useChartLabels();
|
|
2395
|
+
const name = props["aria-label"] ?? describeBars(data, label ?? chartLabels.bars, formatValue);
|
|
2282
2396
|
const token = TONE_TOKEN[tone];
|
|
2283
2397
|
const n = data.length;
|
|
2284
2398
|
const lo = n ? Math.min(0, ...data) : 0;
|
|
@@ -2312,6 +2426,6 @@ function MiniBar({ data, labels, tone = "primary", highlight = "last", width = 1
|
|
|
2312
2426
|
});
|
|
2313
2427
|
}
|
|
2314
2428
|
//#endregion
|
|
2315
|
-
export { AreaChart, BarChart, BarList, CHART_COLORS, ChartBrush, ChartDataTable, ChartEmpty, ChartError, ChartLegend, ChartLoading, ChartMarkers, ChartTooltip, ComboChart, DonutChart, FunnelChart, Heatmap, LineChart, MiniBar, RadarChart, SAFE_CHART_COLORS, SERIES_TOKENS, SankeyChart, TONE_TOKENS, cellHeightFor, chartFmt, clampRange, describeBars, divergingRamp, funnelStages, rampColor, rampIndex, resolveSankeyLinks, sequentialRamp, tooltipContent, useChartRange, useChartTheme, useHiddenSeries, useLiveSeries, usePrefersReducedMotion };
|
|
2429
|
+
export { AreaChart, BarChart, BarList, CHART_COLORS, ChartBrush, ChartDataTable, ChartEmpty, ChartError, ChartLegend, ChartLoading, ChartLocaleProvider, ChartMarkers, ChartTooltip, ComboChart, DonutChart, FunnelChart, Heatmap, LineChart, MiniBar, RadarChart, SAFE_CHART_COLORS, SERIES_TOKENS, SankeyChart, TONE_TOKENS, cellHeightFor, chartFmt, chartLabelSets, clampRange, describeBars, divergingRamp, en, es, funnelStages, rampColor, rampIndex, resolveSankeyLinks, sequentialRamp, tooltipContent, useChartLabels, useChartRange, useChartTheme, useHiddenSeries, useLiveSeries, usePrefersReducedMotion };
|
|
2316
2430
|
|
|
2317
2431
|
//# sourceMappingURL=index.js.map
|