@meetreeve/ui 0.21.0 → 0.23.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/README.md +100 -0
- package/THIRD_PARTY_NOTICES.md +68 -0
- package/dist/charts/index.d.mts +331 -0
- package/dist/charts/index.d.ts +331 -0
- package/dist/charts/index.js +913 -0
- package/dist/charts/index.mjs +860 -0
- package/dist/index.d.mts +1 -12
- package/dist/index.d.ts +1 -12
- package/dist/index.js +3 -1
- package/dist/index.mjs +3 -1
- package/dist/theme/index.d.mts +190 -0
- package/dist/theme/index.d.ts +190 -0
- package/dist/theme/index.js +351 -0
- package/dist/theme/index.mjs +309 -0
- package/dist/tokens.css +41 -0
- package/package.json +23 -4
|
@@ -0,0 +1,860 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/charts/theme.ts
|
|
4
|
+
var CHART_SERIES_COUNT = 8;
|
|
5
|
+
function chartColor(index) {
|
|
6
|
+
return `var(--chart-${index % CHART_SERIES_COUNT + 1})`;
|
|
7
|
+
}
|
|
8
|
+
var chartPalette = Array.from({ length: CHART_SERIES_COUNT }, (_, i) => chartColor(i));
|
|
9
|
+
var chartTokens = {
|
|
10
|
+
positive: "var(--chart-positive)",
|
|
11
|
+
negative: "var(--chart-negative)",
|
|
12
|
+
// Fall back to the shadcn tokens every host has, so grid and ticks still
|
|
13
|
+
// render when a host defines only the series colours.
|
|
14
|
+
grid: "var(--chart-grid, var(--border))",
|
|
15
|
+
muted: "var(--chart-muted, var(--muted-foreground))",
|
|
16
|
+
foreground: "var(--foreground)",
|
|
17
|
+
card: "var(--card)"
|
|
18
|
+
};
|
|
19
|
+
function withAlpha(color, percent) {
|
|
20
|
+
return `color-mix(in srgb, ${color} ${percent}%, transparent)`;
|
|
21
|
+
}
|
|
22
|
+
var chartConfig = {
|
|
23
|
+
tooltip: {
|
|
24
|
+
background: chartTokens.card,
|
|
25
|
+
border: withAlpha(chartColor(0), 20),
|
|
26
|
+
text: chartTokens.foreground,
|
|
27
|
+
label: chartTokens.muted
|
|
28
|
+
},
|
|
29
|
+
grid: { stroke: chartTokens.grid },
|
|
30
|
+
axis: { stroke: chartTokens.grid, tick: chartTokens.muted, fontSize: 11 }
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/charts/chart.tsx
|
|
34
|
+
import { createContext, useContext, useId } from "react";
|
|
35
|
+
import { ResponsiveContainer, Tooltip } from "recharts";
|
|
36
|
+
|
|
37
|
+
// src/lib/cn.ts
|
|
38
|
+
function cn(...inputs) {
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const input of inputs) {
|
|
41
|
+
if (!input) continue;
|
|
42
|
+
if (typeof input === "string" || typeof input === "number") {
|
|
43
|
+
out.push(String(input));
|
|
44
|
+
} else if (Array.isArray(input)) {
|
|
45
|
+
const nested = cn(...input);
|
|
46
|
+
if (nested) out.push(nested);
|
|
47
|
+
} else if (typeof input === "object") {
|
|
48
|
+
for (const [key, value] of Object.entries(input)) {
|
|
49
|
+
if (value) out.push(key);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return out.join(" ");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/lib/use-media-query.ts
|
|
57
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
58
|
+
function useMediaQuery(query) {
|
|
59
|
+
const subscribe = useCallback(
|
|
60
|
+
(onChange) => {
|
|
61
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
62
|
+
return () => {
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const mql = window.matchMedia(query);
|
|
66
|
+
mql.addEventListener("change", onChange);
|
|
67
|
+
return () => mql.removeEventListener("change", onChange);
|
|
68
|
+
},
|
|
69
|
+
[query]
|
|
70
|
+
);
|
|
71
|
+
const getSnapshot = () => typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(query).matches : false;
|
|
72
|
+
return useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/charts/chart.tsx
|
|
76
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
77
|
+
var ChartContext = createContext(null);
|
|
78
|
+
function useChart() {
|
|
79
|
+
const ctx = useContext(ChartContext);
|
|
80
|
+
if (!ctx) throw new Error("useChart must be used within a <ChartContainer />");
|
|
81
|
+
return ctx;
|
|
82
|
+
}
|
|
83
|
+
function usePrefersReducedMotion() {
|
|
84
|
+
return useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
85
|
+
}
|
|
86
|
+
function ChartContainer({ config = {}, height = 300, loading = false, className, children }) {
|
|
87
|
+
const chartId = `chart-${useId().replace(/:/g, "")}`;
|
|
88
|
+
const vars = Object.fromEntries(
|
|
89
|
+
Object.entries(config).filter(([, c]) => c.color).map(([key, c]) => [`--color-${key}`, c.color])
|
|
90
|
+
);
|
|
91
|
+
return /* @__PURE__ */ jsx(ChartContext.Provider, { value: { config }, children: /* @__PURE__ */ jsx("div", { "data-slot": "chart", "data-chart": chartId, className: cn("w-full", className), style: { ...vars, height }, children: loading ? /* @__PURE__ */ jsx(ChartSkeleton, { height }) : /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height, children }) }) });
|
|
92
|
+
}
|
|
93
|
+
function ChartSkeleton({ height = 300 }) {
|
|
94
|
+
const reduced = usePrefersReducedMotion();
|
|
95
|
+
const bars = [0.45, 0.7, 0.55, 0.85, 0.6, 0.75, 0.5];
|
|
96
|
+
return /* @__PURE__ */ jsx(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
role: "status",
|
|
100
|
+
"aria-label": "Loading chart",
|
|
101
|
+
"data-testid": "chart-skeleton",
|
|
102
|
+
className: cn("flex w-full items-end gap-2", !reduced && "animate-pulse"),
|
|
103
|
+
style: { height },
|
|
104
|
+
children: bars.map((h, i) => /* @__PURE__ */ jsx("div", { className: "flex-1 rounded-t-md", style: { height: `${h * 100}%`, background: "var(--muted)" } }, i))
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
function ChartTooltipContent({ active, payload, label, formatter }) {
|
|
109
|
+
if (!active || !payload?.length) return null;
|
|
110
|
+
return /* @__PURE__ */ jsxs(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
className: "rounded-lg px-3 py-2 text-xs shadow-xl",
|
|
114
|
+
style: { background: chartConfig.tooltip.background, border: `1px solid ${chartConfig.tooltip.border}` },
|
|
115
|
+
children: [
|
|
116
|
+
label != null && label !== "" && /* @__PURE__ */ jsx("p", { className: "mb-1 font-medium", style: { color: chartConfig.tooltip.label }, children: label }),
|
|
117
|
+
payload.map((entry, i) => /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-2", style: { color: chartConfig.tooltip.text }, children: [
|
|
118
|
+
/* @__PURE__ */ jsx("span", { className: "inline-block h-2 w-2 rounded-full", style: { backgroundColor: entry.color } }),
|
|
119
|
+
/* @__PURE__ */ jsxs("span", { style: { color: chartConfig.tooltip.label }, children: [
|
|
120
|
+
entry.name,
|
|
121
|
+
":"
|
|
122
|
+
] }),
|
|
123
|
+
" ",
|
|
124
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: formatter ? formatter(entry.value, entry.name) : entry.value.toLocaleString() })
|
|
125
|
+
] }, i))
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
var ChartTooltip = Tooltip;
|
|
131
|
+
|
|
132
|
+
// src/charts/area-chart.tsx
|
|
133
|
+
import { useId as useId2 } from "react";
|
|
134
|
+
import { Area, AreaChart as RechartsAreaChart, CartesianGrid, Legend, Tooltip as Tooltip2, XAxis, YAxis } from "recharts";
|
|
135
|
+
|
|
136
|
+
// src/charts/patterns.tsx
|
|
137
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
138
|
+
function fillId(chartId, dataKey, variant) {
|
|
139
|
+
return `${chartId}-${variant}-${dataKey.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
140
|
+
}
|
|
141
|
+
function AreaFill({ id, variant, color }) {
|
|
142
|
+
switch (variant) {
|
|
143
|
+
case "gradient":
|
|
144
|
+
return /* @__PURE__ */ jsxs2("linearGradient", { id, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
145
|
+
/* @__PURE__ */ jsx2("stop", { offset: "0%", stopColor: color, stopOpacity: 0.3 }),
|
|
146
|
+
/* @__PURE__ */ jsx2("stop", { offset: "100%", stopColor: color, stopOpacity: 0 })
|
|
147
|
+
] });
|
|
148
|
+
case "solid":
|
|
149
|
+
return /* @__PURE__ */ jsxs2("linearGradient", { id, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
150
|
+
/* @__PURE__ */ jsx2("stop", { offset: "0%", stopColor: color, stopOpacity: 0.15 }),
|
|
151
|
+
/* @__PURE__ */ jsx2("stop", { offset: "100%", stopColor: color, stopOpacity: 0.15 })
|
|
152
|
+
] });
|
|
153
|
+
case "dotted":
|
|
154
|
+
return /* @__PURE__ */ jsx2("pattern", { id, width: "6", height: "6", patternUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx2("circle", { cx: "3", cy: "3", r: "1", fill: color, fillOpacity: 0.45 }) });
|
|
155
|
+
case "hatched":
|
|
156
|
+
return /* @__PURE__ */ jsxs2("pattern", { id, width: "8", height: "8", patternUnits: "userSpaceOnUse", patternTransform: "rotate(20)", children: [
|
|
157
|
+
/* @__PURE__ */ jsx2("rect", { width: "8", height: "8", fill: color, fillOpacity: 0.06 }),
|
|
158
|
+
/* @__PURE__ */ jsx2("rect", { width: "4", height: "8", fill: color, fillOpacity: 0.22 })
|
|
159
|
+
] });
|
|
160
|
+
case "lines":
|
|
161
|
+
return /* @__PURE__ */ jsx2("pattern", { id, width: "5", height: "5", patternUnits: "userSpaceOnUse", patternTransform: "rotate(45)", children: /* @__PURE__ */ jsx2("line", { x1: "0", y1: "0", x2: "0", y2: "5", stroke: color, strokeOpacity: 0.35, strokeWidth: 1 }) });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function GlowFilter({ id }) {
|
|
165
|
+
return /* @__PURE__ */ jsxs2("filter", { id, filterUnits: "userSpaceOnUse", x: "0", y: "0", width: "100%", height: "100%", children: [
|
|
166
|
+
/* @__PURE__ */ jsx2("feGaussianBlur", { stdDeviation: "4", result: "blur" }),
|
|
167
|
+
/* @__PURE__ */ jsxs2("feMerge", { children: [
|
|
168
|
+
/* @__PURE__ */ jsx2("feMergeNode", { in: "blur" }),
|
|
169
|
+
/* @__PURE__ */ jsx2("feMergeNode", { in: "SourceGraphic" })
|
|
170
|
+
] })
|
|
171
|
+
] });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/charts/area-chart.tsx
|
|
175
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
176
|
+
function AreaChart({
|
|
177
|
+
data,
|
|
178
|
+
xKey,
|
|
179
|
+
series,
|
|
180
|
+
height = 300,
|
|
181
|
+
showGrid = false,
|
|
182
|
+
showLegend = false,
|
|
183
|
+
showYAxis = true,
|
|
184
|
+
tooltipFormatter,
|
|
185
|
+
yTickFormatter,
|
|
186
|
+
variant = "gradient",
|
|
187
|
+
curve = "monotone",
|
|
188
|
+
stack = "none",
|
|
189
|
+
loading = false
|
|
190
|
+
}) {
|
|
191
|
+
const chartId = `area-${useId2().replace(/:/g, "")}`;
|
|
192
|
+
const animate = !usePrefersReducedMotion();
|
|
193
|
+
const colorOf = (s, i) => s.color ?? chartColor(i);
|
|
194
|
+
const variantOf = (s) => s.variant ?? variant;
|
|
195
|
+
return /* @__PURE__ */ jsx3(ChartContainer, { height, loading, children: /* @__PURE__ */ jsxs3(
|
|
196
|
+
RechartsAreaChart,
|
|
197
|
+
{
|
|
198
|
+
data,
|
|
199
|
+
margin: { top: 8, right: 8, left: showYAxis ? -12 : 8, bottom: 0 },
|
|
200
|
+
stackOffset: stack === "expanded" ? "expand" : void 0,
|
|
201
|
+
children: [
|
|
202
|
+
/* @__PURE__ */ jsx3("defs", { children: series.map((s, i) => {
|
|
203
|
+
const v = variantOf(s);
|
|
204
|
+
return /* @__PURE__ */ jsx3(AreaFill, { id: fillId(chartId, s.dataKey, v), variant: v, color: colorOf(s, i) }, s.dataKey);
|
|
205
|
+
}) }),
|
|
206
|
+
showGrid && /* @__PURE__ */ jsx3(CartesianGrid, { strokeDasharray: "3 3", stroke: chartConfig.grid.stroke }),
|
|
207
|
+
/* @__PURE__ */ jsx3(
|
|
208
|
+
XAxis,
|
|
209
|
+
{
|
|
210
|
+
dataKey: xKey,
|
|
211
|
+
stroke: chartConfig.axis.stroke,
|
|
212
|
+
tick: { fill: chartConfig.axis.tick, fontSize: chartConfig.axis.fontSize },
|
|
213
|
+
tickLine: false,
|
|
214
|
+
axisLine: false
|
|
215
|
+
}
|
|
216
|
+
),
|
|
217
|
+
/* @__PURE__ */ jsx3(
|
|
218
|
+
YAxis,
|
|
219
|
+
{
|
|
220
|
+
hide: !showYAxis,
|
|
221
|
+
stroke: chartConfig.axis.stroke,
|
|
222
|
+
tick: { fill: chartConfig.axis.tick, fontSize: chartConfig.axis.fontSize },
|
|
223
|
+
tickFormatter: yTickFormatter,
|
|
224
|
+
tickLine: false,
|
|
225
|
+
axisLine: false
|
|
226
|
+
}
|
|
227
|
+
),
|
|
228
|
+
/* @__PURE__ */ jsx3(
|
|
229
|
+
Tooltip2,
|
|
230
|
+
{
|
|
231
|
+
content: /* @__PURE__ */ jsx3(ChartTooltipContent, { formatter: tooltipFormatter }),
|
|
232
|
+
cursor: { stroke: withAlpha(chartColor(0), 20) }
|
|
233
|
+
}
|
|
234
|
+
),
|
|
235
|
+
showLegend && /* @__PURE__ */ jsx3(Legend, { wrapperStyle: { fontSize: 12, color: chartTokens.muted, paddingTop: 8 } }),
|
|
236
|
+
series.map((s, i) => /* @__PURE__ */ jsx3(
|
|
237
|
+
Area,
|
|
238
|
+
{
|
|
239
|
+
type: curve,
|
|
240
|
+
dataKey: s.dataKey,
|
|
241
|
+
name: s.name,
|
|
242
|
+
stackId: s.stackId ?? (stack === "none" ? void 0 : "stack"),
|
|
243
|
+
stroke: colorOf(s, i),
|
|
244
|
+
strokeWidth: 2,
|
|
245
|
+
fill: `url(#${fillId(chartId, s.dataKey, variantOf(s))})`,
|
|
246
|
+
dot: false,
|
|
247
|
+
activeDot: { r: 4, fill: colorOf(s, i), stroke: "var(--background)", strokeWidth: 2 },
|
|
248
|
+
isAnimationActive: animate
|
|
249
|
+
},
|
|
250
|
+
s.dataKey
|
|
251
|
+
))
|
|
252
|
+
]
|
|
253
|
+
}
|
|
254
|
+
) });
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/charts/line-chart.tsx
|
|
258
|
+
import { useId as useId3 } from "react";
|
|
259
|
+
import { CartesianGrid as CartesianGrid2, Legend as Legend2, Line, LineChart as RechartsLineChart, Tooltip as Tooltip3, XAxis as XAxis2, YAxis as YAxis2 } from "recharts";
|
|
260
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
261
|
+
function LineChart({
|
|
262
|
+
data,
|
|
263
|
+
xKey,
|
|
264
|
+
series,
|
|
265
|
+
height = 300,
|
|
266
|
+
showGrid = false,
|
|
267
|
+
showLegend = false,
|
|
268
|
+
showYAxis = true,
|
|
269
|
+
tooltipFormatter,
|
|
270
|
+
yTickFormatter,
|
|
271
|
+
curve = "monotone",
|
|
272
|
+
loading = false
|
|
273
|
+
}) {
|
|
274
|
+
const chartId = `line-${useId3().replace(/:/g, "")}`;
|
|
275
|
+
const animate = !usePrefersReducedMotion();
|
|
276
|
+
const glowId = (s) => `${chartId}-glow-${s.dataKey.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
277
|
+
return /* @__PURE__ */ jsx4(ChartContainer, { height, loading, children: /* @__PURE__ */ jsxs4(RechartsLineChart, { data, margin: { top: 8, right: 8, left: showYAxis ? -12 : 8, bottom: 0 }, children: [
|
|
278
|
+
/* @__PURE__ */ jsx4("defs", { children: series.filter((s) => s.glow).map((s) => /* @__PURE__ */ jsx4(GlowFilter, { id: glowId(s) }, s.dataKey)) }),
|
|
279
|
+
showGrid && /* @__PURE__ */ jsx4(CartesianGrid2, { strokeDasharray: "3 3", stroke: chartConfig.grid.stroke, vertical: false }),
|
|
280
|
+
/* @__PURE__ */ jsx4(
|
|
281
|
+
XAxis2,
|
|
282
|
+
{
|
|
283
|
+
dataKey: xKey,
|
|
284
|
+
stroke: chartConfig.axis.stroke,
|
|
285
|
+
tick: { fill: chartConfig.axis.tick, fontSize: chartConfig.axis.fontSize },
|
|
286
|
+
tickLine: false,
|
|
287
|
+
axisLine: false
|
|
288
|
+
}
|
|
289
|
+
),
|
|
290
|
+
/* @__PURE__ */ jsx4(
|
|
291
|
+
YAxis2,
|
|
292
|
+
{
|
|
293
|
+
hide: !showYAxis,
|
|
294
|
+
stroke: chartConfig.axis.stroke,
|
|
295
|
+
tick: { fill: chartConfig.axis.tick, fontSize: chartConfig.axis.fontSize },
|
|
296
|
+
tickFormatter: yTickFormatter,
|
|
297
|
+
tickLine: false,
|
|
298
|
+
axisLine: false
|
|
299
|
+
}
|
|
300
|
+
),
|
|
301
|
+
/* @__PURE__ */ jsx4(
|
|
302
|
+
Tooltip3,
|
|
303
|
+
{
|
|
304
|
+
content: /* @__PURE__ */ jsx4(ChartTooltipContent, { formatter: tooltipFormatter }),
|
|
305
|
+
cursor: { stroke: withAlpha(chartColor(0), 20) }
|
|
306
|
+
}
|
|
307
|
+
),
|
|
308
|
+
showLegend && /* @__PURE__ */ jsx4(Legend2, { wrapperStyle: { fontSize: 12, color: chartTokens.muted, paddingTop: 8 } }),
|
|
309
|
+
series.map((s, i) => {
|
|
310
|
+
const color = s.color ?? chartColor(i);
|
|
311
|
+
return /* @__PURE__ */ jsx4(
|
|
312
|
+
Line,
|
|
313
|
+
{
|
|
314
|
+
type: curve,
|
|
315
|
+
dataKey: s.dataKey,
|
|
316
|
+
name: s.name,
|
|
317
|
+
stroke: color,
|
|
318
|
+
strokeWidth: 2,
|
|
319
|
+
strokeDasharray: s.dashed ? "5 4" : void 0,
|
|
320
|
+
filter: s.glow ? `url(#${glowId(s)})` : void 0,
|
|
321
|
+
dot: s.dots ? { r: 3, fill: color, strokeWidth: 0 } : false,
|
|
322
|
+
activeDot: { r: 4, fill: color, stroke: "var(--background)", strokeWidth: 2 },
|
|
323
|
+
isAnimationActive: animate
|
|
324
|
+
},
|
|
325
|
+
s.dataKey
|
|
326
|
+
);
|
|
327
|
+
})
|
|
328
|
+
] }) });
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/charts/bar-chart.tsx
|
|
332
|
+
import { Bar, BarChart as RechartsBarChart, CartesianGrid as CartesianGrid3, LabelList, Legend as Legend3, Tooltip as Tooltip4, XAxis as XAxis3, YAxis as YAxis3 } from "recharts";
|
|
333
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
334
|
+
var BAR_CATEGORY_GAP = "8.33%";
|
|
335
|
+
var BAR_LABEL_FONT_SIZE = chartConfig.axis.fontSize;
|
|
336
|
+
var BAR_STANDARD = {
|
|
337
|
+
barCategoryGap: BAR_CATEGORY_GAP
|
|
338
|
+
};
|
|
339
|
+
var BAR_LABEL_STYLE = {
|
|
340
|
+
fill: chartTokens.foreground,
|
|
341
|
+
fontSize: BAR_LABEL_FONT_SIZE,
|
|
342
|
+
fontWeight: 500
|
|
343
|
+
};
|
|
344
|
+
function barValueLabel(format = (v) => v.toLocaleString(), {
|
|
345
|
+
slack = 0.2,
|
|
346
|
+
orientation = "vertical"
|
|
347
|
+
} = {}) {
|
|
348
|
+
function BarValueLabel({ value, offset = 6, viewBox }) {
|
|
349
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
350
|
+
if (value == null || value === "" || !Number.isFinite(n) || !viewBox || !("width" in viewBox)) return null;
|
|
351
|
+
const { x = 0, y = 0, width = 0, height = 0 } = viewBox;
|
|
352
|
+
const text = format(n);
|
|
353
|
+
if (orientation === "horizontal") {
|
|
354
|
+
if (Math.abs(height) < BAR_LABEL_FONT_SIZE) return null;
|
|
355
|
+
const negative = width < 0;
|
|
356
|
+
return /* @__PURE__ */ jsx5(
|
|
357
|
+
"text",
|
|
358
|
+
{
|
|
359
|
+
x: x + width + (negative ? -offset : offset),
|
|
360
|
+
y: y + height / 2,
|
|
361
|
+
dominantBaseline: "central",
|
|
362
|
+
textAnchor: negative ? "end" : "start",
|
|
363
|
+
...BAR_LABEL_STYLE,
|
|
364
|
+
children: text
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
const barWidth = Math.abs(width);
|
|
369
|
+
const room = barWidth + (typeof slack === "function" ? slack(barWidth) : barWidth * slack);
|
|
370
|
+
if (text.length * BAR_LABEL_FONT_SIZE * 0.6 > room) return null;
|
|
371
|
+
return /* @__PURE__ */ jsx5("text", { x: x + width / 2, y: Math.min(y, y + height) - offset, textAnchor: "middle", ...BAR_LABEL_STYLE, children: text });
|
|
372
|
+
}
|
|
373
|
+
return BarValueLabel;
|
|
374
|
+
}
|
|
375
|
+
var GROUPED_BAR_GAP = 4;
|
|
376
|
+
function BarChart({
|
|
377
|
+
data,
|
|
378
|
+
xKey,
|
|
379
|
+
series,
|
|
380
|
+
height = 300,
|
|
381
|
+
showGrid = false,
|
|
382
|
+
showLegend = false,
|
|
383
|
+
tooltipFormatter,
|
|
384
|
+
labelFormatter,
|
|
385
|
+
showValueLabels = true,
|
|
386
|
+
showYAxis = false,
|
|
387
|
+
loading = false
|
|
388
|
+
}) {
|
|
389
|
+
const animate = !usePrefersReducedMotion();
|
|
390
|
+
const grouped = series.length > 1;
|
|
391
|
+
const formatLabel = labelFormatter ?? tooltipFormatter ?? ((v) => v.toLocaleString());
|
|
392
|
+
return /* @__PURE__ */ jsx5(ChartContainer, { height, loading, children: /* @__PURE__ */ jsxs5(
|
|
393
|
+
RechartsBarChart,
|
|
394
|
+
{
|
|
395
|
+
data,
|
|
396
|
+
barCategoryGap: BAR_CATEGORY_GAP,
|
|
397
|
+
barGap: GROUPED_BAR_GAP,
|
|
398
|
+
margin: {
|
|
399
|
+
top: showValueLabels ? 22 : 8,
|
|
400
|
+
right: 8,
|
|
401
|
+
left: showYAxis ? -12 : 8,
|
|
402
|
+
bottom: 0
|
|
403
|
+
},
|
|
404
|
+
children: [
|
|
405
|
+
showGrid && /* @__PURE__ */ jsx5(CartesianGrid3, { strokeDasharray: "3 3", stroke: chartConfig.grid.stroke, vertical: false }),
|
|
406
|
+
/* @__PURE__ */ jsx5(
|
|
407
|
+
XAxis3,
|
|
408
|
+
{
|
|
409
|
+
dataKey: xKey,
|
|
410
|
+
stroke: chartConfig.axis.stroke,
|
|
411
|
+
tick: { fill: chartConfig.axis.tick, fontSize: chartConfig.axis.fontSize },
|
|
412
|
+
tickLine: false,
|
|
413
|
+
axisLine: false
|
|
414
|
+
}
|
|
415
|
+
),
|
|
416
|
+
showYAxis ? /* @__PURE__ */ jsx5(
|
|
417
|
+
YAxis3,
|
|
418
|
+
{
|
|
419
|
+
stroke: chartConfig.axis.stroke,
|
|
420
|
+
tick: { fill: chartConfig.axis.tick, fontSize: chartConfig.axis.fontSize },
|
|
421
|
+
tickLine: false,
|
|
422
|
+
axisLine: false
|
|
423
|
+
}
|
|
424
|
+
) : (
|
|
425
|
+
// Hidden scale: without visible ticks there is no reason to round the
|
|
426
|
+
// top up to a "nice" number, so the tallest bar reaches the label row.
|
|
427
|
+
// An all-zero series still gets a [0, 1] scale, keeping its "0" labels
|
|
428
|
+
// on the baseline instead of floating mid-chart; an all-negative series
|
|
429
|
+
// tops out at 0 so its bars span the full height below the baseline
|
|
430
|
+
// (DEV-16977).
|
|
431
|
+
/* @__PURE__ */ jsx5(YAxis3, { hide: true, domain: [(min) => Math.min(0, min), (max) => max < 0 ? 0 : max || 1] })
|
|
432
|
+
),
|
|
433
|
+
/* @__PURE__ */ jsx5(
|
|
434
|
+
Tooltip4,
|
|
435
|
+
{
|
|
436
|
+
content: /* @__PURE__ */ jsx5(ChartTooltipContent, { formatter: tooltipFormatter }),
|
|
437
|
+
cursor: { fill: withAlpha(chartColor(0), 6) }
|
|
438
|
+
}
|
|
439
|
+
),
|
|
440
|
+
showLegend && /* @__PURE__ */ jsx5(Legend3, { wrapperStyle: { fontSize: 12, color: chartTokens.muted, paddingTop: 8 } }),
|
|
441
|
+
series.map((s, i) => /* @__PURE__ */ jsx5(
|
|
442
|
+
Bar,
|
|
443
|
+
{
|
|
444
|
+
dataKey: s.dataKey,
|
|
445
|
+
name: s.name,
|
|
446
|
+
fill: s.color ?? chartColor(i),
|
|
447
|
+
radius: s.radius ?? 4,
|
|
448
|
+
isAnimationActive: animate,
|
|
449
|
+
children: showValueLabels && /* @__PURE__ */ jsx5(
|
|
450
|
+
LabelList,
|
|
451
|
+
{
|
|
452
|
+
dataKey: s.dataKey,
|
|
453
|
+
position: "top",
|
|
454
|
+
content: barValueLabel((v) => formatLabel(v, s.name), {
|
|
455
|
+
slack: grouped ? () => GROUPED_BAR_GAP : 0.2
|
|
456
|
+
})
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
},
|
|
460
|
+
s.dataKey
|
|
461
|
+
))
|
|
462
|
+
]
|
|
463
|
+
}
|
|
464
|
+
) });
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/charts/donut-chart.tsx
|
|
468
|
+
import { Cell, Label, Legend as Legend4, Pie, PieChart, Tooltip as Tooltip5 } from "recharts";
|
|
469
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
470
|
+
function DonutChart({
|
|
471
|
+
data,
|
|
472
|
+
height = 300,
|
|
473
|
+
innerRadius = 60,
|
|
474
|
+
outerRadius = 90,
|
|
475
|
+
showLegend = true,
|
|
476
|
+
tooltipFormatter,
|
|
477
|
+
centerLabel,
|
|
478
|
+
centerValue,
|
|
479
|
+
loading = false
|
|
480
|
+
}) {
|
|
481
|
+
const animate = !usePrefersReducedMotion();
|
|
482
|
+
return /* @__PURE__ */ jsx6(ChartContainer, { height, loading, children: /* @__PURE__ */ jsxs6(PieChart, { children: [
|
|
483
|
+
/* @__PURE__ */ jsx6(Tooltip5, { content: /* @__PURE__ */ jsx6(ChartTooltipContent, { formatter: tooltipFormatter }) }),
|
|
484
|
+
/* @__PURE__ */ jsxs6(
|
|
485
|
+
Pie,
|
|
486
|
+
{
|
|
487
|
+
data,
|
|
488
|
+
cx: "50%",
|
|
489
|
+
cy: "50%",
|
|
490
|
+
innerRadius,
|
|
491
|
+
outerRadius,
|
|
492
|
+
paddingAngle: 2,
|
|
493
|
+
dataKey: "value",
|
|
494
|
+
nameKey: "name",
|
|
495
|
+
stroke: "none",
|
|
496
|
+
isAnimationActive: animate,
|
|
497
|
+
children: [
|
|
498
|
+
data.map((entry, i) => /* @__PURE__ */ jsx6(Cell, { fill: entry.fill ?? chartColor(i) }, i)),
|
|
499
|
+
(centerLabel || centerValue) && // Anchored to the pie's own centre: a bottom legend shifts the pie
|
|
500
|
+
// up, so the SVG's 50% would sit below the hole. Recharts 3 hands a
|
|
501
|
+
// Pie's Label the plot box (legend space already removed), and the
|
|
502
|
+
// pie's cx/cy="50%" are relative to that same box.
|
|
503
|
+
/* @__PURE__ */ jsx6(
|
|
504
|
+
Label,
|
|
505
|
+
{
|
|
506
|
+
position: "center",
|
|
507
|
+
content: ({ viewBox }) => {
|
|
508
|
+
const { x = 0, y = 0, width = 0, height: height2 = 0 } = viewBox ?? {};
|
|
509
|
+
const cx = x + width / 2;
|
|
510
|
+
const cy = y + height2 / 2;
|
|
511
|
+
return /* @__PURE__ */ jsxs6("text", { x: cx, y: cy, textAnchor: "middle", dominantBaseline: "middle", "data-testid": "donut-center", children: [
|
|
512
|
+
centerValue && /* @__PURE__ */ jsx6("tspan", { x: cx, dy: centerLabel ? -8 : 0, fill: chartTokens.foreground, fontSize: 20, fontWeight: 600, children: centerValue }),
|
|
513
|
+
centerLabel && /* @__PURE__ */ jsx6("tspan", { x: cx, dy: centerValue ? 22 : 0, fill: chartTokens.muted, fontSize: 11, children: centerLabel })
|
|
514
|
+
] });
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
)
|
|
518
|
+
]
|
|
519
|
+
}
|
|
520
|
+
),
|
|
521
|
+
showLegend && /* @__PURE__ */ jsx6(Legend4, { wrapperStyle: { fontSize: 12, color: chartTokens.muted, paddingTop: 8 } })
|
|
522
|
+
] }) });
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// src/charts/radial-chart.tsx
|
|
526
|
+
import { PolarAngleAxis, RadialBar, RadialBarChart } from "recharts";
|
|
527
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
528
|
+
function RadialChart({ data, max = 100, height = 220, centerValue, centerLabel, loading = false }) {
|
|
529
|
+
const animate = !usePrefersReducedMotion();
|
|
530
|
+
const rows = data.map((d, i) => ({ ...d, fill: d.fill ?? chartColor(i) }));
|
|
531
|
+
return /* @__PURE__ */ jsx7(ChartContainer, { height, loading, children: /* @__PURE__ */ jsxs7(RadialBarChart, { data: rows, innerRadius: "55%", outerRadius: "100%", startAngle: 90, endAngle: -270, barSize: 10, children: [
|
|
532
|
+
/* @__PURE__ */ jsx7(PolarAngleAxis, { type: "number", domain: [0, max], tick: false, axisLine: false }),
|
|
533
|
+
/* @__PURE__ */ jsx7(RadialBar, { dataKey: "value", background: { fill: "var(--muted)" }, cornerRadius: 6, isAnimationActive: animate }),
|
|
534
|
+
(centerLabel || centerValue) && /* @__PURE__ */ jsxs7("text", { x: "50%", y: "50%", textAnchor: "middle", dominantBaseline: "middle", children: [
|
|
535
|
+
centerValue && /* @__PURE__ */ jsx7("tspan", { x: "50%", dy: "-6", fill: chartTokens.foreground, fontSize: 20, fontWeight: 600, children: centerValue }),
|
|
536
|
+
centerLabel && /* @__PURE__ */ jsx7("tspan", { x: "50%", dy: centerValue ? "20" : "0", fill: chartTokens.muted, fontSize: 11, children: centerLabel })
|
|
537
|
+
] })
|
|
538
|
+
] }) });
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/charts/sparkline.tsx
|
|
542
|
+
import { useId as useId4 } from "react";
|
|
543
|
+
import { Area as Area2, AreaChart as RechartsAreaChart2, YAxis as YAxis4 } from "recharts";
|
|
544
|
+
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
545
|
+
function Sparkline({ values, color = chartColor(0), height = 32, filled = true }) {
|
|
546
|
+
const chartId = `spark-${useId4().replace(/:/g, "")}`;
|
|
547
|
+
const data = values.filter(Number.isFinite).map((v, i) => ({ i, v }));
|
|
548
|
+
if (data.length < 2) return null;
|
|
549
|
+
const id = fillId(chartId, "v", "gradient");
|
|
550
|
+
return /* @__PURE__ */ jsx8("div", { "aria-hidden": "true", "data-testid": "sparkline", children: /* @__PURE__ */ jsx8(ChartContainer, { height, children: /* @__PURE__ */ jsxs8(RechartsAreaChart2, { data, margin: { top: 2, right: 0, left: 0, bottom: 2 }, children: [
|
|
551
|
+
/* @__PURE__ */ jsx8("defs", { children: /* @__PURE__ */ jsx8(AreaFill, { id, variant: "gradient", color }) }),
|
|
552
|
+
/* @__PURE__ */ jsx8(YAxis4, { hide: true, domain: ["dataMin", "dataMax"] }),
|
|
553
|
+
/* @__PURE__ */ jsx8(
|
|
554
|
+
Area2,
|
|
555
|
+
{
|
|
556
|
+
type: "monotone",
|
|
557
|
+
dataKey: "v",
|
|
558
|
+
stroke: color,
|
|
559
|
+
strokeWidth: 1.5,
|
|
560
|
+
fill: filled ? `url(#${id})` : "none",
|
|
561
|
+
dot: false,
|
|
562
|
+
isAnimationActive: false
|
|
563
|
+
}
|
|
564
|
+
)
|
|
565
|
+
] }) }) });
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// src/charts/kpi-card.tsx
|
|
569
|
+
import { ArrowDownRight, ArrowUpRight, Minus } from "lucide-react";
|
|
570
|
+
|
|
571
|
+
// src/info-tip.tsx
|
|
572
|
+
import { Popover } from "@base-ui/react/popover";
|
|
573
|
+
|
|
574
|
+
// src/tokens.ts
|
|
575
|
+
var MIN_SIZES = {
|
|
576
|
+
/** WCAG 2.5.5 minimum interactive target, px. Applies to BOTH width and height. */
|
|
577
|
+
touchTarget: 44,
|
|
578
|
+
/** Floor width for the always-inline search field on mobile, px. */
|
|
579
|
+
searchInput: 200,
|
|
580
|
+
/** Generic minimum width/height for a secondary control (button, select), px. */
|
|
581
|
+
control: 44,
|
|
582
|
+
/** Max width of the brand wordmark before it truncates, px. */
|
|
583
|
+
// DEV-5340: scaled with the wordmark's text-sm→text-base bump (180 × 16/14
|
|
584
|
+
// ≈ 206) so the truncation point keeps the same character budget.
|
|
585
|
+
wordmarkMaxWidth: 205
|
|
586
|
+
};
|
|
587
|
+
var TOUCH_TARGET_STYLE = {
|
|
588
|
+
minWidth: MIN_SIZES.touchTarget,
|
|
589
|
+
minHeight: MIN_SIZES.touchTarget
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/info-tip.tsx
|
|
593
|
+
import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
594
|
+
function InfoTip({ children, label = "More information", side = "top", align = "center", className }) {
|
|
595
|
+
return /* @__PURE__ */ jsxs9(Popover.Root, { children: [
|
|
596
|
+
/* @__PURE__ */ jsx9(
|
|
597
|
+
Popover.Trigger,
|
|
598
|
+
{
|
|
599
|
+
openOnHover: true,
|
|
600
|
+
delay: 150,
|
|
601
|
+
closeDelay: 100,
|
|
602
|
+
"aria-label": label,
|
|
603
|
+
style: TOUCH_TARGET_STYLE,
|
|
604
|
+
className: cn(
|
|
605
|
+
"group -my-3.5 inline-flex shrink-0 cursor-help items-center justify-center rounded-full align-middle text-muted-foreground outline-none transition-colors hover:text-foreground data-[popup-open]:text-foreground",
|
|
606
|
+
className
|
|
607
|
+
),
|
|
608
|
+
children: /* @__PURE__ */ jsx9(
|
|
609
|
+
"span",
|
|
610
|
+
{
|
|
611
|
+
"aria-hidden": "true",
|
|
612
|
+
className: "inline-flex size-4 items-center justify-center rounded-full border border-current text-[0.625rem] font-semibold leading-none group-focus-visible:ring-2 group-focus-visible:ring-ring/50",
|
|
613
|
+
children: "?"
|
|
614
|
+
}
|
|
615
|
+
)
|
|
616
|
+
}
|
|
617
|
+
),
|
|
618
|
+
/* @__PURE__ */ jsx9(Popover.Portal, { children: /* @__PURE__ */ jsx9(Popover.Positioner, { side, align, sideOffset: 8, collisionPadding: 16, className: "z-50", children: /* @__PURE__ */ jsx9(
|
|
619
|
+
Popover.Popup,
|
|
620
|
+
{
|
|
621
|
+
"aria-label": label,
|
|
622
|
+
className: "max-w-[min(20rem,calc(100vw-2rem))] origin-[var(--transform-origin)] rounded-md border border-border bg-popover px-3 py-2 text-left text-xs font-normal leading-relaxed text-popover-foreground shadow-md outline-none transition-[opacity,transform] duration-150 ease-out data-[ending-style]:scale-95 data-[ending-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 motion-reduce:transition-none",
|
|
623
|
+
children: /* @__PURE__ */ jsx9(Popover.Description, { children })
|
|
624
|
+
}
|
|
625
|
+
) }) })
|
|
626
|
+
] });
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/charts/kpi-card.tsx
|
|
630
|
+
import { Fragment, jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
631
|
+
function deltaTone(delta, polarity = "up-is-good") {
|
|
632
|
+
if (delta == null || !Number.isFinite(delta) || delta === 0 || polarity === "neutral") return "neutral";
|
|
633
|
+
const up = delta > 0;
|
|
634
|
+
return up === (polarity === "up-is-good") ? "positive" : "negative";
|
|
635
|
+
}
|
|
636
|
+
var TONE_COLOR = {
|
|
637
|
+
positive: chartTokens.positive,
|
|
638
|
+
negative: chartTokens.negative,
|
|
639
|
+
neutral: chartTokens.muted
|
|
640
|
+
};
|
|
641
|
+
var defaultDeltaFormat = (d) => `${d > 0 ? "+" : d < 0 ? "\u2212" : ""}${Math.abs(d * 100).toLocaleString("en-US", { maximumFractionDigits: 1 })}%`;
|
|
642
|
+
function KpiCard({
|
|
643
|
+
label,
|
|
644
|
+
value,
|
|
645
|
+
delta,
|
|
646
|
+
deltaLabel,
|
|
647
|
+
deltaFormatter = defaultDeltaFormat,
|
|
648
|
+
polarity = "up-is-good",
|
|
649
|
+
trend,
|
|
650
|
+
info,
|
|
651
|
+
loading = false,
|
|
652
|
+
state = "ok",
|
|
653
|
+
message,
|
|
654
|
+
action,
|
|
655
|
+
className
|
|
656
|
+
}) {
|
|
657
|
+
const tone = deltaTone(delta, polarity);
|
|
658
|
+
const toneColor = TONE_COLOR[tone];
|
|
659
|
+
const Arrow = !delta ? Minus : delta > 0 ? ArrowUpRight : ArrowDownRight;
|
|
660
|
+
return /* @__PURE__ */ jsxs10(
|
|
661
|
+
"div",
|
|
662
|
+
{
|
|
663
|
+
"data-slot": "kpi-card",
|
|
664
|
+
"data-state": loading ? "loading" : state,
|
|
665
|
+
className: cn("flex h-full min-w-0 flex-col gap-1 rounded-xl border bg-card p-4 text-card-foreground", className),
|
|
666
|
+
children: [
|
|
667
|
+
/* @__PURE__ */ jsxs10("div", { className: "flex min-w-0 items-center gap-1 text-xs font-medium text-muted-foreground", children: [
|
|
668
|
+
/* @__PURE__ */ jsx10("span", { className: "truncate", children: label }),
|
|
669
|
+
info && /* @__PURE__ */ jsx10(InfoTip, { label: "About this metric", children: info })
|
|
670
|
+
] }),
|
|
671
|
+
loading ? /* @__PURE__ */ jsxs10("div", { "aria-label": "Loading", role: "status", className: "flex flex-col gap-2 pt-1", children: [
|
|
672
|
+
/* @__PURE__ */ jsx10("div", { className: "h-7 w-24 animate-pulse rounded-md", style: { background: "var(--muted)" } }),
|
|
673
|
+
/* @__PURE__ */ jsx10("div", { className: "h-4 w-16 animate-pulse rounded-md", style: { background: "var(--muted)" } })
|
|
674
|
+
] }) : state !== "ok" ? /* @__PURE__ */ jsxs10("div", { className: "flex flex-1 flex-col items-start gap-2 pt-1", children: [
|
|
675
|
+
/* @__PURE__ */ jsx10("p", { className: "text-sm text-muted-foreground", children: message ?? (state === "setup" ? "Not connected yet." : "No data yet.") }),
|
|
676
|
+
state === "setup" && action
|
|
677
|
+
] }) : /* @__PURE__ */ jsxs10(Fragment, { children: [
|
|
678
|
+
/* @__PURE__ */ jsx10("div", { className: "truncate text-2xl font-semibold tabular-nums tracking-tight", children: value }),
|
|
679
|
+
/* @__PURE__ */ jsxs10("div", { className: "flex min-w-0 items-center gap-2 text-xs", children: [
|
|
680
|
+
delta != null && Number.isFinite(delta) && /* @__PURE__ */ jsxs10(
|
|
681
|
+
"span",
|
|
682
|
+
{
|
|
683
|
+
"data-testid": "kpi-delta",
|
|
684
|
+
"data-tone": tone,
|
|
685
|
+
className: "inline-flex items-center gap-0.5 rounded-full px-1.5 py-0.5 font-medium tabular-nums",
|
|
686
|
+
style: { color: toneColor, background: withAlpha(toneColor, 12) },
|
|
687
|
+
children: [
|
|
688
|
+
/* @__PURE__ */ jsx10(Arrow, { "aria-hidden": "true", className: "h-3 w-3" }),
|
|
689
|
+
deltaFormatter(delta)
|
|
690
|
+
]
|
|
691
|
+
}
|
|
692
|
+
),
|
|
693
|
+
deltaLabel && /* @__PURE__ */ jsx10("span", { className: "truncate text-muted-foreground", children: deltaLabel })
|
|
694
|
+
] }),
|
|
695
|
+
trend && trend.length > 1 && /* @__PURE__ */ jsx10("div", { className: "mt-auto pt-2", children: /* @__PURE__ */ jsx10(Sparkline, { values: trend, color: tone === "neutral" ? chartColor(0) : toneColor }) })
|
|
696
|
+
] })
|
|
697
|
+
]
|
|
698
|
+
}
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// src/charts/chart-card.tsx
|
|
703
|
+
import { Fragment as Fragment2, jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
704
|
+
var RANGE_LABEL = { "7d": "7d", "30d": "30d", "90d": "90d", custom: "Custom" };
|
|
705
|
+
var DEFAULT_MESSAGE = {
|
|
706
|
+
empty: "No data for this period.",
|
|
707
|
+
setup: "Connect a source to see this chart.",
|
|
708
|
+
error: "This chart couldn\u2019t load. Try again shortly."
|
|
709
|
+
};
|
|
710
|
+
function ChartCard({
|
|
711
|
+
title,
|
|
712
|
+
subtitle,
|
|
713
|
+
info,
|
|
714
|
+
action,
|
|
715
|
+
range,
|
|
716
|
+
legend,
|
|
717
|
+
state = "ok",
|
|
718
|
+
message,
|
|
719
|
+
setupAction,
|
|
720
|
+
height = 240,
|
|
721
|
+
className,
|
|
722
|
+
children
|
|
723
|
+
}) {
|
|
724
|
+
return /* @__PURE__ */ jsxs11(
|
|
725
|
+
"section",
|
|
726
|
+
{
|
|
727
|
+
"data-slot": "chart-card",
|
|
728
|
+
"data-state": state,
|
|
729
|
+
className: cn("flex h-full min-w-0 flex-col gap-3 rounded-xl border bg-card p-4 text-card-foreground", className),
|
|
730
|
+
children: [
|
|
731
|
+
/* @__PURE__ */ jsxs11("header", { className: "flex min-w-0 flex-wrap items-start justify-between gap-2", children: [
|
|
732
|
+
/* @__PURE__ */ jsxs11("div", { className: "min-w-0", children: [
|
|
733
|
+
/* @__PURE__ */ jsxs11("h3", { className: "flex items-center gap-1 text-sm font-semibold", children: [
|
|
734
|
+
/* @__PURE__ */ jsx11("span", { className: "truncate", children: title }),
|
|
735
|
+
info && /* @__PURE__ */ jsx11(InfoTip, { label: "About this chart", children: info })
|
|
736
|
+
] }),
|
|
737
|
+
subtitle && /* @__PURE__ */ jsx11("p", { className: "truncate text-xs text-muted-foreground", children: subtitle })
|
|
738
|
+
] }),
|
|
739
|
+
/* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-2", children: [
|
|
740
|
+
range && /* @__PURE__ */ jsx11("div", { role: "group", "aria-label": "Date range", className: "inline-flex rounded-lg border p-0.5 text-xs", children: (range.options ?? ["7d", "30d", "90d"]).map((r) => (
|
|
741
|
+
// 44px hit area (the package floor) with a vertical negative
|
|
742
|
+
// margin, so the pill stays compact in the header — same trick
|
|
743
|
+
// as InfoTip.
|
|
744
|
+
/* @__PURE__ */ jsx11(
|
|
745
|
+
"button",
|
|
746
|
+
{
|
|
747
|
+
type: "button",
|
|
748
|
+
"aria-pressed": range.value === r,
|
|
749
|
+
onClick: () => range.onChange(r),
|
|
750
|
+
className: "inline-flex items-center justify-center",
|
|
751
|
+
style: { ...TOUCH_TARGET_STYLE, marginBlock: -10 },
|
|
752
|
+
children: /* @__PURE__ */ jsx11(
|
|
753
|
+
"span",
|
|
754
|
+
{
|
|
755
|
+
className: cn(
|
|
756
|
+
"rounded-md px-2 py-1 font-medium tabular-nums",
|
|
757
|
+
range.value === r ? "bg-muted text-foreground" : "text-muted-foreground"
|
|
758
|
+
),
|
|
759
|
+
children: RANGE_LABEL[r]
|
|
760
|
+
}
|
|
761
|
+
)
|
|
762
|
+
},
|
|
763
|
+
r
|
|
764
|
+
)
|
|
765
|
+
)) }),
|
|
766
|
+
action
|
|
767
|
+
] })
|
|
768
|
+
] }),
|
|
769
|
+
state === "loading" ? /* @__PURE__ */ jsx11(ChartSkeleton, { height }) : state === "ok" ? /* @__PURE__ */ jsxs11(Fragment2, { children: [
|
|
770
|
+
/* @__PURE__ */ jsx11("div", { className: "min-w-0", children }),
|
|
771
|
+
legend && /* @__PURE__ */ jsx11("div", { className: "text-xs text-muted-foreground", children: legend })
|
|
772
|
+
] }) : /* @__PURE__ */ jsxs11(
|
|
773
|
+
"div",
|
|
774
|
+
{
|
|
775
|
+
role: state === "error" ? "alert" : void 0,
|
|
776
|
+
className: "flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed p-6 text-center",
|
|
777
|
+
style: { minHeight: Math.min(height, 160) },
|
|
778
|
+
children: [
|
|
779
|
+
/* @__PURE__ */ jsx11("p", { className: "text-sm text-muted-foreground", children: message ?? DEFAULT_MESSAGE[state] }),
|
|
780
|
+
state === "setup" && setupAction
|
|
781
|
+
]
|
|
782
|
+
}
|
|
783
|
+
)
|
|
784
|
+
]
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// src/charts/dashboard-grid.tsx
|
|
790
|
+
import { jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
791
|
+
var DASHBOARD_TIERS = [
|
|
792
|
+
// Docked desktop pane and up: 4 KPIs per row.
|
|
793
|
+
{ minWidth: 880, columns: 12, span: { sm: 3, md: 6, lg: 8, wide: 9, full: 12 } },
|
|
794
|
+
// Tablet: 3 KPIs per row, charts half or full.
|
|
795
|
+
{ minWidth: 600, columns: 12, span: { sm: 4, md: 6, lg: 12, wide: 12, full: 12 } },
|
|
796
|
+
// Narrow pane and phones: 2 KPIs per row, every chart full width.
|
|
797
|
+
{ minWidth: 320, columns: 6, span: { sm: 3, md: 6, lg: 6, wide: 6, full: 6 } },
|
|
798
|
+
{ minWidth: 0, columns: 1, span: { sm: 1, md: 1, lg: 1, wide: 1, full: 1 } }
|
|
799
|
+
];
|
|
800
|
+
function tierFor(width) {
|
|
801
|
+
return DASHBOARD_TIERS.find((t) => width >= t.minWidth) ?? DASHBOARD_TIERS[DASHBOARD_TIERS.length - 1];
|
|
802
|
+
}
|
|
803
|
+
function dashboardSpan(width, size) {
|
|
804
|
+
const tier = tierFor(width);
|
|
805
|
+
const span = tier.span[size];
|
|
806
|
+
return { columns: tier.columns, span, perRow: Math.floor(tier.columns / span) };
|
|
807
|
+
}
|
|
808
|
+
var SIZES = ["sm", "md", "lg", "wide", "full"];
|
|
809
|
+
function tierRules(t) {
|
|
810
|
+
return [
|
|
811
|
+
`.mf-dash__grid{grid-template-columns:repeat(${t.columns},minmax(0,1fr))}`,
|
|
812
|
+
...SIZES.map((s) => `.mf-dash__item[data-size=${s}]{grid-column:span ${t.span[s]}/span ${t.span[s]}}`)
|
|
813
|
+
].join("");
|
|
814
|
+
}
|
|
815
|
+
var DASHBOARD_GRID_CSS = [
|
|
816
|
+
".mf-dash{container:mf-dash/inline-size}",
|
|
817
|
+
".mf-dash__grid{display:grid;gap:var(--mf-dash-gap,12px);grid-auto-flow:row dense}",
|
|
818
|
+
".mf-dash__item{min-width:0}",
|
|
819
|
+
...[...DASHBOARD_TIERS].reverse().map((t) => t.minWidth === 0 ? tierRules(t) : `@container mf-dash (min-width:${t.minWidth}px){${tierRules(t)}}`)
|
|
820
|
+
].join("\n");
|
|
821
|
+
function DashboardGridRoot({ className, children }) {
|
|
822
|
+
return /* @__PURE__ */ jsxs12("div", { "data-slot": "dashboard-grid", className: cn("mf-dash", className), children: [
|
|
823
|
+
/* @__PURE__ */ jsx12("style", { children: DASHBOARD_GRID_CSS }),
|
|
824
|
+
/* @__PURE__ */ jsx12("div", { className: "mf-dash__grid", children })
|
|
825
|
+
] });
|
|
826
|
+
}
|
|
827
|
+
function DashboardGridItem({ size = "sm", className, children }) {
|
|
828
|
+
return /* @__PURE__ */ jsx12("div", { "data-size": size, className: cn("mf-dash__item", className), children });
|
|
829
|
+
}
|
|
830
|
+
var DashboardGrid = Object.assign(DashboardGridRoot, { Item: DashboardGridItem });
|
|
831
|
+
export {
|
|
832
|
+
AreaChart,
|
|
833
|
+
BAR_CATEGORY_GAP,
|
|
834
|
+
BAR_STANDARD,
|
|
835
|
+
BarChart,
|
|
836
|
+
CHART_SERIES_COUNT,
|
|
837
|
+
ChartCard,
|
|
838
|
+
ChartContainer,
|
|
839
|
+
ChartSkeleton,
|
|
840
|
+
ChartTooltip,
|
|
841
|
+
ChartTooltipContent,
|
|
842
|
+
DASHBOARD_GRID_CSS,
|
|
843
|
+
DASHBOARD_TIERS,
|
|
844
|
+
DashboardGrid,
|
|
845
|
+
DonutChart,
|
|
846
|
+
KpiCard,
|
|
847
|
+
LineChart,
|
|
848
|
+
RadialChart,
|
|
849
|
+
Sparkline,
|
|
850
|
+
barValueLabel,
|
|
851
|
+
chartColor,
|
|
852
|
+
chartConfig,
|
|
853
|
+
chartPalette,
|
|
854
|
+
chartTokens,
|
|
855
|
+
dashboardSpan,
|
|
856
|
+
deltaTone,
|
|
857
|
+
useChart,
|
|
858
|
+
usePrefersReducedMotion,
|
|
859
|
+
withAlpha
|
|
860
|
+
};
|