@10x-media/analytics 0.1.0-beta.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/CHANGELOG.md +41 -0
- package/LICENSE +21 -0
- package/README.md +387 -0
- package/dist/RealtimeCounter-BJrjMPSa.js +473 -0
- package/dist/RealtimeCounter-BJrjMPSa.js.map +1 -0
- package/dist/contract-CWZPKWuR.d.ts +83 -0
- package/dist/dist-B6HruP5v.js +4731 -0
- package/dist/dist-B6HruP5v.js.map +1 -0
- package/dist/exports/adapters/ga4.d.ts +20 -0
- package/dist/exports/adapters/ga4.js +177 -0
- package/dist/exports/adapters/ga4.js.map +1 -0
- package/dist/exports/adapters/native.d.ts +22 -0
- package/dist/exports/adapters/native.js +849 -0
- package/dist/exports/adapters/native.js.map +1 -0
- package/dist/exports/adapters/plausible.d.ts +15 -0
- package/dist/exports/adapters/plausible.js +143 -0
- package/dist/exports/adapters/plausible.js.map +1 -0
- package/dist/exports/adapters/posthog.d.ts +17 -0
- package/dist/exports/adapters/posthog.js +119 -0
- package/dist/exports/adapters/posthog.js.map +1 -0
- package/dist/exports/adapters/umami.d.ts +18 -0
- package/dist/exports/adapters/umami.js +139 -0
- package/dist/exports/adapters/umami.js.map +1 -0
- package/dist/exports/client.d.ts +77 -0
- package/dist/exports/client.js +388 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/geo.d.ts +19 -0
- package/dist/exports/geo.js +2 -0
- package/dist/exports/i18n.d.ts +63 -0
- package/dist/exports/i18n.js +3 -0
- package/dist/exports/rsc.d.ts +120 -0
- package/dist/exports/rsc.js +598 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/types.d.ts +4 -0
- package/dist/exports/types.js +1 -0
- package/dist/fetchJson-DZb2_Puj.js +36 -0
- package/dist/fetchJson-DZb2_Puj.js.map +1 -0
- package/dist/geoResolver-CasIa4T9.d.ts +12 -0
- package/dist/index-CZdCT0WJ.d.ts +98 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1081 -0
- package/dist/index.js.map +1 -0
- package/dist/keys-DEqL4LOT.js +57 -0
- package/dist/keys-DEqL4LOT.js.map +1 -0
- package/dist/lib-CE5x1zLQ.js +1058 -0
- package/dist/lib-CE5x1zLQ.js.map +1 -0
- package/dist/maxmindResolver-CXYXXdul.js +99 -0
- package/dist/maxmindResolver-CXYXXdul.js.map +1 -0
- package/dist/presets-CBfq_uJX.d.ts +38 -0
- package/dist/readForWidgetRealtime-D1BD37ST.d.ts +32 -0
- package/dist/series-zytbzPoc.js +17 -0
- package/dist/series-zytbzPoc.js.map +1 -0
- package/dist/server-Cuvhgz-S.js +492 -0
- package/dist/server-Cuvhgz-S.js.map +1 -0
- package/dist/testing/memoryAdapter.d.ts +16 -0
- package/dist/testing/memoryAdapter.js +98 -0
- package/dist/testing/memoryAdapter.js.map +1 -0
- package/dist/translations-keiKtSjF.js +77 -0
- package/dist/translations-keiKtSjF.js.map +1 -0
- package/package.json +156 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region src/charts/bars.ts
|
|
4
|
+
/**
|
|
5
|
+
* Scale each datum's value to a `[0, 1]` fraction of the largest value, for a ranked
|
|
6
|
+
* bar list. A degenerate all-zero set yields zero fractions (no bar), never a divide
|
|
7
|
+
* by zero.
|
|
8
|
+
*/
|
|
9
|
+
const toBarRows = (data) => {
|
|
10
|
+
const max = data.reduce((m, d) => Math.max(m, d.value), 0);
|
|
11
|
+
return data.map((d) => ({
|
|
12
|
+
label: d.label,
|
|
13
|
+
value: d.value,
|
|
14
|
+
fraction: max > 0 ? d.value / max : 0,
|
|
15
|
+
display: d.display
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/charts/styles.tsx
|
|
20
|
+
const CHART_CSS = `
|
|
21
|
+
:where(:root) {
|
|
22
|
+
--analytics-chart-1: var(--theme-success-500, #3b82f6);
|
|
23
|
+
}
|
|
24
|
+
.analytics-chart { position: relative; width: 100%; }
|
|
25
|
+
.analytics-chart__svg { display: block; width: 100%; height: 100%; overflow: visible; }
|
|
26
|
+
.analytics-chart__grid { stroke: var(--theme-elevation-150); stroke-width: 1; vector-effect: non-scaling-stroke; }
|
|
27
|
+
.analytics-chart__area { stroke: none; }
|
|
28
|
+
.analytics-chart__line { fill: none; stroke: var(--analytics-chart-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
|
|
29
|
+
.analytics-chart__dot { fill: var(--theme-elevation-0); stroke: var(--analytics-chart-1); stroke-width: 2; }
|
|
30
|
+
.analytics-chart__axis { fill: var(--theme-elevation-450); font-size: 0.6875rem; }
|
|
31
|
+
.analytics-chart__cursor { stroke: var(--theme-elevation-300); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
|
|
32
|
+
.analytics-chart__active { fill: var(--analytics-chart-1); stroke: var(--theme-elevation-0); stroke-width: 2; }
|
|
33
|
+
.analytics-chart__tooltip { position: absolute; pointer-events: none; transform: translate(-50%, -120%); background: var(--theme-elevation-0); border: 1px solid var(--theme-elevation-150); border-radius: var(--style-radius-m, 6px); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18); padding: 0.4rem 0.6rem; font-size: 0.75rem; white-space: nowrap; z-index: 10; animation: analytics-fade 0.12s ease-out; }
|
|
34
|
+
.analytics-chart__tooltip-label { color: var(--theme-elevation-500); font-weight: 600; margin-bottom: 0.15rem; }
|
|
35
|
+
.analytics-chart__tooltip-value { color: var(--theme-elevation-800); font-weight: 700; font-variant-numeric: tabular-nums; }
|
|
36
|
+
@keyframes analytics-fade { from { opacity: 0; } to { opacity: 1; } }
|
|
37
|
+
.analytics-bars { display: flex; flex-direction: column; gap: 0.35rem; }
|
|
38
|
+
.analytics-bars__row { position: relative; display: flex; align-items: center; gap: 0.6rem; }
|
|
39
|
+
.analytics-bars__track { position: relative; flex: 1; min-width: 0; height: 1.85rem; border-radius: var(--style-radius-s, 4px); overflow: hidden; }
|
|
40
|
+
.analytics-bars__fill { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: color-mix(in srgb, var(--analytics-chart-1) 90%, transparent); transition: filter 0.1s ease; }
|
|
41
|
+
.analytics-bars__row:hover .analytics-bars__fill { filter: brightness(1.12); }
|
|
42
|
+
.analytics-bars__label { position: relative; padding: 0 0.6rem; color: var(--theme-base-800, #fff); font-size: 0.8125rem; line-height: 1.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
43
|
+
.analytics-bars__value { flex: none; font-size: 0.8125rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--theme-elevation-800); }
|
|
44
|
+
.analytics-bars__empty { color: var(--theme-elevation-400); font-size: 0.8125rem; }
|
|
45
|
+
`;
|
|
46
|
+
/**
|
|
47
|
+
* Single scoped stylesheet for all analytics charts, injected as a `<style>` element so
|
|
48
|
+
* it ships as a JS string (our tsdown build has no CSS pipeline) and behaves identically
|
|
49
|
+
* in dev and when installed from npm. The `--analytics-chart-*` tokens live in `:root`
|
|
50
|
+
* scope so a consuming app can override them.
|
|
51
|
+
*/
|
|
52
|
+
function ChartStyles() {
|
|
53
|
+
return /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: CHART_CSS } });
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/charts/BarList.tsx
|
|
57
|
+
/**
|
|
58
|
+
* Ranked horizontal bar list (shadcn "custom label" style): each row is a filled,
|
|
59
|
+
* proportional bar with the label inside and the value outside; hovering a row lifts
|
|
60
|
+
* it and shows a tooltip with the full label and value (useful when the label is
|
|
61
|
+
* truncated). Dependency-free; styling comes from the shared chart stylesheet.
|
|
62
|
+
*/
|
|
63
|
+
function BarList({ data, emptyLabel }) {
|
|
64
|
+
const rows = toBarRows(data);
|
|
65
|
+
const [hover, setHover] = useState(null);
|
|
66
|
+
if (rows.length === 0) return /* @__PURE__ */ jsx("span", {
|
|
67
|
+
className: "analytics-bars__empty",
|
|
68
|
+
children: emptyLabel
|
|
69
|
+
});
|
|
70
|
+
const track = (i) => (e) => setHover({
|
|
71
|
+
i,
|
|
72
|
+
x: e.clientX,
|
|
73
|
+
y: e.clientY
|
|
74
|
+
});
|
|
75
|
+
const hovered = hover ? rows[hover.i] : void 0;
|
|
76
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
77
|
+
className: "analytics-chart",
|
|
78
|
+
children: [
|
|
79
|
+
/* @__PURE__ */ jsx(ChartStyles, {}),
|
|
80
|
+
/* @__PURE__ */ jsx("div", {
|
|
81
|
+
className: "analytics-bars",
|
|
82
|
+
children: rows.map((row, i) => /* @__PURE__ */ jsxs("div", {
|
|
83
|
+
className: "analytics-bars__row",
|
|
84
|
+
onPointerEnter: track(i),
|
|
85
|
+
onPointerMove: track(i),
|
|
86
|
+
onPointerLeave: () => setHover(null),
|
|
87
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
88
|
+
className: "analytics-bars__track",
|
|
89
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
90
|
+
className: "analytics-bars__fill",
|
|
91
|
+
style: { width: `${row.fraction * 100}%` }
|
|
92
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
93
|
+
className: "analytics-bars__label",
|
|
94
|
+
children: row.label
|
|
95
|
+
})]
|
|
96
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
97
|
+
className: "analytics-bars__value",
|
|
98
|
+
children: row.display ?? row.value
|
|
99
|
+
})]
|
|
100
|
+
}, row.label))
|
|
101
|
+
}),
|
|
102
|
+
hover && hovered ? /* @__PURE__ */ jsxs("div", {
|
|
103
|
+
className: "analytics-chart__tooltip",
|
|
104
|
+
style: {
|
|
105
|
+
position: "fixed",
|
|
106
|
+
left: hover.x,
|
|
107
|
+
top: hover.y
|
|
108
|
+
},
|
|
109
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
110
|
+
className: "analytics-chart__tooltip-label",
|
|
111
|
+
children: hovered.label
|
|
112
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
113
|
+
className: "analytics-chart__tooltip-value",
|
|
114
|
+
children: hovered.display ?? hovered.value
|
|
115
|
+
})]
|
|
116
|
+
}) : null
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/charts/spline.ts
|
|
122
|
+
const round = (n) => Math.round(n * 100) / 100;
|
|
123
|
+
/**
|
|
124
|
+
* Fritsch-Carlson monotone tangents for a unit-spaced series: endpoints take the
|
|
125
|
+
* adjacent secant, interior points the average of neighbouring secants, then each is
|
|
126
|
+
* clamped so the cubic never overshoots (no wiggle between points).
|
|
127
|
+
*/
|
|
128
|
+
const computeTangents = (ys) => {
|
|
129
|
+
const n = ys.length;
|
|
130
|
+
if (n < 2) return ys.map(() => 0);
|
|
131
|
+
const d = ys.slice(0, -1).map((y, i) => (ys[i + 1] ?? 0) - y);
|
|
132
|
+
const m = ys.map((_, i) => {
|
|
133
|
+
if (i === 0) return d[0] ?? 0;
|
|
134
|
+
if (i === n - 1) return d[n - 2] ?? 0;
|
|
135
|
+
return ((d[i - 1] ?? 0) + (d[i] ?? 0)) / 2;
|
|
136
|
+
});
|
|
137
|
+
for (let i = 0; i < n - 1; i++) {
|
|
138
|
+
const di = d[i] ?? 0;
|
|
139
|
+
if (di === 0) {
|
|
140
|
+
m[i] = 0;
|
|
141
|
+
m[i + 1] = 0;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const mi = m[i] ?? 0;
|
|
145
|
+
const mi1 = m[i + 1] ?? 0;
|
|
146
|
+
const a = mi / di;
|
|
147
|
+
const b = mi1 / di;
|
|
148
|
+
const s = a * a + b * b;
|
|
149
|
+
if (s > 9) {
|
|
150
|
+
const t = 3 / Math.sqrt(s);
|
|
151
|
+
m[i] = t * a * di;
|
|
152
|
+
m[i + 1] = t * b * di;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return m;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Build SVG path strings for a monotone-cubic line and its closed area fill, mapping a
|
|
159
|
+
* value series into a `width` x `height` box (y normalized to the value range; flat or
|
|
160
|
+
* single-value series sit on the vertical midline).
|
|
161
|
+
*/
|
|
162
|
+
const monotoneAreaPath = (values, opts) => {
|
|
163
|
+
const { width, height } = opts;
|
|
164
|
+
const padding = opts.padding ?? 0;
|
|
165
|
+
if (values.length === 0) return {
|
|
166
|
+
line: "",
|
|
167
|
+
area: ""
|
|
168
|
+
};
|
|
169
|
+
const innerH = height - padding * 2;
|
|
170
|
+
const max = Math.max(...values);
|
|
171
|
+
const min = Math.min(...values);
|
|
172
|
+
const span = max - min || 1;
|
|
173
|
+
const x = (i) => round(values.length > 1 ? i / (values.length - 1) * width : 0);
|
|
174
|
+
const y = (v) => round(max === min ? height / 2 : padding + innerH - (v - min) / span * innerH);
|
|
175
|
+
const v0 = values[0] ?? 0;
|
|
176
|
+
if (values.length === 1) return {
|
|
177
|
+
line: `M0,${y(v0)} L${round(width)},${y(v0)}`,
|
|
178
|
+
area: ""
|
|
179
|
+
};
|
|
180
|
+
const tangents = computeTangents(values);
|
|
181
|
+
let line = `M${x(0)},${y(v0)}`;
|
|
182
|
+
for (let i = 0; i < values.length - 1; i++) {
|
|
183
|
+
const x0 = i;
|
|
184
|
+
const x1 = i + 1;
|
|
185
|
+
const vi = values[i] ?? 0;
|
|
186
|
+
const vi1 = values[i + 1] ?? 0;
|
|
187
|
+
const ti = tangents[i] ?? 0;
|
|
188
|
+
const ti1 = tangents[i + 1] ?? 0;
|
|
189
|
+
const cp1x = round(x(x0 + 1 / 3));
|
|
190
|
+
const cp1y = round(y(vi + ti / 3));
|
|
191
|
+
const cp2x = round(x(x1 - 1 / 3));
|
|
192
|
+
const cp2y = round(y(vi1 - ti1 / 3));
|
|
193
|
+
line += ` C${cp1x},${cp1y} ${cp2x},${cp2y} ${x(x1)},${y(vi1)}`;
|
|
194
|
+
}
|
|
195
|
+
const area = `${line} L${x(values.length - 1)},${round(height)} L${x(0)},${round(height)} Z`;
|
|
196
|
+
return {
|
|
197
|
+
line,
|
|
198
|
+
area
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/charts/TrendChart.tsx
|
|
203
|
+
const MARGIN = {
|
|
204
|
+
top: 8,
|
|
205
|
+
right: 8,
|
|
206
|
+
bottom: 18,
|
|
207
|
+
left: 8
|
|
208
|
+
};
|
|
209
|
+
const MAX_TICKS = 6;
|
|
210
|
+
const PAD = 2;
|
|
211
|
+
const GRID = [
|
|
212
|
+
.25,
|
|
213
|
+
.5,
|
|
214
|
+
.75
|
|
215
|
+
];
|
|
216
|
+
const tickIndices = (n) => {
|
|
217
|
+
if (n <= MAX_TICKS) return Array.from({ length: n }, (_, i) => i);
|
|
218
|
+
const step = (n - 1) / (MAX_TICKS - 1);
|
|
219
|
+
return Array.from({ length: MAX_TICKS }, (_, i) => Math.round(i * step));
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Gradient area trend chart: a monotone-cubic line over a themed gradient fill, with
|
|
223
|
+
* gridlines, dots (when sparse), timeframe-aware x-axis labels, and a pointer-tracked
|
|
224
|
+
* tooltip. Dependency-free; sizes to its container via a ResizeObserver so dots and
|
|
225
|
+
* labels stay crisp (no aspect-ratio distortion).
|
|
226
|
+
*/
|
|
227
|
+
function TrendChart({ buckets, ariaLabel, minHeight = 160 }) {
|
|
228
|
+
const ref = useRef(null);
|
|
229
|
+
const [size, setSize] = useState({
|
|
230
|
+
w: 600,
|
|
231
|
+
h: minHeight
|
|
232
|
+
});
|
|
233
|
+
const [active, setActive] = useState(null);
|
|
234
|
+
const gradientId = useId();
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
const el = ref.current;
|
|
237
|
+
if (!el) return;
|
|
238
|
+
const update = () => setSize({
|
|
239
|
+
w: el.clientWidth || 600,
|
|
240
|
+
h: el.clientHeight || minHeight
|
|
241
|
+
});
|
|
242
|
+
update();
|
|
243
|
+
const ro = new ResizeObserver(update);
|
|
244
|
+
ro.observe(el);
|
|
245
|
+
return () => ro.disconnect();
|
|
246
|
+
}, [minHeight]);
|
|
247
|
+
const width = size.w;
|
|
248
|
+
const height = size.h;
|
|
249
|
+
const values = buckets.map((b) => b.value);
|
|
250
|
+
const n = values.length;
|
|
251
|
+
const plotW = Math.max(1, width - MARGIN.left - MARGIN.right);
|
|
252
|
+
const plotH = Math.max(1, height - MARGIN.top - MARGIN.bottom);
|
|
253
|
+
const { line, area } = monotoneAreaPath(values, {
|
|
254
|
+
width: plotW,
|
|
255
|
+
height: plotH,
|
|
256
|
+
padding: PAD
|
|
257
|
+
});
|
|
258
|
+
const vmax = n > 0 ? Math.max(...values) : 0;
|
|
259
|
+
const vmin = n > 0 ? Math.min(...values) : 0;
|
|
260
|
+
const vspan = vmax - vmin || 1;
|
|
261
|
+
const px = (i) => n > 1 ? i / (n - 1) * plotW : plotW / 2;
|
|
262
|
+
const py = (v) => vmax === vmin ? plotH / 2 : PAD + (plotH - PAD * 2) - (v - vmin) / vspan * (plotH - PAD * 2);
|
|
263
|
+
const onMove = (e) => {
|
|
264
|
+
if (n === 0) return;
|
|
265
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
266
|
+
const rel = e.clientX - rect.left - MARGIN.left;
|
|
267
|
+
setActive(Math.max(0, Math.min(n - 1, Math.round(rel / plotW * (n - 1)))));
|
|
268
|
+
};
|
|
269
|
+
const activeValue = active !== null ? values[active] ?? 0 : 0;
|
|
270
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
271
|
+
ref,
|
|
272
|
+
className: "analytics-chart",
|
|
273
|
+
style: {
|
|
274
|
+
flex: "1 1 0",
|
|
275
|
+
minHeight
|
|
276
|
+
},
|
|
277
|
+
onPointerMove: onMove,
|
|
278
|
+
onPointerLeave: () => setActive(null),
|
|
279
|
+
children: [
|
|
280
|
+
/* @__PURE__ */ jsx(ChartStyles, {}),
|
|
281
|
+
/* @__PURE__ */ jsxs("svg", {
|
|
282
|
+
className: "analytics-chart__svg",
|
|
283
|
+
width,
|
|
284
|
+
height,
|
|
285
|
+
role: "img",
|
|
286
|
+
"aria-label": ariaLabel,
|
|
287
|
+
children: [
|
|
288
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", {
|
|
289
|
+
id: gradientId,
|
|
290
|
+
x1: "0",
|
|
291
|
+
y1: "0",
|
|
292
|
+
x2: "0",
|
|
293
|
+
y2: "1",
|
|
294
|
+
children: [
|
|
295
|
+
/* @__PURE__ */ jsx("stop", {
|
|
296
|
+
offset: "0%",
|
|
297
|
+
stopColor: "var(--analytics-chart-1)",
|
|
298
|
+
stopOpacity: "0.38"
|
|
299
|
+
}),
|
|
300
|
+
/* @__PURE__ */ jsx("stop", {
|
|
301
|
+
offset: "55%",
|
|
302
|
+
stopColor: "var(--analytics-chart-1)",
|
|
303
|
+
stopOpacity: "0.1"
|
|
304
|
+
}),
|
|
305
|
+
/* @__PURE__ */ jsx("stop", {
|
|
306
|
+
offset: "100%",
|
|
307
|
+
stopColor: "var(--analytics-chart-1)",
|
|
308
|
+
stopOpacity: "0"
|
|
309
|
+
})
|
|
310
|
+
]
|
|
311
|
+
}) }),
|
|
312
|
+
/* @__PURE__ */ jsxs("g", {
|
|
313
|
+
transform: `translate(${MARGIN.left},${MARGIN.top})`,
|
|
314
|
+
children: [
|
|
315
|
+
GRID.map((g) => /* @__PURE__ */ jsx("line", {
|
|
316
|
+
className: "analytics-chart__grid",
|
|
317
|
+
x1: 0,
|
|
318
|
+
x2: plotW,
|
|
319
|
+
y1: g * plotH,
|
|
320
|
+
y2: g * plotH
|
|
321
|
+
}, g)),
|
|
322
|
+
area ? /* @__PURE__ */ jsx("path", {
|
|
323
|
+
className: "analytics-chart__area",
|
|
324
|
+
d: area,
|
|
325
|
+
fill: `url(#${gradientId})`
|
|
326
|
+
}) : null,
|
|
327
|
+
line ? /* @__PURE__ */ jsx("path", {
|
|
328
|
+
className: "analytics-chart__line",
|
|
329
|
+
d: line
|
|
330
|
+
}) : null,
|
|
331
|
+
n <= 12 ? values.map((v, i) => /* @__PURE__ */ jsx("circle", {
|
|
332
|
+
className: "analytics-chart__dot",
|
|
333
|
+
cx: px(i),
|
|
334
|
+
cy: py(v),
|
|
335
|
+
r: 2.5
|
|
336
|
+
}, buckets[i]?.label ?? i)) : null,
|
|
337
|
+
active !== null ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("line", {
|
|
338
|
+
className: "analytics-chart__cursor",
|
|
339
|
+
x1: px(active),
|
|
340
|
+
x2: px(active),
|
|
341
|
+
y1: 0,
|
|
342
|
+
y2: plotH
|
|
343
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
344
|
+
className: "analytics-chart__active",
|
|
345
|
+
cx: px(active),
|
|
346
|
+
cy: py(activeValue),
|
|
347
|
+
r: 3.5
|
|
348
|
+
})] }) : null
|
|
349
|
+
]
|
|
350
|
+
}),
|
|
351
|
+
/* @__PURE__ */ jsx("g", {
|
|
352
|
+
transform: `translate(${MARGIN.left},${height - 4})`,
|
|
353
|
+
children: tickIndices(n).map((i) => /* @__PURE__ */ jsx("text", {
|
|
354
|
+
className: "analytics-chart__axis",
|
|
355
|
+
x: px(i),
|
|
356
|
+
textAnchor: i === 0 ? "start" : i === n - 1 ? "end" : "middle",
|
|
357
|
+
children: buckets[i]?.label
|
|
358
|
+
}, buckets[i]?.label ?? i))
|
|
359
|
+
})
|
|
360
|
+
]
|
|
361
|
+
}),
|
|
362
|
+
active !== null ? /* @__PURE__ */ jsxs("div", {
|
|
363
|
+
className: "analytics-chart__tooltip",
|
|
364
|
+
style: {
|
|
365
|
+
left: MARGIN.left + px(active),
|
|
366
|
+
top: MARGIN.top + py(activeValue)
|
|
367
|
+
},
|
|
368
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
369
|
+
className: "analytics-chart__tooltip-label",
|
|
370
|
+
children: buckets[active]?.label
|
|
371
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
372
|
+
className: "analytics-chart__tooltip-value",
|
|
373
|
+
children: buckets[active]?.display
|
|
374
|
+
})]
|
|
375
|
+
}) : null
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/widgets/realtimePoll.ts
|
|
381
|
+
/** Build the realtime endpoint path + query string for a poll. */
|
|
382
|
+
const buildPollPath = (endpoint, config) => {
|
|
383
|
+
const params = new URLSearchParams({
|
|
384
|
+
metric: config.metric,
|
|
385
|
+
windowMinutes: String(config.windowMinutes)
|
|
386
|
+
});
|
|
387
|
+
if (config.dataSource) params.set("dataSource", config.dataSource);
|
|
388
|
+
return `${endpoint}?${params.toString()}`;
|
|
389
|
+
};
|
|
390
|
+
/** Map a minute series to TrendChart points (HH:MM labels, locale-formatted values). */
|
|
391
|
+
const toRealtimePoints = (series, locale) => {
|
|
392
|
+
const nf = new Intl.NumberFormat(locale);
|
|
393
|
+
return series.map((p) => ({
|
|
394
|
+
label: new Date(p.date).toLocaleTimeString(locale, {
|
|
395
|
+
hour: "2-digit",
|
|
396
|
+
minute: "2-digit"
|
|
397
|
+
}),
|
|
398
|
+
value: p.value,
|
|
399
|
+
display: nf.format(p.value)
|
|
400
|
+
}));
|
|
401
|
+
};
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/widgets/RealtimeCounter.tsx
|
|
404
|
+
function RealtimeCounter(props) {
|
|
405
|
+
const { endpoint, intervalMs, metric, windowMinutes, dataSource, locale, caption, pausedLabel } = props;
|
|
406
|
+
const [activeNow, setActiveNow] = useState(props.initialActiveNow);
|
|
407
|
+
const [series, setSeries] = useState(props.initialSeries);
|
|
408
|
+
const [paused, setPaused] = useState(false);
|
|
409
|
+
useEffect(() => {
|
|
410
|
+
let cancelled = false;
|
|
411
|
+
const path = buildPollPath(endpoint, {
|
|
412
|
+
metric,
|
|
413
|
+
windowMinutes,
|
|
414
|
+
dataSource
|
|
415
|
+
});
|
|
416
|
+
const tick = async () => {
|
|
417
|
+
try {
|
|
418
|
+
const res = await fetch(path, { credentials: "same-origin" });
|
|
419
|
+
if (!res.ok) {
|
|
420
|
+
if (!cancelled) setPaused(true);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const data = await res.json();
|
|
424
|
+
if (cancelled || data.status !== "ok") return;
|
|
425
|
+
setActiveNow(data.activeNow);
|
|
426
|
+
setSeries(data.series);
|
|
427
|
+
setPaused(false);
|
|
428
|
+
} catch {
|
|
429
|
+
if (!cancelled) setPaused(true);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
const id = setInterval(tick, intervalMs);
|
|
433
|
+
return () => {
|
|
434
|
+
cancelled = true;
|
|
435
|
+
clearInterval(id);
|
|
436
|
+
};
|
|
437
|
+
}, [
|
|
438
|
+
endpoint,
|
|
439
|
+
intervalMs,
|
|
440
|
+
metric,
|
|
441
|
+
windowMinutes,
|
|
442
|
+
dataSource
|
|
443
|
+
]);
|
|
444
|
+
const nf = new Intl.NumberFormat(locale);
|
|
445
|
+
const points = toRealtimePoints(series, locale);
|
|
446
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
447
|
+
/* @__PURE__ */ jsx("span", {
|
|
448
|
+
style: {
|
|
449
|
+
fontSize: "2rem",
|
|
450
|
+
fontWeight: 700,
|
|
451
|
+
lineHeight: 1.1,
|
|
452
|
+
color: "var(--theme-elevation-800)"
|
|
453
|
+
},
|
|
454
|
+
children: nf.format(activeNow)
|
|
455
|
+
}),
|
|
456
|
+
/* @__PURE__ */ jsx("span", {
|
|
457
|
+
style: {
|
|
458
|
+
fontSize: "0.75rem",
|
|
459
|
+
color: "var(--theme-elevation-400)"
|
|
460
|
+
},
|
|
461
|
+
children: paused ? pausedLabel : caption
|
|
462
|
+
}),
|
|
463
|
+
/* @__PURE__ */ jsx(TrendChart, {
|
|
464
|
+
buckets: points,
|
|
465
|
+
ariaLabel: caption,
|
|
466
|
+
minHeight: 120
|
|
467
|
+
})
|
|
468
|
+
] });
|
|
469
|
+
}
|
|
470
|
+
//#endregion
|
|
471
|
+
export { TrendChart as n, BarList as r, RealtimeCounter as t };
|
|
472
|
+
|
|
473
|
+
//# sourceMappingURL=RealtimeCounter-BJrjMPSa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealtimeCounter-BJrjMPSa.js","names":[],"sources":["../src/charts/bars.ts","../src/charts/styles.tsx","../src/charts/BarList.tsx","../src/charts/spline.ts","../src/charts/TrendChart.tsx","../src/widgets/realtimePoll.ts","../src/widgets/RealtimeCounter.tsx"],"sourcesContent":["export interface BarDatum {\n\tlabel: string\n\tvalue: number\n\tdisplay?: string\n}\n\nexport interface BarRow {\n\tlabel: string\n\tvalue: number\n\tfraction: number\n\tdisplay?: string\n}\n\n/**\n * Scale each datum's value to a `[0, 1]` fraction of the largest value, for a ranked\n * bar list. A degenerate all-zero set yields zero fractions (no bar), never a divide\n * by zero.\n */\nexport const toBarRows = (data: BarDatum[]): BarRow[] => {\n\tconst max = data.reduce((m, d) => Math.max(m, d.value), 0)\n\treturn data.map((d) => ({\n\t\tlabel: d.label,\n\t\tvalue: d.value,\n\t\tfraction: max > 0 ? d.value / max : 0,\n\t\tdisplay: d.display,\n\t}))\n}\n","'use client'\n\nconst CHART_CSS = `\n:where(:root) {\n\t--analytics-chart-1: var(--theme-success-500, #3b82f6);\n}\n.analytics-chart { position: relative; width: 100%; }\n.analytics-chart__svg { display: block; width: 100%; height: 100%; overflow: visible; }\n.analytics-chart__grid { stroke: var(--theme-elevation-150); stroke-width: 1; vector-effect: non-scaling-stroke; }\n.analytics-chart__area { stroke: none; }\n.analytics-chart__line { fill: none; stroke: var(--analytics-chart-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }\n.analytics-chart__dot { fill: var(--theme-elevation-0); stroke: var(--analytics-chart-1); stroke-width: 2; }\n.analytics-chart__axis { fill: var(--theme-elevation-450); font-size: 0.6875rem; }\n.analytics-chart__cursor { stroke: var(--theme-elevation-300); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }\n.analytics-chart__active { fill: var(--analytics-chart-1); stroke: var(--theme-elevation-0); stroke-width: 2; }\n.analytics-chart__tooltip { position: absolute; pointer-events: none; transform: translate(-50%, -120%); background: var(--theme-elevation-0); border: 1px solid var(--theme-elevation-150); border-radius: var(--style-radius-m, 6px); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18); padding: 0.4rem 0.6rem; font-size: 0.75rem; white-space: nowrap; z-index: 10; animation: analytics-fade 0.12s ease-out; }\n.analytics-chart__tooltip-label { color: var(--theme-elevation-500); font-weight: 600; margin-bottom: 0.15rem; }\n.analytics-chart__tooltip-value { color: var(--theme-elevation-800); font-weight: 700; font-variant-numeric: tabular-nums; }\n@keyframes analytics-fade { from { opacity: 0; } to { opacity: 1; } }\n.analytics-bars { display: flex; flex-direction: column; gap: 0.35rem; }\n.analytics-bars__row { position: relative; display: flex; align-items: center; gap: 0.6rem; }\n.analytics-bars__track { position: relative; flex: 1; min-width: 0; height: 1.85rem; border-radius: var(--style-radius-s, 4px); overflow: hidden; }\n.analytics-bars__fill { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: color-mix(in srgb, var(--analytics-chart-1) 90%, transparent); transition: filter 0.1s ease; }\n.analytics-bars__row:hover .analytics-bars__fill { filter: brightness(1.12); }\n.analytics-bars__label { position: relative; padding: 0 0.6rem; color: var(--theme-base-800, #fff); font-size: 0.8125rem; line-height: 1.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.analytics-bars__value { flex: none; font-size: 0.8125rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--theme-elevation-800); }\n.analytics-bars__empty { color: var(--theme-elevation-400); font-size: 0.8125rem; }\n`\n\n/**\n * Single scoped stylesheet for all analytics charts, injected as a `<style>` element so\n * it ships as a JS string (our tsdown build has no CSS pipeline) and behaves identically\n * in dev and when installed from npm. The `--analytics-chart-*` tokens live in `:root`\n * scope so a consuming app can override them.\n */\nexport function ChartStyles() {\n\t// biome-ignore lint/security/noDangerouslySetInnerHtml: static build-time CSS constant, no user input\n\treturn <style dangerouslySetInnerHTML={{ __html: CHART_CSS }} />\n}\n","'use client'\n\nimport { type PointerEvent, useState } from 'react'\nimport { type BarDatum, toBarRows } from './bars'\nimport { ChartStyles } from './styles'\n\nexport interface BarListProps {\n\tdata: BarDatum[]\n\temptyLabel: string\n}\n\ninterface Hover {\n\ti: number\n\tx: number\n\ty: number\n}\n\n/**\n * Ranked horizontal bar list (shadcn \"custom label\" style): each row is a filled,\n * proportional bar with the label inside and the value outside; hovering a row lifts\n * it and shows a tooltip with the full label and value (useful when the label is\n * truncated). Dependency-free; styling comes from the shared chart stylesheet.\n */\nexport function BarList({ data, emptyLabel }: BarListProps) {\n\tconst rows = toBarRows(data)\n\tconst [hover, setHover] = useState<Hover | null>(null)\n\tif (rows.length === 0) {\n\t\treturn <span className=\"analytics-bars__empty\">{emptyLabel}</span>\n\t}\n\tconst track = (i: number) => (e: PointerEvent<HTMLDivElement>) =>\n\t\tsetHover({ i, x: e.clientX, y: e.clientY })\n\tconst hovered = hover ? rows[hover.i] : undefined\n\treturn (\n\t\t<div className=\"analytics-chart\">\n\t\t\t<ChartStyles />\n\t\t\t<div className=\"analytics-bars\">\n\t\t\t\t{rows.map((row, i) => (\n\t\t\t\t\t<div\n\t\t\t\t\t\tkey={row.label}\n\t\t\t\t\t\tclassName=\"analytics-bars__row\"\n\t\t\t\t\t\tonPointerEnter={track(i)}\n\t\t\t\t\t\tonPointerMove={track(i)}\n\t\t\t\t\t\tonPointerLeave={() => setHover(null)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"analytics-bars__track\">\n\t\t\t\t\t\t\t<span className=\"analytics-bars__fill\" style={{ width: `${row.fraction * 100}%` }} />\n\t\t\t\t\t\t\t<span className=\"analytics-bars__label\">{row.label}</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span className=\"analytics-bars__value\">{row.display ?? row.value}</span>\n\t\t\t\t\t</div>\n\t\t\t\t))}\n\t\t\t</div>\n\t\t\t{hover && hovered ? (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"analytics-chart__tooltip\"\n\t\t\t\t\tstyle={{ position: 'fixed', left: hover.x, top: hover.y }}\n\t\t\t\t>\n\t\t\t\t\t<div className=\"analytics-chart__tooltip-label\">{hovered.label}</div>\n\t\t\t\t\t<div className=\"analytics-chart__tooltip-value\">{hovered.display ?? hovered.value}</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t)\n}\n","export interface SplineGeometry {\n\tline: string\n\tarea: string\n}\n\nexport interface SplineOptions {\n\twidth: number\n\theight: number\n\tpadding?: number\n}\n\nconst round = (n: number): number => Math.round(n * 100) / 100\n\n/**\n * Fritsch-Carlson monotone tangents for a unit-spaced series: endpoints take the\n * adjacent secant, interior points the average of neighbouring secants, then each is\n * clamped so the cubic never overshoots (no wiggle between points).\n */\nexport const computeTangents = (ys: number[]): number[] => {\n\tconst n = ys.length\n\tif (n < 2) {\n\t\treturn ys.map(() => 0)\n\t}\n\tconst d = ys.slice(0, -1).map((y, i) => (ys[i + 1] ?? 0) - y)\n\tconst m = ys.map((_, i) => {\n\t\tif (i === 0) return d[0] ?? 0\n\t\tif (i === n - 1) return d[n - 2] ?? 0\n\t\treturn ((d[i - 1] ?? 0) + (d[i] ?? 0)) / 2\n\t})\n\tfor (let i = 0; i < n - 1; i++) {\n\t\tconst di = d[i] ?? 0\n\t\tif (di === 0) {\n\t\t\tm[i] = 0\n\t\t\tm[i + 1] = 0\n\t\t\tcontinue\n\t\t}\n\t\tconst mi = m[i] ?? 0\n\t\tconst mi1 = m[i + 1] ?? 0\n\t\tconst a = mi / di\n\t\tconst b = mi1 / di\n\t\tconst s = a * a + b * b\n\t\tif (s > 9) {\n\t\t\tconst t = 3 / Math.sqrt(s)\n\t\t\tm[i] = t * a * di\n\t\t\tm[i + 1] = t * b * di\n\t\t}\n\t}\n\treturn m\n}\n\n/**\n * Build SVG path strings for a monotone-cubic line and its closed area fill, mapping a\n * value series into a `width` x `height` box (y normalized to the value range; flat or\n * single-value series sit on the vertical midline).\n */\nexport const monotoneAreaPath = (values: number[], opts: SplineOptions): SplineGeometry => {\n\tconst { width, height } = opts\n\tconst padding = opts.padding ?? 0\n\tif (values.length === 0) {\n\t\treturn { line: '', area: '' }\n\t}\n\tconst innerH = height - padding * 2\n\tconst max = Math.max(...values)\n\tconst min = Math.min(...values)\n\tconst span = max - min || 1\n\tconst x = (i: number): number => round(values.length > 1 ? (i / (values.length - 1)) * width : 0)\n\tconst y = (v: number): number =>\n\t\tround(max === min ? height / 2 : padding + innerH - ((v - min) / span) * innerH)\n\tconst v0 = values[0] ?? 0\n\tif (values.length === 1) {\n\t\tconst line = `M0,${y(v0)} L${round(width)},${y(v0)}`\n\t\treturn { line, area: '' }\n\t}\n\tconst tangents = computeTangents(values)\n\tlet line = `M${x(0)},${y(v0)}`\n\tfor (let i = 0; i < values.length - 1; i++) {\n\t\tconst x0 = i\n\t\tconst x1 = i + 1\n\t\tconst vi = values[i] ?? 0\n\t\tconst vi1 = values[i + 1] ?? 0\n\t\tconst ti = tangents[i] ?? 0\n\t\tconst ti1 = tangents[i + 1] ?? 0\n\t\tconst cp1x = round(x(x0 + 1 / 3))\n\t\tconst cp1y = round(y(vi + ti / 3))\n\t\tconst cp2x = round(x(x1 - 1 / 3))\n\t\tconst cp2y = round(y(vi1 - ti1 / 3))\n\t\tline += ` C${cp1x},${cp1y} ${cp2x},${cp2y} ${x(x1)},${y(vi1)}`\n\t}\n\tconst area = `${line} L${x(values.length - 1)},${round(height)} L${x(0)},${round(height)} Z`\n\treturn { line, area }\n}\n","'use client'\n\nimport { type PointerEvent, useEffect, useId, useRef, useState } from 'react'\nimport { monotoneAreaPath } from './spline'\nimport { ChartStyles } from './styles'\n\nexport interface TrendPoint {\n\tlabel: string\n\tvalue: number\n\tdisplay: string\n}\n\nexport interface TrendChartProps {\n\tbuckets: TrendPoint[]\n\tariaLabel: string\n\tminHeight?: number\n}\n\nconst MARGIN = { top: 8, right: 8, bottom: 18, left: 8 }\nconst MAX_TICKS = 6\nconst PAD = 2\nconst GRID = [0.25, 0.5, 0.75]\n\nconst tickIndices = (n: number): number[] => {\n\tif (n <= MAX_TICKS) {\n\t\treturn Array.from({ length: n }, (_, i) => i)\n\t}\n\tconst step = (n - 1) / (MAX_TICKS - 1)\n\treturn Array.from({ length: MAX_TICKS }, (_, i) => Math.round(i * step))\n}\n\n/**\n * Gradient area trend chart: a monotone-cubic line over a themed gradient fill, with\n * gridlines, dots (when sparse), timeframe-aware x-axis labels, and a pointer-tracked\n * tooltip. Dependency-free; sizes to its container via a ResizeObserver so dots and\n * labels stay crisp (no aspect-ratio distortion).\n */\nexport function TrendChart({ buckets, ariaLabel, minHeight = 160 }: TrendChartProps) {\n\tconst ref = useRef<HTMLDivElement>(null)\n\tconst [size, setSize] = useState({ w: 600, h: minHeight })\n\tconst [active, setActive] = useState<number | null>(null)\n\tconst gradientId = useId()\n\n\tuseEffect(() => {\n\t\tconst el = ref.current\n\t\tif (!el) {\n\t\t\treturn\n\t\t}\n\t\tconst update = () => setSize({ w: el.clientWidth || 600, h: el.clientHeight || minHeight })\n\t\tupdate()\n\t\tconst ro = new ResizeObserver(update)\n\t\tro.observe(el)\n\t\treturn () => ro.disconnect()\n\t}, [minHeight])\n\n\tconst width = size.w\n\tconst height = size.h\n\tconst values = buckets.map((b) => b.value)\n\tconst n = values.length\n\tconst plotW = Math.max(1, width - MARGIN.left - MARGIN.right)\n\tconst plotH = Math.max(1, height - MARGIN.top - MARGIN.bottom)\n\tconst { line, area } = monotoneAreaPath(values, { width: plotW, height: plotH, padding: PAD })\n\n\tconst vmax = n > 0 ? Math.max(...values) : 0\n\tconst vmin = n > 0 ? Math.min(...values) : 0\n\tconst vspan = vmax - vmin || 1\n\tconst px = (i: number): number => (n > 1 ? (i / (n - 1)) * plotW : plotW / 2)\n\tconst py = (v: number): number =>\n\t\tvmax === vmin ? plotH / 2 : PAD + (plotH - PAD * 2) - ((v - vmin) / vspan) * (plotH - PAD * 2)\n\n\tconst onMove = (e: PointerEvent<HTMLDivElement>): void => {\n\t\tif (n === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst rect = e.currentTarget.getBoundingClientRect()\n\t\tconst rel = e.clientX - rect.left - MARGIN.left\n\t\tsetActive(Math.max(0, Math.min(n - 1, Math.round((rel / plotW) * (n - 1)))))\n\t}\n\n\tconst activeValue = active !== null ? (values[active] ?? 0) : 0\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName=\"analytics-chart\"\n\t\t\tstyle={{ flex: '1 1 0', minHeight }}\n\t\t\tonPointerMove={onMove}\n\t\t\tonPointerLeave={() => setActive(null)}\n\t\t>\n\t\t\t<ChartStyles />\n\t\t\t<svg\n\t\t\t\tclassName=\"analytics-chart__svg\"\n\t\t\t\twidth={width}\n\t\t\t\theight={height}\n\t\t\t\trole=\"img\"\n\t\t\t\taria-label={ariaLabel}\n\t\t\t>\n\t\t\t\t<defs>\n\t\t\t\t\t<linearGradient id={gradientId} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n\t\t\t\t\t\t<stop offset=\"0%\" stopColor=\"var(--analytics-chart-1)\" stopOpacity=\"0.38\" />\n\t\t\t\t\t\t<stop offset=\"55%\" stopColor=\"var(--analytics-chart-1)\" stopOpacity=\"0.1\" />\n\t\t\t\t\t\t<stop offset=\"100%\" stopColor=\"var(--analytics-chart-1)\" stopOpacity=\"0\" />\n\t\t\t\t\t</linearGradient>\n\t\t\t\t</defs>\n\t\t\t\t<g transform={`translate(${MARGIN.left},${MARGIN.top})`}>\n\t\t\t\t\t{GRID.map((g) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={g}\n\t\t\t\t\t\t\tclassName=\"analytics-chart__grid\"\n\t\t\t\t\t\t\tx1={0}\n\t\t\t\t\t\t\tx2={plotW}\n\t\t\t\t\t\t\ty1={g * plotH}\n\t\t\t\t\t\t\ty2={g * plotH}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\t\t\t\t\t{area ? (\n\t\t\t\t\t\t<path className=\"analytics-chart__area\" d={area} fill={`url(#${gradientId})`} />\n\t\t\t\t\t) : null}\n\t\t\t\t\t{line ? <path className=\"analytics-chart__line\" d={line} /> : null}\n\t\t\t\t\t{n <= 12\n\t\t\t\t\t\t? values.map((v, i) => (\n\t\t\t\t\t\t\t\t<circle\n\t\t\t\t\t\t\t\t\tkey={buckets[i]?.label ?? i}\n\t\t\t\t\t\t\t\t\tclassName=\"analytics-chart__dot\"\n\t\t\t\t\t\t\t\t\tcx={px(i)}\n\t\t\t\t\t\t\t\t\tcy={py(v)}\n\t\t\t\t\t\t\t\t\tr={2.5}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t))\n\t\t\t\t\t\t: null}\n\t\t\t\t\t{active !== null ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<line\n\t\t\t\t\t\t\t\tclassName=\"analytics-chart__cursor\"\n\t\t\t\t\t\t\t\tx1={px(active)}\n\t\t\t\t\t\t\t\tx2={px(active)}\n\t\t\t\t\t\t\t\ty1={0}\n\t\t\t\t\t\t\t\ty2={plotH}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<circle\n\t\t\t\t\t\t\t\tclassName=\"analytics-chart__active\"\n\t\t\t\t\t\t\t\tcx={px(active)}\n\t\t\t\t\t\t\t\tcy={py(activeValue)}\n\t\t\t\t\t\t\t\tr={3.5}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) : null}\n\t\t\t\t</g>\n\t\t\t\t<g transform={`translate(${MARGIN.left},${height - 4})`}>\n\t\t\t\t\t{tickIndices(n).map((i) => (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tkey={buckets[i]?.label ?? i}\n\t\t\t\t\t\t\tclassName=\"analytics-chart__axis\"\n\t\t\t\t\t\t\tx={px(i)}\n\t\t\t\t\t\t\ttextAnchor={i === 0 ? 'start' : i === n - 1 ? 'end' : 'middle'}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{buckets[i]?.label}\n\t\t\t\t\t\t</text>\n\t\t\t\t\t))}\n\t\t\t\t</g>\n\t\t\t</svg>\n\t\t\t{active !== null ? (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"analytics-chart__tooltip\"\n\t\t\t\t\tstyle={{ left: MARGIN.left + px(active), top: MARGIN.top + py(activeValue) }}\n\t\t\t\t>\n\t\t\t\t\t<div className=\"analytics-chart__tooltip-label\">{buckets[active]?.label}</div>\n\t\t\t\t\t<div className=\"analytics-chart__tooltip-value\">{buckets[active]?.display}</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t)\n}\n","import type { RealtimePoint } from './readForWidgetRealtime'\n\nexport interface PollConfig {\n\tmetric: string\n\twindowMinutes: number\n\tdataSource?: string\n}\n\nexport interface RealtimeChartPoint {\n\tlabel: string\n\tvalue: number\n\tdisplay: string\n}\n\n/** Build the realtime endpoint path + query string for a poll. */\nexport const buildPollPath = (endpoint: string, config: PollConfig): string => {\n\tconst params = new URLSearchParams({\n\t\tmetric: config.metric,\n\t\twindowMinutes: String(config.windowMinutes),\n\t})\n\tif (config.dataSource) {\n\t\tparams.set('dataSource', config.dataSource)\n\t}\n\treturn `${endpoint}?${params.toString()}`\n}\n\n/** Map a minute series to TrendChart points (HH:MM labels, locale-formatted values). */\nexport const toRealtimePoints = (series: RealtimePoint[], locale: string): RealtimeChartPoint[] => {\n\tconst nf = new Intl.NumberFormat(locale)\n\treturn series.map((p) => ({\n\t\tlabel: new Date(p.date).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' }),\n\t\tvalue: p.value,\n\t\tdisplay: nf.format(p.value),\n\t}))\n}\n","'use client'\n\nimport { useEffect, useState } from 'react'\nimport { TrendChart } from '../charts/TrendChart'\nimport type { RealtimePoint } from './readForWidgetRealtime'\nimport { buildPollPath, toRealtimePoints } from './realtimePoll'\n\nexport interface RealtimeCounterProps {\n\tendpoint: string\n\tintervalMs: number\n\tmetric: string\n\twindowMinutes: number\n\tdataSource?: string\n\tinitialActiveNow: number\n\tinitialSeries: RealtimePoint[]\n\tlocale: string\n\tcaption: string\n\tpausedLabel: string\n}\n\nexport function RealtimeCounter(props: RealtimeCounterProps) {\n\tconst { endpoint, intervalMs, metric, windowMinutes, dataSource, locale, caption, pausedLabel } =\n\t\tprops\n\tconst [activeNow, setActiveNow] = useState(props.initialActiveNow)\n\tconst [series, setSeries] = useState(props.initialSeries)\n\tconst [paused, setPaused] = useState(false)\n\n\tuseEffect(() => {\n\t\tlet cancelled = false\n\t\tconst path = buildPollPath(endpoint, { metric, windowMinutes, dataSource })\n\t\tconst tick = async () => {\n\t\t\ttry {\n\t\t\t\tconst res = await fetch(path, { credentials: 'same-origin' })\n\t\t\t\tif (!res.ok) {\n\t\t\t\t\tif (!cancelled) setPaused(true)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst data = (await res.json()) as {\n\t\t\t\t\tstatus: string\n\t\t\t\t\tactiveNow: number\n\t\t\t\t\tseries: RealtimePoint[]\n\t\t\t\t}\n\t\t\t\tif (cancelled || data.status !== 'ok') return\n\t\t\t\tsetActiveNow(data.activeNow)\n\t\t\t\tsetSeries(data.series)\n\t\t\t\tsetPaused(false)\n\t\t\t} catch {\n\t\t\t\tif (!cancelled) setPaused(true)\n\t\t\t}\n\t\t}\n\t\tconst id = setInterval(tick, intervalMs)\n\t\treturn () => {\n\t\t\tcancelled = true\n\t\t\tclearInterval(id)\n\t\t}\n\t}, [endpoint, intervalMs, metric, windowMinutes, dataSource])\n\n\tconst nf = new Intl.NumberFormat(locale)\n\tconst points = toRealtimePoints(series, locale)\n\treturn (\n\t\t<>\n\t\t\t<span\n\t\t\t\tstyle={{\n\t\t\t\t\tfontSize: '2rem',\n\t\t\t\t\tfontWeight: 700,\n\t\t\t\t\tlineHeight: 1.1,\n\t\t\t\t\tcolor: 'var(--theme-elevation-800)',\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{nf.format(activeNow)}\n\t\t\t</span>\n\t\t\t<span style={{ fontSize: '0.75rem', color: 'var(--theme-elevation-400)' }}>\n\t\t\t\t{paused ? pausedLabel : caption}\n\t\t\t</span>\n\t\t\t<TrendChart buckets={points} ariaLabel={caption} minHeight={120} />\n\t\t</>\n\t)\n}\n"],"mappings":";;;;;;;;AAkBA,MAAa,aAAa,SAA+B;CACxD,MAAM,MAAM,KAAK,QAAQ,GAAG,MAAM,KAAK,IAAI,GAAG,EAAE,KAAK,GAAG,CAAC;CACzD,OAAO,KAAK,KAAK,OAAO;EACvB,OAAO,EAAE;EACT,OAAO,EAAE;EACT,UAAU,MAAM,IAAI,EAAE,QAAQ,MAAM;EACpC,SAAS,EAAE;CACZ,EAAE;AACH;;;ACxBA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiClB,SAAgB,cAAc;CAE7B,OAAO,oBAAC,SAAD,EAAO,yBAAyB,EAAE,QAAQ,UAAU,EAAI,CAAA;AAChE;;;;;;;;;ACfA,SAAgB,QAAQ,EAAE,MAAM,cAA4B;CAC3D,MAAM,OAAO,UAAU,IAAI;CAC3B,MAAM,CAAC,OAAO,YAAY,SAAuB,IAAI;CACrD,IAAI,KAAK,WAAW,GACnB,OAAO,oBAAC,QAAD;EAAM,WAAU;YAAyB;CAAiB,CAAA;CAElE,MAAM,SAAS,OAAe,MAC7B,SAAS;EAAE;EAAG,GAAG,EAAE;EAAS,GAAG,EAAE;CAAQ,CAAC;CAC3C,MAAM,UAAU,QAAQ,KAAK,MAAM,KAAK,KAAA;CACxC,OACC,qBAAC,OAAD;EAAK,WAAU;YAAf;GACC,oBAAC,aAAD,CAAc,CAAA;GACd,oBAAC,OAAD;IA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O;GAA6B;aACtE,SAAS,cAAc;EACnB,CAAA;EACN,oBAAC,YAAD;GAAY,SAAS;GAAQ,WAAW;GAAS,WAAW;EAAM,CAAA;CACjE,EAAA,CAAA;AAEJ"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Config } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/core/contract.d.ts
|
|
4
|
+
type MetricKey = 'pageviews' | 'visitors' | 'visits' | 'sessions' | 'bounceRate' | 'avgDuration' | 'entries' | 'exits' | 'scrollDepth' | 'events' | 'conversions' | 'revenue';
|
|
5
|
+
type DimensionKey = 'page' | 'referrer' | 'source' | 'medium' | 'campaign' | 'utmSource' | 'utmMedium' | 'utmCampaign' | 'utmContent' | 'utmTerm' | 'device' | 'browser' | 'os' | 'country' | 'region' | 'city' | 'language' | 'event';
|
|
6
|
+
type Granularity = 'minute' | 'hour' | 'day' | 'week' | 'month';
|
|
7
|
+
interface DateRange {
|
|
8
|
+
start: Date;
|
|
9
|
+
end: Date;
|
|
10
|
+
}
|
|
11
|
+
interface AnalyticsFilter {
|
|
12
|
+
dimension: DimensionKey;
|
|
13
|
+
operator: 'eq' | 'contains' | 'matches';
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
interface AnalyticsQuery {
|
|
17
|
+
path?: string;
|
|
18
|
+
hostname?: string;
|
|
19
|
+
metrics: MetricKey[];
|
|
20
|
+
dimensions?: DimensionKey[];
|
|
21
|
+
dateRange: DateRange;
|
|
22
|
+
granularity?: Granularity;
|
|
23
|
+
filters?: AnalyticsFilter[];
|
|
24
|
+
limit?: number;
|
|
25
|
+
order?: {
|
|
26
|
+
metric: MetricKey;
|
|
27
|
+
direction: 'asc' | 'desc';
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface AnalyticsRow {
|
|
31
|
+
dimensions?: Partial<Record<DimensionKey, string>>;
|
|
32
|
+
metrics: Partial<Record<MetricKey, number>>;
|
|
33
|
+
timestamp?: string;
|
|
34
|
+
}
|
|
35
|
+
interface AnalyticsResult {
|
|
36
|
+
rows: AnalyticsRow[];
|
|
37
|
+
totals?: Partial<Record<MetricKey, number>>;
|
|
38
|
+
meta: {
|
|
39
|
+
provider: string;
|
|
40
|
+
sampled?: boolean;
|
|
41
|
+
clamped?: boolean;
|
|
42
|
+
fetchedAt: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
interface RateLimitDescriptor {
|
|
46
|
+
requestsPerMinute?: number;
|
|
47
|
+
requestsPerHour?: number;
|
|
48
|
+
maxConcurrent?: number;
|
|
49
|
+
quotaModel?: 'requests' | 'tokens';
|
|
50
|
+
readsCountAsUsage?: boolean;
|
|
51
|
+
}
|
|
52
|
+
interface AnalyticsCapabilities {
|
|
53
|
+
perPageQuery: boolean;
|
|
54
|
+
realtime: boolean;
|
|
55
|
+
realtimeWindowMinutes?: number;
|
|
56
|
+
comparison: boolean;
|
|
57
|
+
minGranularity: Granularity;
|
|
58
|
+
maxLookbackDays: number | null;
|
|
59
|
+
metrics: ReadonlySet<MetricKey>;
|
|
60
|
+
dimensions: ReadonlySet<DimensionKey>;
|
|
61
|
+
batchPageReport: boolean;
|
|
62
|
+
rateLimit: RateLimitDescriptor | null;
|
|
63
|
+
recommendedTtl: {
|
|
64
|
+
realtime: number;
|
|
65
|
+
aggregate: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
interface AdapterContext {
|
|
69
|
+
signal?: AbortSignal;
|
|
70
|
+
}
|
|
71
|
+
interface AnalyticsAdapter {
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly label: string;
|
|
74
|
+
readonly capabilities: AnalyticsCapabilities;
|
|
75
|
+
isConfigured(): boolean;
|
|
76
|
+
query(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>;
|
|
77
|
+
realtime?(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>;
|
|
78
|
+
register?(config: Config): void;
|
|
79
|
+
}
|
|
80
|
+
type AnalyticsAdapterFactory<Config> = (config: Config) => AnalyticsAdapter;
|
|
81
|
+
//#endregion
|
|
82
|
+
export { AnalyticsFilter as a, AnalyticsRow as c, Granularity as d, MetricKey as f, AnalyticsCapabilities as i, DateRange as l, AnalyticsAdapter as n, AnalyticsQuery as o, RateLimitDescriptor as p, AnalyticsAdapterFactory as r, AnalyticsResult as s, AdapterContext as t, DimensionKey as u };
|
|
83
|
+
//# sourceMappingURL=contract-CWZPKWuR.d.ts.map
|