@haakco/custd-react 3.74.0 → 3.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/uptime-charts.d.ts +3 -2
- package/dist/uptime-charts.js +39 -16
- package/package.json +1 -1
package/dist/uptime-charts.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SiteResponseHour, SiteUptimeDay, SiteUptimeWindow } from "@haakco/custd-sdk";
|
|
2
|
-
import type
|
|
2
|
+
import { type CSSProperties } from "react";
|
|
3
3
|
/** Round down so a missed check never displays as 100%. */
|
|
4
4
|
export declare function uptimePercent({ checks, upChecks }: SiteUptimeWindow): number | undefined;
|
|
5
5
|
export type DailyUptimeChartProps = {
|
|
@@ -23,5 +23,6 @@ export type UptimeResponseChartProps = {
|
|
|
23
23
|
slowestMs: number;
|
|
24
24
|
}) => string;
|
|
25
25
|
formatTime?: (timestamp: string) => string;
|
|
26
|
+
dataLabel?: string;
|
|
26
27
|
};
|
|
27
|
-
export declare function UptimeResponseChart({ hours, className, style, emptyLabel, averageLabel, slowestLabel, formatSummary, formatTime, }: UptimeResponseChartProps): import("react").JSX.Element;
|
|
28
|
+
export declare function UptimeResponseChart({ hours, className, style, emptyLabel, averageLabel, slowestLabel, formatSummary, formatTime, dataLabel, }: UptimeResponseChartProps): import("react").JSX.Element;
|
package/dist/uptime-charts.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
2
3
|
import { scaleLinear } from "./chart-scale.js";
|
|
3
4
|
/** Round down so a missed check never displays as 100%. */
|
|
4
5
|
export function uptimePercent({ checks, upChecks }) {
|
|
@@ -27,7 +28,22 @@ const dailyColors = {
|
|
|
27
28
|
const HOUR_MS = 3600000;
|
|
28
29
|
const WIDTH = 640;
|
|
29
30
|
const HEIGHT = 160;
|
|
30
|
-
|
|
31
|
+
const plotInset = 4;
|
|
32
|
+
const chartColors = {
|
|
33
|
+
avgMs: "var(--custd-chart-primary, #2563eb)",
|
|
34
|
+
maxMs: "var(--custd-chart-secondary, #9333ea)",
|
|
35
|
+
};
|
|
36
|
+
const utcHour = new Intl.DateTimeFormat("en", {
|
|
37
|
+
timeZone: "UTC",
|
|
38
|
+
month: "short",
|
|
39
|
+
day: "numeric",
|
|
40
|
+
hour: "numeric",
|
|
41
|
+
minute: "2-digit",
|
|
42
|
+
hourCycle: "h23",
|
|
43
|
+
});
|
|
44
|
+
const formatUtcHour = (timestamp) => `${utcHour.format(Date.parse(timestamp))} UTC`;
|
|
45
|
+
export function UptimeResponseChart({ hours, className, style, emptyLabel = "No passing checks in this range.", averageLabel = "Average", slowestLabel = "Slowest", formatSummary, formatTime = formatUtcHour, dataLabel = "Hourly data", }) {
|
|
46
|
+
const [showData, setShowData] = useState(false);
|
|
31
47
|
const passing = hours.filter((hour) => hour.avgMs != null && hour.upChecks > 0);
|
|
32
48
|
if (passing.length === 0)
|
|
33
49
|
return (_jsx("p", { className: className, style: style, children: emptyLabel }));
|
|
@@ -36,21 +52,28 @@ export function UptimeResponseChart({ hours, className, style, emptyLabel = "No
|
|
|
36
52
|
const average = Math.round(passing.reduce((sum, hour) => sum + (hour.avgMs ?? 0) * hour.upChecks, 0) / checks);
|
|
37
53
|
const start = Date.parse(hours[0].hourStart);
|
|
38
54
|
const end = Date.parse(hours[hours.length - 1].hourStart);
|
|
39
|
-
const x = scaleLinear({ start: start - HOUR_MS / 2, end: end + HOUR_MS / 2 },
|
|
40
|
-
const
|
|
55
|
+
const x = scaleLinear({ start: start - HOUR_MS / 2, end: end + HOUR_MS / 2 }, plotInset, WIDTH - plotInset);
|
|
56
|
+
const yMax = Math.max(1, maximum);
|
|
57
|
+
const y = scaleLinear({ start: 0, end: yMax }, HEIGHT - plotInset, plotInset);
|
|
41
58
|
const summary = formatSummary?.({ averageMs: average, slowestMs: maximum }) ??
|
|
42
59
|
`Response time: ${average} ms on average, slowest ${maximum} ms.`;
|
|
43
|
-
return (_jsxs("figure", { className: className, "data-custd-part": "response-chart", style: { margin: 0, ...style }, children: [_jsx("svg", { viewBox: `0 0 ${WIDTH} ${HEIGHT}`, style: { display: "block", width: "100%" }, role: "img", "aria-label": summary, children: ["avgMs", "maxMs"].map((field) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
return (_jsxs("figure", { className: className, "data-custd-chart": "", "data-custd-part": "response-chart", style: { margin: 0, minWidth: 0, ...style }, children: [_jsx("figcaption", { children: summary }), _jsxs("div", { style: { display: "flex", flexWrap: "wrap", gap: "0.75rem" }, children: [_jsxs("span", { children: [_jsxs("span", { "aria-hidden": "true", style: { color: chartColors.avgMs }, children: ["\u2501", " "] }), averageLabel] }), _jsxs("span", { children: [_jsxs("span", { "aria-hidden": "true", style: { color: chartColors.maxMs }, children: ["\u2504", " "] }), slowestLabel] })] }), _jsxs("div", { style: { display: "grid", gridTemplateColumns: "auto minmax(0, 1fr)", alignItems: "stretch", gap: "0.5rem" }, children: [_jsxs("div", { "aria-hidden": "true", style: { display: "flex", flexDirection: "column", justifyContent: "space-between", fontSize: "0.75rem" }, children: [_jsxs("span", { children: [yMax, " ms"] }), _jsx("span", { children: "0 ms" })] }), _jsx("svg", { viewBox: `0 0 ${WIDTH} ${HEIGHT}`, style: { display: "block", width: "100%", height: HEIGHT }, preserveAspectRatio: "none", role: "img", "aria-label": summary, children: ["avgMs", "maxMs"].map((field) => {
|
|
61
|
+
const color = chartColors[field];
|
|
62
|
+
return (_jsx("g", { "data-series": field, fill: color, stroke: color, children: passing.map((hour, index) => {
|
|
63
|
+
const value = hour[field];
|
|
64
|
+
if (value == null)
|
|
65
|
+
return null;
|
|
66
|
+
const time = Date.parse(hour.hourStart);
|
|
67
|
+
const previous = passing[index - 1];
|
|
68
|
+
const previousValue = previous?.[field];
|
|
69
|
+
const joined = previousValue != null && time - Date.parse(previous.hourStart) === HOUR_MS;
|
|
70
|
+
return (_jsxs("g", { children: [_jsx("title", { children: `${formatTime(hour.hourStart)} · ${field === "avgMs" ? averageLabel : slowestLabel} ${value} ms` }), joined && (_jsx("line", { x1: x(time - HOUR_MS), y1: y(previousValue), x2: x(time), y2: y(value), vectorEffect: "non-scaling-stroke", strokeWidth: 2, strokeDasharray: field === "maxMs" ? "5 3" : undefined })), _jsx("circle", { cx: x(time), cy: y(value), r: 2 })] }, hour.hourStart));
|
|
71
|
+
}) }, field));
|
|
72
|
+
}) })] }), _jsxs("div", { "aria-hidden": "true", style: {
|
|
73
|
+
display: "flex",
|
|
74
|
+
justifyContent: "space-between",
|
|
75
|
+
flexWrap: "wrap",
|
|
76
|
+
gap: "0.5rem",
|
|
77
|
+
fontSize: "0.75rem",
|
|
78
|
+
}, children: [_jsx("span", { children: formatTime(hours[0].hourStart) }), start !== end && _jsx("span", { children: formatTime(hours[hours.length - 1].hourStart) })] }), _jsxs("details", { onToggle: (event) => setShowData(event.currentTarget.open), children: [_jsx("summary", { children: dataLabel }), showData && (_jsx("div", { style: { maxHeight: "16rem", overflow: "auto" }, children: _jsxs("table", { "aria-label": dataLabel, style: { width: "100%" }, children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "Hour" }), _jsxs("th", { scope: "col", children: [averageLabel, " (ms)"] }), _jsxs("th", { scope: "col", children: [slowestLabel, " (ms)"] })] }) }), _jsx("tbody", { children: hours.map((hour) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: formatTime(hour.hourStart) }), _jsx("td", { children: hour.avgMs ?? "—" }), _jsx("td", { children: hour.maxMs ?? "—" })] }, hour.hourStart))) })] }) }))] })] }));
|
|
56
79
|
}
|