@cere/cere-design-system 0.0.45 → 0.2.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 +76 -0
- package/dist/buttons.d.mts +119 -0
- package/dist/buttons.d.ts +119 -0
- package/dist/buttons.js +19 -0
- package/dist/buttons.js.map +1 -0
- package/dist/buttons.mjs +19 -0
- package/dist/buttons.mjs.map +1 -0
- package/dist/carousel.d.mts +51 -0
- package/dist/carousel.d.ts +51 -0
- package/dist/carousel.js +185 -0
- package/dist/carousel.js.map +1 -0
- package/dist/carousel.mjs +185 -0
- package/dist/carousel.mjs.map +1 -0
- package/dist/charts.d.mts +187 -0
- package/dist/charts.d.ts +187 -0
- package/dist/charts.js +13 -0
- package/dist/charts.js.map +1 -0
- package/dist/charts.mjs +13 -0
- package/dist/charts.mjs.map +1 -0
- package/dist/chunk-2EBCST6X.js +25 -0
- package/dist/chunk-2EBCST6X.js.map +1 -0
- package/dist/chunk-2KDN37PQ.js +486 -0
- package/dist/chunk-2KDN37PQ.js.map +1 -0
- package/dist/chunk-34LFXT6C.mjs +486 -0
- package/dist/chunk-34LFXT6C.mjs.map +1 -0
- package/dist/chunk-3KCXCVOX.mjs +411 -0
- package/dist/chunk-3KCXCVOX.mjs.map +1 -0
- package/dist/chunk-4OKTICU5.js +374 -0
- package/dist/chunk-4OKTICU5.js.map +1 -0
- package/dist/chunk-5ASG6G6U.mjs +40 -0
- package/dist/chunk-5ASG6G6U.mjs.map +1 -0
- package/dist/chunk-72TQ56EP.js +280 -0
- package/dist/chunk-72TQ56EP.js.map +1 -0
- package/dist/chunk-7KXKK2RE.js +43 -0
- package/dist/chunk-7KXKK2RE.js.map +1 -0
- package/dist/chunk-ARSCL4ZZ.js +111 -0
- package/dist/chunk-ARSCL4ZZ.js.map +1 -0
- package/dist/chunk-AWVNEU6R.mjs +1478 -0
- package/dist/chunk-AWVNEU6R.mjs.map +1 -0
- package/dist/chunk-BH4FNZKK.mjs +1472 -0
- package/dist/chunk-BH4FNZKK.mjs.map +1 -0
- package/dist/chunk-BIZK6FUD.js +37 -0
- package/dist/chunk-BIZK6FUD.js.map +1 -0
- package/dist/chunk-BOQPWZIB.mjs +147 -0
- package/dist/chunk-BOQPWZIB.mjs.map +1 -0
- package/dist/chunk-BT7XUTT5.mjs +392 -0
- package/dist/chunk-BT7XUTT5.mjs.map +1 -0
- package/dist/chunk-D7D25O6E.mjs +280 -0
- package/dist/chunk-D7D25O6E.mjs.map +1 -0
- package/dist/chunk-DRGMEIPT.mjs +162 -0
- package/dist/chunk-DRGMEIPT.mjs.map +1 -0
- package/dist/chunk-DZXNYLVG.js +392 -0
- package/dist/chunk-DZXNYLVG.js.map +1 -0
- package/dist/chunk-GR52ENYI.mjs +527 -0
- package/dist/chunk-GR52ENYI.mjs.map +1 -0
- package/dist/chunk-GTBKQXXI.js +1472 -0
- package/dist/chunk-GTBKQXXI.js.map +1 -0
- package/dist/chunk-HJ24WKU4.js +120 -0
- package/dist/chunk-HJ24WKU4.js.map +1 -0
- package/dist/chunk-JBHRAAN3.js +31 -0
- package/dist/chunk-JBHRAAN3.js.map +1 -0
- package/dist/chunk-KKIKOIMP.js +1478 -0
- package/dist/chunk-KKIKOIMP.js.map +1 -0
- package/dist/chunk-LVJSKRX3.js +147 -0
- package/dist/chunk-LVJSKRX3.js.map +1 -0
- package/dist/chunk-OWWDNDF4.js +40 -0
- package/dist/chunk-OWWDNDF4.js.map +1 -0
- package/dist/chunk-PFZZJZ64.js +162 -0
- package/dist/chunk-PFZZJZ64.js.map +1 -0
- package/dist/chunk-PHMNZK2R.mjs +18 -0
- package/dist/chunk-PHMNZK2R.mjs.map +1 -0
- package/dist/chunk-POCAW2G4.mjs +111 -0
- package/dist/chunk-POCAW2G4.mjs.map +1 -0
- package/dist/chunk-QBCRH7YF.mjs +37 -0
- package/dist/chunk-QBCRH7YF.mjs.map +1 -0
- package/dist/chunk-QCFLZ7X3.js +527 -0
- package/dist/chunk-QCFLZ7X3.js.map +1 -0
- package/dist/chunk-SG2TD7FQ.mjs +374 -0
- package/dist/chunk-SG2TD7FQ.mjs.map +1 -0
- package/dist/chunk-SSFALO6S.mjs +120 -0
- package/dist/chunk-SSFALO6S.mjs.map +1 -0
- package/dist/chunk-U2QHFISG.js +18 -0
- package/dist/chunk-U2QHFISG.js.map +1 -0
- package/dist/chunk-UPGFBPFX.mjs +25 -0
- package/dist/chunk-UPGFBPFX.mjs.map +1 -0
- package/dist/chunk-WC2TCWXK.mjs +445 -0
- package/dist/chunk-WC2TCWXK.mjs.map +1 -0
- package/dist/chunk-XZZZ4MZV.js +445 -0
- package/dist/chunk-XZZZ4MZV.js.map +1 -0
- package/dist/chunk-YCDCQSYH.js +411 -0
- package/dist/chunk-YCDCQSYH.js.map +1 -0
- package/dist/chunk-ZDAZYIXB.mjs +43 -0
- package/dist/chunk-ZDAZYIXB.mjs.map +1 -0
- package/dist/chunk-ZP26PGMS.mjs +31 -0
- package/dist/chunk-ZP26PGMS.mjs.map +1 -0
- package/dist/feedback.d.mts +368 -0
- package/dist/feedback.d.ts +368 -0
- package/dist/feedback.js +43 -0
- package/dist/feedback.js.map +1 -0
- package/dist/feedback.mjs +43 -0
- package/dist/feedback.mjs.map +1 -0
- package/dist/fonts/HumanSans-BlackOblique.otf +0 -0
- package/dist/fonts/HumanSans-Thin.otf +0 -0
- package/dist/fonts/HumanSans-ThinOblique.otf +0 -0
- package/dist/fonts/human-sans-font.css +88 -0
- package/dist/fonts/human-sans.css +3 -0
- package/dist/fonts/inter.css +3 -0
- package/dist/icons.d.mts +21 -0
- package/dist/icons.d.ts +21 -0
- package/dist/icons.js +23 -0
- package/dist/icons.js.map +1 -0
- package/dist/icons.mjs +23 -0
- package/dist/icons.mjs.map +1 -0
- package/dist/index.d.mts +196 -3082
- package/dist/index.d.ts +196 -3082
- package/dist/index.js +253 -10082
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +229 -10017
- package/dist/index.mjs.map +1 -1
- package/dist/inputs.d.mts +129 -0
- package/dist/inputs.d.ts +129 -0
- package/dist/inputs.js +43 -0
- package/dist/inputs.js.map +1 -0
- package/dist/inputs.mjs +43 -0
- package/dist/inputs.mjs.map +1 -0
- package/dist/layout.d.mts +681 -0
- package/dist/layout.d.ts +681 -0
- package/dist/layout.js +98 -0
- package/dist/layout.js.map +1 -0
- package/dist/layout.mjs +98 -0
- package/dist/layout.mjs.map +1 -0
- package/dist/navigation.d.mts +611 -0
- package/dist/navigation.d.ts +611 -0
- package/dist/navigation.js +54 -0
- package/dist/navigation.js.map +1 -0
- package/dist/navigation.mjs +54 -0
- package/dist/navigation.mjs.map +1 -0
- package/dist/third-party.d.mts +113 -0
- package/dist/third-party.d.ts +113 -0
- package/dist/third-party.js +7 -0
- package/dist/third-party.js.map +1 -0
- package/dist/third-party.mjs +7 -0
- package/dist/third-party.mjs.map +1 -0
- package/dist/tokens.css +45 -71
- package/dist/utilities.d.mts +39 -0
- package/dist/utilities.d.ts +39 -0
- package/dist/utilities.js +17 -0
- package/dist/utilities.js.map +1 -0
- package/dist/utilities.mjs +17 -0
- package/dist/utilities.mjs.map +1 -0
- package/package.json +76 -8
- package/dist/index.css +0 -79
- package/dist/index.css.map +0 -1
- /package/dist/{HumanSans-Black-C4YJONK7.otf → fonts/HumanSans-Black.otf} +0 -0
- /package/dist/{HumanSans-Bold-4EAJ3L3T.otf → fonts/HumanSans-Bold.otf} +0 -0
- /package/dist/{HumanSans-BoldOblique-4D325T4F.otf → fonts/HumanSans-BoldOblique.otf} +0 -0
- /package/dist/{HumanSans-ExtraLight-VL7DEKQ4.otf → fonts/HumanSans-ExtraLight.otf} +0 -0
- /package/dist/{HumanSans-ExtraLightOblique-VK2JTUXF.otf → fonts/HumanSans-ExtraLightOblique.otf} +0 -0
- /package/dist/{HumanSans-Light-YV7AFKRB.otf → fonts/HumanSans-Light.otf} +0 -0
- /package/dist/{HumanSans-LightOblique-VIXV7QA6.otf → fonts/HumanSans-LightOblique.otf} +0 -0
- /package/dist/{HumanSans-Medium-UULJ3PIR.otf → fonts/HumanSans-Medium.otf} +0 -0
- /package/dist/{HumanSans-MediumOblique-M7FHDZRS.otf → fonts/HumanSans-MediumOblique.otf} +0 -0
- /package/dist/{HumanSans-Regular-QMFEP3F6.otf → fonts/HumanSans-Regular.otf} +0 -0
- /package/dist/{HumanSans-RegularOblique-YPKQJAAM.otf → fonts/HumanSans-RegularOblique.otf} +0 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// src/components/charts/ChartWidget/ChartWidget.tsx
|
|
2
|
+
import Box from "@mui/material/Box";
|
|
3
|
+
import Stack from "@mui/material/Stack";
|
|
4
|
+
import Typography from "@mui/material/Typography";
|
|
5
|
+
import { styled, useTheme } from "@mui/material/styles";
|
|
6
|
+
import { LineChart } from "@mui/x-charts";
|
|
7
|
+
import size from "byte-size";
|
|
8
|
+
import { format } from "date-fns";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var Chart = styled(Box)(() => ({
|
|
11
|
+
height: 200
|
|
12
|
+
}));
|
|
13
|
+
var ChartWidget = ({
|
|
14
|
+
title,
|
|
15
|
+
value,
|
|
16
|
+
history,
|
|
17
|
+
formatValue = (value2) => size(value2 || 0).toString()
|
|
18
|
+
}) => {
|
|
19
|
+
const theme = useTheme();
|
|
20
|
+
return /* @__PURE__ */ jsxs(Stack, { spacing: 1, children: [
|
|
21
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: title }),
|
|
22
|
+
/* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: value }),
|
|
23
|
+
/* @__PURE__ */ jsx(Chart, { children: /* @__PURE__ */ jsx(
|
|
24
|
+
LineChart,
|
|
25
|
+
{
|
|
26
|
+
dataset: history || [],
|
|
27
|
+
axisHighlight: { x: "none", y: "none" },
|
|
28
|
+
grid: { horizontal: true, vertical: false },
|
|
29
|
+
margin: { top: 10, right: 20, bottom: 40, left: 40 },
|
|
30
|
+
colors: [theme.palette.primary.main],
|
|
31
|
+
slots: {
|
|
32
|
+
noDataOverlay: () => null
|
|
33
|
+
},
|
|
34
|
+
yAxis: [
|
|
35
|
+
{
|
|
36
|
+
dataKey: "value",
|
|
37
|
+
disableLine: true,
|
|
38
|
+
disableTicks: true,
|
|
39
|
+
min: history?.length ? void 0 : 0,
|
|
40
|
+
max: history?.length ? void 0 : 100,
|
|
41
|
+
tickNumber: history?.length ? void 0 : 5,
|
|
42
|
+
valueFormatter: (value2) => formatValue(value2 || 0),
|
|
43
|
+
tickLabelStyle: {
|
|
44
|
+
fontSize: 10
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
xAxis: [
|
|
49
|
+
{
|
|
50
|
+
dataKey: "date",
|
|
51
|
+
min: history && Math.min(...history.map((record) => +record.date)),
|
|
52
|
+
max: history && Math.max(...history.map((record) => +record.date)),
|
|
53
|
+
disableLine: true,
|
|
54
|
+
disableTicks: true,
|
|
55
|
+
valueFormatter: (date) => format(date, "do MMM"),
|
|
56
|
+
tickPlacement: "end",
|
|
57
|
+
tickNumber: 1,
|
|
58
|
+
tickLabelStyle: {
|
|
59
|
+
fontSize: 10,
|
|
60
|
+
transform: "translate(-16px, 16px) rotate(-30deg)"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
series: [
|
|
65
|
+
{
|
|
66
|
+
curve: "linear",
|
|
67
|
+
dataKey: "value",
|
|
68
|
+
showMark: false,
|
|
69
|
+
valueFormatter: (value2) => formatValue(value2 || 0)
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
) })
|
|
74
|
+
] });
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/components/charts/TimeSeriesGraph/TimeSeriesGraph.tsx
|
|
78
|
+
import { useCallback, useMemo, useState } from "react";
|
|
79
|
+
import Box2 from "@mui/material/Box";
|
|
80
|
+
import Card from "@mui/material/Card";
|
|
81
|
+
import CardHeader from "@mui/material/CardHeader";
|
|
82
|
+
import CardMedia from "@mui/material/CardMedia";
|
|
83
|
+
import CircularProgress from "@mui/material/CircularProgress";
|
|
84
|
+
import Divider from "@mui/material/Divider";
|
|
85
|
+
import Stack3 from "@mui/material/Stack";
|
|
86
|
+
import Typography3 from "@mui/material/Typography";
|
|
87
|
+
import { styled as styled2, useTheme as useTheme2 } from "@mui/material/styles";
|
|
88
|
+
import { LineChart as LineChart2 } from "@mui/x-charts";
|
|
89
|
+
import { format as format2 } from "date-fns";
|
|
90
|
+
|
|
91
|
+
// src/components/charts/TimeSeriesGraph/TimeRangeSelect.tsx
|
|
92
|
+
import MenuItem from "@mui/material/MenuItem";
|
|
93
|
+
import TextField from "@mui/material/TextField";
|
|
94
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
95
|
+
var TimeRangeSelect = ({ options, value, onChange }) => /* @__PURE__ */ jsx2(
|
|
96
|
+
TextField,
|
|
97
|
+
{
|
|
98
|
+
select: true,
|
|
99
|
+
size: "small",
|
|
100
|
+
value: value ?? (options.length > 0 ? options[0].value : ""),
|
|
101
|
+
onChange: (e) => onChange?.(e.target.value),
|
|
102
|
+
"aria-label": "Time range selector",
|
|
103
|
+
sx: { minWidth: 120 },
|
|
104
|
+
children: options.map((option) => /* @__PURE__ */ jsx2(MenuItem, { value: option.value, children: option.label }, option.value))
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// src/components/charts/TimeSeriesGraph/SummaryStats.tsx
|
|
109
|
+
import Stack2 from "@mui/material/Stack";
|
|
110
|
+
import Typography2 from "@mui/material/Typography";
|
|
111
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
112
|
+
var formatSummaryValue = (value, unit) => {
|
|
113
|
+
const displayValue = typeof value === "number" ? value.toLocaleString() : value;
|
|
114
|
+
return unit ? `${displayValue} ${unit}` : displayValue;
|
|
115
|
+
};
|
|
116
|
+
var SummaryStats = ({ items }) => {
|
|
117
|
+
if (items.length === 0) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return /* @__PURE__ */ jsx3(
|
|
121
|
+
Stack2,
|
|
122
|
+
{
|
|
123
|
+
direction: "row",
|
|
124
|
+
spacing: 3,
|
|
125
|
+
padding: 2,
|
|
126
|
+
flexWrap: "wrap",
|
|
127
|
+
useFlexGap: true,
|
|
128
|
+
role: "list",
|
|
129
|
+
"aria-label": "Summary statistics",
|
|
130
|
+
children: items.map((item) => /* @__PURE__ */ jsxs2(
|
|
131
|
+
Stack2,
|
|
132
|
+
{
|
|
133
|
+
direction: "row",
|
|
134
|
+
alignItems: "center",
|
|
135
|
+
spacing: 1,
|
|
136
|
+
role: "listitem",
|
|
137
|
+
children: [
|
|
138
|
+
/* @__PURE__ */ jsx3(Typography2, { variant: "body2", color: "text.secondary", children: item.label }),
|
|
139
|
+
/* @__PURE__ */ jsx3(Typography2, { variant: "h5", fontWeight: 600, children: formatSummaryValue(item.value, item.unit) })
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
item.label
|
|
143
|
+
))
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/components/charts/TimeSeriesGraph/TimeSeriesGraph.tsx
|
|
149
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
150
|
+
var ChartContainer = styled2(Box2)({
|
|
151
|
+
position: "relative",
|
|
152
|
+
height: 320
|
|
153
|
+
});
|
|
154
|
+
var LoadingOverlay = styled2(Box2)(({ theme }) => ({
|
|
155
|
+
position: "absolute",
|
|
156
|
+
inset: 0,
|
|
157
|
+
display: "flex",
|
|
158
|
+
alignItems: "center",
|
|
159
|
+
justifyContent: "center",
|
|
160
|
+
backgroundColor: "rgba(255, 255, 255, 0.7)",
|
|
161
|
+
zIndex: 1,
|
|
162
|
+
borderRadius: theme.shape.borderRadius
|
|
163
|
+
}));
|
|
164
|
+
var LegendDot = styled2(Box2, {
|
|
165
|
+
shouldForwardProp: (prop) => prop !== "dotColor"
|
|
166
|
+
})(({ dotColor }) => ({
|
|
167
|
+
width: 14,
|
|
168
|
+
height: 14,
|
|
169
|
+
borderRadius: 4,
|
|
170
|
+
backgroundColor: dotColor,
|
|
171
|
+
flexShrink: 0
|
|
172
|
+
}));
|
|
173
|
+
var formatYAxisValue = (value) => {
|
|
174
|
+
const absValue = Math.abs(value);
|
|
175
|
+
if (absValue >= 1e9) {
|
|
176
|
+
return `${(value / 1e9).toFixed(absValue % 1e9 === 0 ? 0 : 1)}B`;
|
|
177
|
+
}
|
|
178
|
+
if (absValue >= 1e6) {
|
|
179
|
+
return `${(value / 1e6).toFixed(absValue % 1e6 === 0 ? 0 : 1)}M`;
|
|
180
|
+
}
|
|
181
|
+
if (absValue >= 1e3) {
|
|
182
|
+
return `${(value / 1e3).toFixed(absValue % 1e3 === 0 ? 0 : 1)}K`;
|
|
183
|
+
}
|
|
184
|
+
return String(value);
|
|
185
|
+
};
|
|
186
|
+
var TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1e3;
|
|
187
|
+
var inferXAxisFormat = (min, max) => {
|
|
188
|
+
if (!min || !max) return "do MMM";
|
|
189
|
+
const spanMs = max.getTime() - min.getTime();
|
|
190
|
+
return spanMs <= TWENTY_FOUR_HOURS_MS ? "HH:mm" : "do MMM";
|
|
191
|
+
};
|
|
192
|
+
var buildDataset = (series, hiddenSeries) => {
|
|
193
|
+
const timestampMap = /* @__PURE__ */ new Map();
|
|
194
|
+
series.forEach((s) => {
|
|
195
|
+
if (hiddenSeries.has(s.name)) return;
|
|
196
|
+
s.data.forEach((dp) => {
|
|
197
|
+
const ts = dp.timestamp.getTime();
|
|
198
|
+
if (!timestampMap.has(ts)) {
|
|
199
|
+
timestampMap.set(ts, { timestamp: dp.timestamp });
|
|
200
|
+
}
|
|
201
|
+
timestampMap.get(ts)[s.name] = dp.value;
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
return Array.from(timestampMap.values()).sort(
|
|
205
|
+
(a, b) => a.timestamp.getTime() - b.timestamp.getTime()
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
var TimeSeriesGraph = ({
|
|
209
|
+
title,
|
|
210
|
+
series,
|
|
211
|
+
timeRangeOptions,
|
|
212
|
+
selectedTimeRange,
|
|
213
|
+
onTimeRangeChange,
|
|
214
|
+
summaryItems,
|
|
215
|
+
showSummary = true,
|
|
216
|
+
headerAction,
|
|
217
|
+
loading = false,
|
|
218
|
+
xAxisFormat
|
|
219
|
+
}) => {
|
|
220
|
+
const theme = useTheme2();
|
|
221
|
+
const [hiddenSeries, setHiddenSeries] = useState(/* @__PURE__ */ new Set());
|
|
222
|
+
const dataset = useMemo(() => buildDataset(series, hiddenSeries), [series, hiddenSeries]);
|
|
223
|
+
const visibleSeries = useMemo(
|
|
224
|
+
() => series.filter((s) => !hiddenSeries.has(s.name)),
|
|
225
|
+
[series, hiddenSeries]
|
|
226
|
+
);
|
|
227
|
+
const chartColors = useMemo(() => visibleSeries.map((s) => s.color), [visibleSeries]);
|
|
228
|
+
const handleLegendToggle = useCallback((seriesName) => {
|
|
229
|
+
setHiddenSeries((prev) => {
|
|
230
|
+
const next = new Set(prev);
|
|
231
|
+
if (next.has(seriesName)) {
|
|
232
|
+
next.delete(seriesName);
|
|
233
|
+
} else {
|
|
234
|
+
next.add(seriesName);
|
|
235
|
+
}
|
|
236
|
+
return next;
|
|
237
|
+
});
|
|
238
|
+
}, []);
|
|
239
|
+
const timeBounds = useMemo(() => {
|
|
240
|
+
if (dataset.length === 0) return { min: void 0, max: void 0 };
|
|
241
|
+
const timestamps = dataset.map((row) => row.timestamp.getTime());
|
|
242
|
+
return {
|
|
243
|
+
min: new Date(Math.min(...timestamps)),
|
|
244
|
+
max: new Date(Math.max(...timestamps))
|
|
245
|
+
};
|
|
246
|
+
}, [dataset]);
|
|
247
|
+
const resolvedXAxisFormat = useMemo(
|
|
248
|
+
() => xAxisFormat ?? inferXAxisFormat(timeBounds.min, timeBounds.max),
|
|
249
|
+
[xAxisFormat, timeBounds.min, timeBounds.max]
|
|
250
|
+
);
|
|
251
|
+
const hasData = dataset.length > 0;
|
|
252
|
+
const shouldShowSummary = showSummary && summaryItems && summaryItems.length > 0;
|
|
253
|
+
const headerActionElement = /* @__PURE__ */ jsxs3(Stack3, { direction: "row", spacing: 1, alignItems: "center", children: [
|
|
254
|
+
headerAction,
|
|
255
|
+
timeRangeOptions && timeRangeOptions.length > 0 && /* @__PURE__ */ jsx4(
|
|
256
|
+
TimeRangeSelect,
|
|
257
|
+
{
|
|
258
|
+
options: timeRangeOptions,
|
|
259
|
+
value: selectedTimeRange,
|
|
260
|
+
onChange: onTimeRangeChange
|
|
261
|
+
}
|
|
262
|
+
)
|
|
263
|
+
] });
|
|
264
|
+
const showHeader = !!title || !!headerAction || timeRangeOptions && timeRangeOptions.length > 0;
|
|
265
|
+
return /* @__PURE__ */ jsxs3(
|
|
266
|
+
Card,
|
|
267
|
+
{
|
|
268
|
+
"aria-label": title ? `Line chart showing ${title}` : "Line chart",
|
|
269
|
+
role: "figure",
|
|
270
|
+
children: [
|
|
271
|
+
showHeader && /* @__PURE__ */ jsx4(
|
|
272
|
+
CardHeader,
|
|
273
|
+
{
|
|
274
|
+
title,
|
|
275
|
+
titleTypographyProps: {
|
|
276
|
+
variant: "subtitle1",
|
|
277
|
+
fontWeight: 500
|
|
278
|
+
},
|
|
279
|
+
action: headerActionElement
|
|
280
|
+
}
|
|
281
|
+
),
|
|
282
|
+
/* @__PURE__ */ jsxs3(CardMedia, { children: [
|
|
283
|
+
/* @__PURE__ */ jsxs3(ChartContainer, { children: [
|
|
284
|
+
loading && /* @__PURE__ */ jsx4(LoadingOverlay, { role: "status", "aria-label": "Loading chart data", children: /* @__PURE__ */ jsx4(CircularProgress, { size: 40 }) }),
|
|
285
|
+
/* @__PURE__ */ jsx4(
|
|
286
|
+
LineChart2,
|
|
287
|
+
{
|
|
288
|
+
dataset,
|
|
289
|
+
axisHighlight: { x: "line", y: "none" },
|
|
290
|
+
grid: { horizontal: true, vertical: false },
|
|
291
|
+
margin: { top: 10, right: 20, bottom: 40, left: 50 },
|
|
292
|
+
colors: chartColors.length > 0 ? chartColors : [theme.palette.primary.main],
|
|
293
|
+
slots: {
|
|
294
|
+
noDataOverlay: () => null
|
|
295
|
+
},
|
|
296
|
+
tooltip: { trigger: hasData ? "axis" : "none" },
|
|
297
|
+
yAxis: [
|
|
298
|
+
{
|
|
299
|
+
disableLine: true,
|
|
300
|
+
disableTicks: true,
|
|
301
|
+
min: hasData ? void 0 : 0,
|
|
302
|
+
max: hasData ? void 0 : 100,
|
|
303
|
+
tickNumber: hasData ? void 0 : 5,
|
|
304
|
+
valueFormatter: (value) => formatYAxisValue(value || 0),
|
|
305
|
+
tickLabelStyle: {
|
|
306
|
+
fontSize: 10
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
xAxis: [
|
|
311
|
+
{
|
|
312
|
+
dataKey: "timestamp",
|
|
313
|
+
scaleType: "time",
|
|
314
|
+
min: timeBounds.min,
|
|
315
|
+
max: timeBounds.max,
|
|
316
|
+
disableLine: true,
|
|
317
|
+
disableTicks: true,
|
|
318
|
+
valueFormatter: (date) => format2(date, resolvedXAxisFormat),
|
|
319
|
+
tickLabelStyle: {
|
|
320
|
+
fontSize: 10
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
],
|
|
324
|
+
series: visibleSeries.map((s) => ({
|
|
325
|
+
curve: "linear",
|
|
326
|
+
dataKey: s.name,
|
|
327
|
+
label: s.name,
|
|
328
|
+
showMark: false,
|
|
329
|
+
connectNulls: false
|
|
330
|
+
})),
|
|
331
|
+
slotProps: {
|
|
332
|
+
legend: { hidden: true }
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
] }),
|
|
337
|
+
series.length > 0 && /* @__PURE__ */ jsx4(
|
|
338
|
+
Stack3,
|
|
339
|
+
{
|
|
340
|
+
direction: "row",
|
|
341
|
+
spacing: 2,
|
|
342
|
+
justifyContent: "center",
|
|
343
|
+
paddingY: 1,
|
|
344
|
+
flexWrap: "wrap",
|
|
345
|
+
useFlexGap: true,
|
|
346
|
+
role: "list",
|
|
347
|
+
"aria-label": "Chart legend",
|
|
348
|
+
children: series.map((s) => {
|
|
349
|
+
const isHidden = hiddenSeries.has(s.name);
|
|
350
|
+
return /* @__PURE__ */ jsxs3(
|
|
351
|
+
Stack3,
|
|
352
|
+
{
|
|
353
|
+
direction: "row",
|
|
354
|
+
spacing: 1,
|
|
355
|
+
alignItems: "center",
|
|
356
|
+
role: "listitem",
|
|
357
|
+
onClick: () => handleLegendToggle(s.name),
|
|
358
|
+
sx: {
|
|
359
|
+
cursor: "pointer",
|
|
360
|
+
opacity: isHidden ? 0.4 : 1,
|
|
361
|
+
transition: "opacity 0.2s ease",
|
|
362
|
+
userSelect: "none"
|
|
363
|
+
},
|
|
364
|
+
"aria-pressed": !isHidden,
|
|
365
|
+
"aria-label": `Toggle ${s.name} visibility`,
|
|
366
|
+
children: [
|
|
367
|
+
/* @__PURE__ */ jsx4(LegendDot, { dotColor: s.color }),
|
|
368
|
+
/* @__PURE__ */ jsx4(Typography3, { variant: "body2", children: s.name })
|
|
369
|
+
]
|
|
370
|
+
},
|
|
371
|
+
s.name
|
|
372
|
+
);
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
)
|
|
376
|
+
] }),
|
|
377
|
+
shouldShowSummary && /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
378
|
+
/* @__PURE__ */ jsx4(Divider, {}),
|
|
379
|
+
/* @__PURE__ */ jsx4(SummaryStats, { items: summaryItems })
|
|
380
|
+
] })
|
|
381
|
+
]
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
export {
|
|
387
|
+
ChartWidget,
|
|
388
|
+
TimeRangeSelect,
|
|
389
|
+
SummaryStats,
|
|
390
|
+
TimeSeriesGraph
|
|
391
|
+
};
|
|
392
|
+
//# sourceMappingURL=chunk-BT7XUTT5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/charts/ChartWidget/ChartWidget.tsx","../src/components/charts/TimeSeriesGraph/TimeSeriesGraph.tsx","../src/components/charts/TimeSeriesGraph/TimeRangeSelect.tsx","../src/components/charts/TimeSeriesGraph/SummaryStats.tsx"],"sourcesContent":["import { ReactNode } from 'react';\nimport Box from '@mui/material/Box';\nimport Stack from '@mui/material/Stack';\nimport Typography from '@mui/material/Typography';\nimport { styled, useTheme } from '@mui/material/styles';\nimport { LineChart } from '@mui/x-charts';\nimport size from 'byte-size';\nimport { format } from 'date-fns';\n\ntype ChartWidgetHistoryRecord = {\n date: Date;\n value: number;\n};\n\nexport type ChartWidgetProps = {\n title: string;\n value?: ReactNode;\n history?: ChartWidgetHistoryRecord[];\n formatValue?: (value: number) => string;\n};\n\nconst Chart = styled(Box)(() => ({\n height: 200,\n}));\n\nexport const ChartWidget = ({\n title,\n value,\n history,\n formatValue = (value) => size(value || 0).toString(),\n}: ChartWidgetProps) => {\n const theme = useTheme();\n\n return (\n <Stack spacing={1}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {title}\n </Typography>\n <Typography fontWeight=\"bold\">{value}</Typography>\n\n <Chart>\n <LineChart\n dataset={history || []}\n axisHighlight={{ x: 'none', y: 'none' }}\n grid={{ horizontal: true, vertical: false }}\n margin={{ top: 10, right: 20, bottom: 40, left: 40 }}\n colors={[theme.palette.primary.main]}\n slots={{\n noDataOverlay: () => null,\n }}\n yAxis={[\n {\n dataKey: 'value',\n disableLine: true,\n disableTicks: true,\n min: history?.length ? undefined : 0,\n max: history?.length ? undefined : 100,\n tickNumber: history?.length ? undefined : 5,\n valueFormatter: (value) => formatValue(value || 0),\n tickLabelStyle: {\n fontSize: 10,\n },\n },\n ]}\n xAxis={[\n {\n dataKey: 'date',\n min: history && Math.min(...history.map((record) => +record.date)),\n max: history && Math.max(...history.map((record) => +record.date)),\n disableLine: true,\n disableTicks: true,\n valueFormatter: (date) => format(date, 'do MMM'),\n tickPlacement: 'end',\n tickNumber: 1,\n\n tickLabelStyle: {\n fontSize: 10,\n transform: 'translate(-16px, 16px) rotate(-30deg)',\n },\n },\n ]}\n series={[\n {\n curve: 'linear',\n dataKey: 'value',\n showMark: false,\n valueFormatter: (value) => formatValue(value || 0),\n },\n ]}\n />\n </Chart>\n </Stack>\n );\n};\n","import { ReactNode, useCallback, useMemo, useState } from 'react';\nimport Box from '@mui/material/Box';\nimport Card from '@mui/material/Card';\nimport CardHeader from '@mui/material/CardHeader';\nimport CardMedia from '@mui/material/CardMedia';\nimport CircularProgress from '@mui/material/CircularProgress';\nimport Divider from '@mui/material/Divider';\nimport Stack from '@mui/material/Stack';\nimport Typography from '@mui/material/Typography';\nimport { styled, useTheme } from '@mui/material/styles';\nimport { LineChart } from '@mui/x-charts';\nimport { format } from 'date-fns';\n\nimport { TimeRangeSelect, type TimeRangeOption } from './TimeRangeSelect';\nimport { SummaryStats, type SummaryItem } from './SummaryStats';\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\n/**\n * A single data point in a time series.\n * Use `null` for the value to represent missing/gap data — the line will break.\n */\nexport interface DataPoint {\n /** Timestamp of the observation */\n timestamp: Date;\n /** Numeric value, or `null` to indicate a gap in the data */\n value: number | null;\n}\n\n/**\n * Represents one line on the graph (a named data series).\n */\nexport interface DataSeries {\n /** Unique display name for this series (shown in legend) */\n name: string;\n /** CSS color string for the line and legend indicator */\n color: string;\n /** Ordered array of data points */\n data: DataPoint[];\n}\n\nexport interface TimeSeriesGraphProps {\n /** Optional title displayed at the top-left of the graph card */\n title?: string;\n /**\n * Array of data series to render. Each series becomes one line on the graph.\n * There is no hardcoded limit on the number of series.\n */\n series: DataSeries[];\n /**\n * Configurable time range options for the dropdown selector.\n * When omitted, the time range dropdown is not rendered.\n */\n timeRangeOptions?: TimeRangeOption[];\n /** Currently selected time range value (controlled) */\n selectedTimeRange?: string;\n /** Callback invoked when the user picks a different time range */\n onTimeRangeChange?: (value: string) => void;\n /**\n * Optional array of summary statistics displayed below the graph.\n * When omitted or empty, the summary section is hidden.\n */\n summaryItems?: SummaryItem[];\n /**\n * Whether to show the summary statistics section.\n * Defaults to `true`. Set to `false` to explicitly hide, even when `summaryItems` are provided.\n */\n showSummary?: boolean;\n /**\n * Optional header action element rendered to the right of the title\n * (e.g., a secondary dropdown or filter control).\n */\n headerAction?: ReactNode;\n /**\n * When `true`, shows a loading overlay (spinner) over the graph area\n * while the header remains visible and interactive.\n */\n loading?: boolean;\n /**\n * Override the x-axis date format string (date-fns format tokens).\n * When omitted, the format is auto-detected from the data's time span:\n * - <= 24 hours → `'HH:mm'`\n * - > 24 hours → `'do MMM'`\n */\n xAxisFormat?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Styled helpers\n// ---------------------------------------------------------------------------\n\nconst ChartContainer = styled(Box)({\n position: 'relative',\n height: 320,\n});\n\nconst LoadingOverlay = styled(Box)(({ theme }) => ({\n position: 'absolute',\n inset: 0,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundColor: 'rgba(255, 255, 255, 0.7)',\n zIndex: 1,\n borderRadius: theme.shape.borderRadius,\n}));\n\nconst LegendDot = styled(Box, {\n shouldForwardProp: (prop) => prop !== 'dotColor',\n})<{ dotColor: string }>(({ dotColor }) => ({\n width: 14,\n height: 14,\n borderRadius: 4,\n backgroundColor: dotColor,\n flexShrink: 0,\n}));\n\n// ---------------------------------------------------------------------------\n// Utility functions\n// ---------------------------------------------------------------------------\n\n/**\n * Formats large Y-axis values into shorthand notation.\n * 1,000 → 1K, 1,000,000 → 1M, 1,000,000,000 → 1B\n */\nconst formatYAxisValue = (value: number): string => {\n const absValue = Math.abs(value);\n if (absValue >= 1_000_000_000) {\n return `${(value / 1_000_000_000).toFixed(absValue % 1_000_000_000 === 0 ? 0 : 1)}B`;\n }\n if (absValue >= 1_000_000) {\n return `${(value / 1_000_000).toFixed(absValue % 1_000_000 === 0 ? 0 : 1)}M`;\n }\n if (absValue >= 1_000) {\n return `${(value / 1_000).toFixed(absValue % 1_000 === 0 ? 0 : 1)}K`;\n }\n return String(value);\n};\n\nconst TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1000;\n\n/**\n * Infers the appropriate x-axis date format string based on the time span of the data.\n * - Span <= 24 hours → `'HH:mm'` (e.g., \"14:30\")\n * - Span > 24 hours → `'do MMM'` (e.g., \"2nd Jan\")\n */\nexport const inferXAxisFormat = (\n min: Date | undefined,\n max: Date | undefined,\n): string => {\n if (!min || !max) return 'do MMM';\n const spanMs = max.getTime() - min.getTime();\n return spanMs <= TWENTY_FOUR_HOURS_MS ? 'HH:mm' : 'do MMM';\n};\n\n/** A single row in the chart dataset — timestamp plus one field per series. */\ntype DatasetRow = Record<string, string | number | Date | null | undefined>;\n\n/**\n * Builds the unified dataset array that MUI X-Charts expects.\n * Each row is keyed by timestamp with one field per series.\n */\nconst buildDataset = (\n series: DataSeries[],\n hiddenSeries: Set<string>,\n): DatasetRow[] => {\n // Collect all unique timestamps across all visible series\n const timestampMap = new Map<number, DatasetRow>();\n\n series.forEach((s) => {\n if (hiddenSeries.has(s.name)) return;\n s.data.forEach((dp) => {\n const ts = dp.timestamp.getTime();\n if (!timestampMap.has(ts)) {\n timestampMap.set(ts, { timestamp: dp.timestamp } as DatasetRow);\n }\n timestampMap.get(ts)![s.name] = dp.value;\n });\n });\n\n // Sort by timestamp ascending\n return Array.from(timestampMap.values()).sort(\n (a, b) => (a.timestamp as Date).getTime() - (b.timestamp as Date).getTime(),\n );\n};\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n/**\n * A reusable time series graph component that displays one or more data lines\n * over a shared time axis. Supports configurable time range selection,\n * optional summary statistics, interactive legend toggling, crosshair tooltips,\n * and a loading state.\n *\n * Built on `@mui/x-charts` LineChart and the Cere Design System theme.\n *\n * @example\n * ```tsx\n * <TimeSeriesGraph\n * title=\"Engagement over time\"\n * series={[\n * { name: 'Engagements', color: '#6750A4', data: engagementData },\n * { name: 'Unique Streams', color: '#4caf50', data: streamData },\n * ]}\n * timeRangeOptions={[\n * { label: 'Last hour', value: 'hour' },\n * { label: '24 hours', value: 'day' },\n * { label: '1 week', value: 'week' },\n * { label: '1 month', value: 'month' },\n * ]}\n * selectedTimeRange=\"week\"\n * onTimeRangeChange={(range) => fetchData(range)}\n * summaryItems={[\n * { label: 'Total Engagements', value: 11372 },\n * { label: 'Daily Engagements', value: 156 },\n * ]}\n * />\n * ```\n *\n * Figma reference: [ROB Design - Node 162:1172](https://www.figma.com/design/xky11VbkkFcgZLwZE8BdCN/ROB?node-id=162-1172&m=dev)\n */\nexport const TimeSeriesGraph = ({\n title,\n series,\n timeRangeOptions,\n selectedTimeRange,\n onTimeRangeChange,\n summaryItems,\n showSummary = true,\n headerAction,\n loading = false,\n xAxisFormat,\n}: TimeSeriesGraphProps) => {\n const theme = useTheme();\n const [hiddenSeries, setHiddenSeries] = useState<Set<string>>(new Set());\n\n // Build the MUI X-Charts dataset from visible series\n const dataset = useMemo(() => buildDataset(series, hiddenSeries), [series, hiddenSeries]);\n\n // Visible series (exclude hidden)\n const visibleSeries = useMemo(\n () => series.filter((s) => !hiddenSeries.has(s.name)),\n [series, hiddenSeries],\n );\n\n // Colors array matching the order of visible series\n const chartColors = useMemo(() => visibleSeries.map((s) => s.color), [visibleSeries]);\n\n // Toggle a series' visibility\n const handleLegendToggle = useCallback((seriesName: string) => {\n setHiddenSeries((prev) => {\n const next = new Set(prev);\n if (next.has(seriesName)) {\n next.delete(seriesName);\n } else {\n next.add(seriesName);\n }\n return next;\n });\n }, []);\n\n // Compute time bounds for the X-axis from visible data\n const timeBounds = useMemo(() => {\n if (dataset.length === 0) return { min: undefined, max: undefined };\n const timestamps = dataset.map((row) => (row.timestamp as Date).getTime());\n return {\n min: new Date(Math.min(...timestamps)),\n max: new Date(Math.max(...timestamps)),\n };\n }, [dataset]);\n\n // Resolve the x-axis date format: explicit prop wins, otherwise auto-detect\n const resolvedXAxisFormat = useMemo(\n () => xAxisFormat ?? inferXAxisFormat(timeBounds.min, timeBounds.max),\n [xAxisFormat, timeBounds.min, timeBounds.max],\n );\n\n // Determine whether we have data to display\n const hasData = dataset.length > 0;\n\n // Whether to render the summary section\n const shouldShowSummary = showSummary && summaryItems && summaryItems.length > 0;\n\n // Build the header action area (time range + optional custom action)\n const headerActionElement = (\n <Stack direction=\"row\" spacing={1} alignItems=\"center\">\n {headerAction}\n {timeRangeOptions && timeRangeOptions.length > 0 && (\n <TimeRangeSelect\n options={timeRangeOptions}\n value={selectedTimeRange}\n onChange={onTimeRangeChange}\n />\n )}\n </Stack>\n );\n\n // Determine whether to show the header at all\n const showHeader = !!title || !!headerAction || (timeRangeOptions && timeRangeOptions.length > 0);\n\n return (\n <Card\n aria-label={title ? `Line chart showing ${title}` : 'Line chart'}\n role=\"figure\"\n >\n {showHeader && (\n <CardHeader\n title={title}\n titleTypographyProps={{\n variant: 'subtitle1',\n fontWeight: 500,\n }}\n action={headerActionElement}\n />\n )}\n\n <CardMedia>\n <ChartContainer>\n {loading && (\n <LoadingOverlay role=\"status\" aria-label=\"Loading chart data\">\n <CircularProgress size={40} />\n </LoadingOverlay>\n )}\n\n <LineChart\n dataset={dataset}\n axisHighlight={{ x: 'line', y: 'none' }}\n grid={{ horizontal: true, vertical: false }}\n margin={{ top: 10, right: 20, bottom: 40, left: 50 }}\n colors={chartColors.length > 0 ? chartColors : [theme.palette.primary.main]}\n slots={{\n noDataOverlay: () => null,\n }}\n tooltip={{ trigger: hasData ? 'axis' : 'none' }}\n yAxis={[\n {\n disableLine: true,\n disableTicks: true,\n min: hasData ? undefined : 0,\n max: hasData ? undefined : 100,\n tickNumber: hasData ? undefined : 5,\n valueFormatter: (value: number) => formatYAxisValue(value || 0),\n tickLabelStyle: {\n fontSize: 10,\n },\n },\n ]}\n xAxis={[\n {\n dataKey: 'timestamp',\n scaleType: 'time',\n min: timeBounds.min,\n max: timeBounds.max,\n disableLine: true,\n disableTicks: true,\n valueFormatter: (date: Date) => format(date, resolvedXAxisFormat),\n tickLabelStyle: {\n fontSize: 10,\n },\n },\n ]}\n series={visibleSeries.map((s) => ({\n curve: 'linear' as const,\n dataKey: s.name,\n label: s.name,\n showMark: false,\n connectNulls: false,\n }))}\n // Hide the built-in legend — we render a custom one below\n slotProps={{\n legend: { hidden: true },\n }}\n />\n </ChartContainer>\n\n {/* Custom interactive legend */}\n {series.length > 0 && (\n <Stack\n direction=\"row\"\n spacing={2}\n justifyContent=\"center\"\n paddingY={1}\n flexWrap=\"wrap\"\n useFlexGap\n role=\"list\"\n aria-label=\"Chart legend\"\n >\n {series.map((s) => {\n const isHidden = hiddenSeries.has(s.name);\n return (\n <Stack\n key={s.name}\n direction=\"row\"\n spacing={1}\n alignItems=\"center\"\n role=\"listitem\"\n onClick={() => handleLegendToggle(s.name)}\n sx={{\n cursor: 'pointer',\n opacity: isHidden ? 0.4 : 1,\n transition: 'opacity 0.2s ease',\n userSelect: 'none',\n }}\n aria-pressed={!isHidden}\n aria-label={`Toggle ${s.name} visibility`}\n >\n <LegendDot dotColor={s.color} />\n <Typography variant=\"body2\">{s.name}</Typography>\n </Stack>\n );\n })}\n </Stack>\n )}\n </CardMedia>\n\n {/* Summary statistics */}\n {shouldShowSummary && (\n <>\n <Divider />\n <SummaryStats items={summaryItems!} />\n </>\n )}\n </Card>\n );\n};\n","import MenuItem from '@mui/material/MenuItem';\nimport TextField from '@mui/material/TextField';\n\n/**\n * Represents a single time range option in the dropdown.\n */\nexport interface TimeRangeOption {\n /** Display label shown in the dropdown (e.g., \"1 week\") */\n label: string;\n /** Value identifier passed to the callback on selection */\n value: string;\n}\n\nexport interface TimeRangeSelectProps {\n /** Available time range options */\n options: TimeRangeOption[];\n /** Currently selected time range value */\n value?: string;\n /** Callback invoked when user selects a different time range */\n onChange?: (value: string) => void;\n}\n\n/**\n * Configurable time range dropdown selector.\n * Renders a compact select field with the provided time range options.\n *\n * @example\n * ```tsx\n * <TimeRangeSelect\n * options={[\n * { label: 'Last hour', value: 'hour' },\n * { label: '24 hours', value: 'day' },\n * { label: '1 week', value: 'week' },\n * ]}\n * value=\"week\"\n * onChange={(value) => console.log(value)}\n * />\n * ```\n */\nexport const TimeRangeSelect = ({ options, value, onChange }: TimeRangeSelectProps) => (\n <TextField\n select\n size=\"small\"\n value={value ?? (options.length > 0 ? options[0].value : '')}\n onChange={(e) => onChange?.(e.target.value)}\n aria-label=\"Time range selector\"\n sx={{ minWidth: 120 }}\n >\n {options.map((option) => (\n <MenuItem key={option.value} value={option.value}>\n {option.label}\n </MenuItem>\n ))}\n </TextField>\n);\n","import Stack from '@mui/material/Stack';\nimport Typography from '@mui/material/Typography';\n\n/**\n * Represents a single summary statistic item displayed below the graph.\n */\nexport interface SummaryItem {\n /** Descriptive label (e.g., \"Total Engagements\") */\n label: string;\n /** Numeric or string value (e.g., \"13.72\" or 11372) */\n value: string | number;\n /** Optional unit suffix (e.g., \"K\", \"GB\", \"%\") */\n unit?: string;\n}\n\nexport interface SummaryStatsProps {\n /** Array of summary items to display */\n items: SummaryItem[];\n}\n\n/**\n * Formats a summary value with its optional unit.\n */\nconst formatSummaryValue = (value: string | number, unit?: string): string => {\n const displayValue = typeof value === 'number' ? value.toLocaleString() : value;\n return unit ? `${displayValue} ${unit}` : displayValue;\n};\n\n/**\n * Renders a horizontal row of summary statistics below the graph.\n * Each item shows a label with its corresponding value and optional unit.\n *\n * Matches the Figma design layout with label in secondary text color\n * and value in bold heading typography.\n *\n * @example\n * ```tsx\n * <SummaryStats\n * items={[\n * { label: 'Total Engagements', value: 11372 },\n * { label: 'Total Consumed', value: '156.91', unit: 'GB' },\n * ]}\n * />\n * ```\n */\nexport const SummaryStats = ({ items }: SummaryStatsProps) => {\n if (items.length === 0) {\n return null;\n }\n\n return (\n <Stack\n direction=\"row\"\n spacing={3}\n padding={2}\n flexWrap=\"wrap\"\n useFlexGap\n role=\"list\"\n aria-label=\"Summary statistics\"\n >\n {items.map((item) => (\n <Stack\n key={item.label}\n direction=\"row\"\n alignItems=\"center\"\n spacing={1}\n role=\"listitem\"\n >\n <Typography variant=\"body2\" color=\"text.secondary\">\n {item.label}\n </Typography>\n <Typography variant=\"h5\" fontWeight={600}>\n {formatSummaryValue(item.value, item.unit)}\n </Typography>\n </Stack>\n ))}\n </Stack>\n );\n};\n"],"mappings":";AACA,OAAO,SAAS;AAChB,OAAO,WAAW;AAClB,OAAO,gBAAgB;AACvB,SAAS,QAAQ,gBAAgB;AACjC,SAAS,iBAAiB;AAC1B,OAAO,UAAU;AACjB,SAAS,cAAc;AA2BnB,SACE,KADF;AAbJ,IAAM,QAAQ,OAAO,GAAG,EAAE,OAAO;AAAA,EAC/B,QAAQ;AACV,EAAE;AAEK,IAAM,cAAc,CAAC;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc,CAACA,WAAU,KAAKA,UAAS,CAAC,EAAE,SAAS;AACrD,MAAwB;AACtB,QAAM,QAAQ,SAAS;AAEvB,SACE,qBAAC,SAAM,SAAS,GACd;AAAA,wBAAC,cAAW,SAAQ,WAAU,OAAM,kBACjC,iBACH;AAAA,IACA,oBAAC,cAAW,YAAW,QAAQ,iBAAM;AAAA,IAErC,oBAAC,SACC;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,WAAW,CAAC;AAAA,QACrB,eAAe,EAAE,GAAG,QAAQ,GAAG,OAAO;AAAA,QACtC,MAAM,EAAE,YAAY,MAAM,UAAU,MAAM;AAAA,QAC1C,QAAQ,EAAE,KAAK,IAAI,OAAO,IAAI,QAAQ,IAAI,MAAM,GAAG;AAAA,QACnD,QAAQ,CAAC,MAAM,QAAQ,QAAQ,IAAI;AAAA,QACnC,OAAO;AAAA,UACL,eAAe,MAAM;AAAA,QACvB;AAAA,QACA,OAAO;AAAA,UACL;AAAA,YACE,SAAS;AAAA,YACT,aAAa;AAAA,YACb,cAAc;AAAA,Y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AC,WAAQ;AAAA,UACT,gBAAAA,KAAC,gBAAa,OAAO,cAAe;AAAA,WACtC;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":["value","Box","Stack","Typography","styled","useTheme","LineChart","format","jsx","Stack","Typography","jsx","jsxs","jsx","jsxs","styled","Box","useTheme","Stack","LineChart","format","Typography"]}
|