@peers-app/peers-ui 0.34.8 → 0.34.10
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/apps-home/apps-home.js +6 -4
- package/dist/components/router.d.ts +1 -1
- package/dist/components/router.js +1 -1
- package/dist/screens/devices/devices-list.d.ts +5 -1
- package/dist/screens/devices/devices-list.js +12 -4
- package/dist/screens/identity/identity-routes.d.ts +2 -1
- package/dist/screens/identity/identity-routes.js +6 -1
- package/dist/screens/monitoring/alerts-tab.d.ts +13 -0
- package/dist/screens/monitoring/alerts-tab.js +68 -0
- package/dist/screens/monitoring/badges.d.ts +25 -0
- package/dist/screens/monitoring/badges.js +68 -0
- package/dist/screens/monitoring/calls-tab.d.ts +30 -0
- package/dist/screens/monitoring/calls-tab.js +104 -0
- package/dist/screens/monitoring/charts/chart-math.d.ts +103 -0
- package/dist/screens/monitoring/charts/chart-math.js +200 -0
- package/dist/screens/monitoring/charts/histogram-chart.d.ts +25 -0
- package/dist/screens/monitoring/charts/histogram-chart.js +74 -0
- package/dist/screens/monitoring/charts/line-chart.d.ts +33 -0
- package/dist/screens/monitoring/charts/line-chart.js +103 -0
- package/dist/screens/monitoring/charts/sparkline.d.ts +30 -0
- package/dist/screens/monitoring/charts/sparkline.js +61 -0
- package/dist/screens/monitoring/charts/use-width.d.ts +9 -0
- package/dist/screens/monitoring/charts/use-width.js +31 -0
- package/dist/screens/monitoring/definition-forms.d.ts +113 -0
- package/dist/screens/monitoring/definition-forms.js +341 -0
- package/dist/screens/monitoring/definitions-tab.d.ts +20 -0
- package/dist/screens/monitoring/definitions-tab.js +110 -0
- package/dist/screens/monitoring/device-picker.d.ts +22 -0
- package/dist/screens/monitoring/device-picker.js +29 -0
- package/dist/screens/monitoring/form-fields.d.ts +76 -0
- package/dist/screens/monitoring/form-fields.js +65 -0
- package/dist/screens/monitoring/format.d.ts +51 -0
- package/dist/screens/monitoring/format.js +150 -0
- package/dist/screens/monitoring/log-lines.d.ts +74 -0
- package/dist/screens/monitoring/log-lines.js +138 -0
- package/dist/screens/monitoring/log-row.d.ts +12 -0
- package/dist/screens/monitoring/log-row.js +23 -0
- package/dist/screens/monitoring/logs-tab.d.ts +15 -0
- package/dist/screens/monitoring/logs-tab.js +256 -0
- package/dist/screens/monitoring/metric-definition-form.d.ts +15 -0
- package/dist/screens/monitoring/metric-definition-form.js +50 -0
- package/dist/screens/monitoring/metrics-tab.d.ts +37 -0
- package/dist/screens/monitoring/metrics-tab.js +149 -0
- package/dist/screens/monitoring/monitoring-routes.d.ts +40 -0
- package/dist/screens/monitoring/monitoring-routes.js +81 -0
- package/dist/screens/monitoring/monitoring-screen.d.ts +17 -0
- package/dist/screens/monitoring/monitoring-screen.js +63 -0
- package/dist/screens/monitoring/overview-tab.d.ts +33 -0
- package/dist/screens/monitoring/overview-tab.js +121 -0
- package/dist/screens/monitoring/telemetry-client.d.ts +48 -0
- package/dist/screens/monitoring/telemetry-client.js +92 -0
- package/dist/screens/monitoring/trigger-form.d.ts +18 -0
- package/dist/screens/monitoring/trigger-form.js +71 -0
- package/dist/screens/monitoring/use-telemetry.d.ts +39 -0
- package/dist/screens/monitoring/use-telemetry.js +120 -0
- package/dist/screens/network-viewer/remote-logs-panel.d.ts +1 -1
- package/dist/screens/network-viewer/remote-logs-panel.js +5 -3
- package/dist/system-apps/index.d.ts +1 -1
- package/dist/system-apps/index.js +5 -5
- package/dist/system-apps/monitoring.app.d.ts +6 -0
- package/dist/system-apps/monitoring.app.js +13 -0
- package/dist/tabs-layout/tabs-state.d.ts +4 -2
- package/dist/tabs-layout/tabs-state.js +23 -11
- package/dist/theme.css +32 -0
- package/package.json +3 -3
- package/dist/screens/console-logs/console-logs-list.d.ts +0 -2
- package/dist/screens/console-logs/console-logs-list.js +0 -284
- package/dist/screens/console-logs/follow-newest.d.ts +0 -11
- package/dist/screens/console-logs/follow-newest.js +0 -17
- package/dist/screens/console-logs/log-display.d.ts +0 -12
- package/dist/screens/console-logs/log-display.js +0 -69
- package/dist/screens/console-logs/log-filters.d.ts +0 -10
- package/dist/screens/console-logs/log-filters.js +0 -8
- package/dist/screens/console-logs/mobile-log-card.d.ts +0 -8
- package/dist/screens/console-logs/mobile-log-card.js +0 -94
- package/dist/screens/console-logs/resizable-table-header.d.ts +0 -14
- package/dist/screens/console-logs/resizable-table-header.js +0 -62
- package/dist/system-apps/console-logs.app.d.ts +0 -2
- package/dist/system-apps/console-logs.app.js +0 -8
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_CHART_SERIES = void 0;
|
|
4
|
+
exports.groupLabel = groupLabel;
|
|
5
|
+
exports.missingIsZero = missingIsZero;
|
|
6
|
+
exports.toTimeSeries = toTimeSeries;
|
|
7
|
+
exports.statOf = statOf;
|
|
8
|
+
exports.niceTicks = niceTicks;
|
|
9
|
+
exports.timeTicks = timeTicks;
|
|
10
|
+
exports.percentileFromBins = percentileFromBins;
|
|
11
|
+
exports.sumOf = sumOf;
|
|
12
|
+
exports.assignColorSlots = assignColorSlots;
|
|
13
|
+
exports.seriesColor = seriesColor;
|
|
14
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
15
|
+
/** At most this many series are drawn, the largest first. */
|
|
16
|
+
exports.MAX_CHART_SERIES = 8;
|
|
17
|
+
/**
|
|
18
|
+
* A group's key and label: `(all)` with no group-by, otherwise `name=value` pairs.
|
|
19
|
+
*
|
|
20
|
+
* @param group - The point's `groupBy` labels.
|
|
21
|
+
*/
|
|
22
|
+
function groupLabel(group) {
|
|
23
|
+
const entries = Object.entries(group);
|
|
24
|
+
if (entries.length === 0)
|
|
25
|
+
return "(all)";
|
|
26
|
+
return entries
|
|
27
|
+
.map(([name, value]) => (entries.length === 1 ? value || "(none)" : `${name}=${value}`))
|
|
28
|
+
.join(", ");
|
|
29
|
+
}
|
|
30
|
+
function groupKey(group) {
|
|
31
|
+
return JSON.stringify(Object.entries(group).sort(([a], [b]) => a.localeCompare(b)));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether a missing bucket means zero (counts and sums) or no data (averages, percentiles, gauges).
|
|
35
|
+
*
|
|
36
|
+
* @param stat - The statistic drawn.
|
|
37
|
+
*/
|
|
38
|
+
function missingIsZero(stat) {
|
|
39
|
+
return stat === "count" || stat === "sum";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Lay a query result out for a time chart: every bucket from `from` to `to`, a series per group,
|
|
43
|
+
* largest first. Like `queryMetric`, it stops at {@link MAX_QUERY_BUCKETS} buckets.
|
|
44
|
+
*
|
|
45
|
+
* @param result - What `queryMetric` returned.
|
|
46
|
+
* @param stat - The statistic to draw.
|
|
47
|
+
*/
|
|
48
|
+
function toTimeSeries(result, stat) {
|
|
49
|
+
const step = peers_sdk_1.RESOLUTION_MS[result.resolution];
|
|
50
|
+
const first = result.from - (result.from % step);
|
|
51
|
+
const times = [];
|
|
52
|
+
for (let t = first; t <= result.to && times.length < peers_sdk_1.MAX_QUERY_BUCKETS; t += step)
|
|
53
|
+
times.push(t);
|
|
54
|
+
const index = new Map(times.map((t, i) => [t, i]));
|
|
55
|
+
const byKey = new Map();
|
|
56
|
+
const zero = missingIsZero(stat);
|
|
57
|
+
for (const point of result.points) {
|
|
58
|
+
const key = groupKey(point.group);
|
|
59
|
+
let series = byKey.get(key);
|
|
60
|
+
if (!series) {
|
|
61
|
+
series = {
|
|
62
|
+
key,
|
|
63
|
+
label: groupLabel(point.group),
|
|
64
|
+
values: times.map(() => (zero ? 0 : undefined)),
|
|
65
|
+
total: 0,
|
|
66
|
+
};
|
|
67
|
+
byKey.set(key, series);
|
|
68
|
+
}
|
|
69
|
+
const i = index.get(point.start);
|
|
70
|
+
const value = statOf(point, stat);
|
|
71
|
+
if (i !== undefined && value !== undefined)
|
|
72
|
+
series.values[i] = value;
|
|
73
|
+
series.total += point.count;
|
|
74
|
+
}
|
|
75
|
+
const series = [...byKey.values()].sort((a, b) => b.total - a.total || a.label.localeCompare(b.label));
|
|
76
|
+
return { times, series };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* One statistic of a point.
|
|
80
|
+
*
|
|
81
|
+
* @param point - A queried bucket.
|
|
82
|
+
* @param stat - The statistic.
|
|
83
|
+
*/
|
|
84
|
+
function statOf(point, stat) {
|
|
85
|
+
return stat === "count" ? point.count : point[stat];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Rounded value-axis ticks from zero (or the lowest value, when it's negative) to at least the
|
|
89
|
+
* highest value: 1, 2 or 5 times a power of ten apart.
|
|
90
|
+
*
|
|
91
|
+
* @param values - Every value drawn.
|
|
92
|
+
* @param count - About how many ticks.
|
|
93
|
+
*/
|
|
94
|
+
function niceTicks(values, count = 4) {
|
|
95
|
+
const finite = values.filter((v) => v !== undefined && Number.isFinite(v));
|
|
96
|
+
const low = Math.min(0, ...finite);
|
|
97
|
+
const high = Math.max(...finite, 0);
|
|
98
|
+
if (high === low) {
|
|
99
|
+
return { min: low, max: low + 1, ticks: [low, low + 1] };
|
|
100
|
+
}
|
|
101
|
+
const rough = (high - low) / count;
|
|
102
|
+
const power = 10 ** Math.floor(Math.log10(rough));
|
|
103
|
+
const step = [1, 2, 5, 10].map((m) => m * power).find((s) => s >= rough) ?? 10 * power;
|
|
104
|
+
const min = Math.floor(low / step) * step;
|
|
105
|
+
const max = Math.ceil(high / step) * step;
|
|
106
|
+
const ticks = [];
|
|
107
|
+
for (let t = min; t <= max + step / 2; t += step)
|
|
108
|
+
ticks.push(Number(t.toPrecision(12)));
|
|
109
|
+
return { min, max, ticks };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Time-axis ticks: about `count` bucket starts, evenly spaced, and how to label them.
|
|
113
|
+
*
|
|
114
|
+
* @param times - The chart's bucket starts.
|
|
115
|
+
* @param count - About how many ticks.
|
|
116
|
+
*/
|
|
117
|
+
function timeTicks(times, count = 5) {
|
|
118
|
+
if (times.length === 0)
|
|
119
|
+
return { ticks: [], label: () => "" };
|
|
120
|
+
const span = times[times.length - 1] - times[0];
|
|
121
|
+
const every = Math.max(1, Math.round(times.length / count));
|
|
122
|
+
const ticks = times.filter((_, i) => i % every === 0);
|
|
123
|
+
const label = (t) => {
|
|
124
|
+
const d = new Date(t);
|
|
125
|
+
const hm = `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
126
|
+
return span > 2 * peers_sdk_1.RESOLUTION_MS.day ? `${d.getMonth() + 1}/${d.getDate()}` : hm;
|
|
127
|
+
};
|
|
128
|
+
return { ticks, label };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A percentile read from histogram bins: the bin the rank falls in, interpolated on a log scale
|
|
132
|
+
* (bins are log-spaced).
|
|
133
|
+
*
|
|
134
|
+
* @param bins - A histogram.
|
|
135
|
+
* @param q - The quantile, 0 to 1 (0.95 for p95).
|
|
136
|
+
* @returns The estimate, or `undefined` for an empty histogram.
|
|
137
|
+
*/
|
|
138
|
+
function percentileFromBins(bins, q) {
|
|
139
|
+
const total = bins.reduce((sum, bin) => sum + bin.count, 0);
|
|
140
|
+
if (total === 0)
|
|
141
|
+
return undefined;
|
|
142
|
+
const rank = q * total;
|
|
143
|
+
let seen = 0;
|
|
144
|
+
for (const bin of bins) {
|
|
145
|
+
if (seen + bin.count >= rank) {
|
|
146
|
+
const within = bin.count === 0 ? 0 : (rank - seen) / bin.count;
|
|
147
|
+
if (bin.low <= 0 || bin.high <= 0)
|
|
148
|
+
return bin.low + (bin.high - bin.low) * within;
|
|
149
|
+
return bin.low * (bin.high / bin.low) ** within;
|
|
150
|
+
}
|
|
151
|
+
seen += bin.count;
|
|
152
|
+
}
|
|
153
|
+
return bins[bins.length - 1].high;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The sum of a series' values, skipping missing buckets.
|
|
157
|
+
*
|
|
158
|
+
* @param values - A series' values.
|
|
159
|
+
*/
|
|
160
|
+
function sumOf(values) {
|
|
161
|
+
return values.reduce((sum, v) => sum + (v ?? 0), 0);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Give each drawn series a color slot (0–7) that it keeps while it stays drawn, so colors follow
|
|
165
|
+
* the series, not their rank: a series keeps its slot from `previous`, and a new one takes the
|
|
166
|
+
* lowest slot no other drawn series holds.
|
|
167
|
+
*
|
|
168
|
+
* @param previous - Slots from the last render (keys to slots).
|
|
169
|
+
* @param keys - The series drawn now, at most {@link MAX_CHART_SERIES}.
|
|
170
|
+
* @returns The slots for `keys`.
|
|
171
|
+
*/
|
|
172
|
+
function assignColorSlots(previous, keys) {
|
|
173
|
+
const slots = new Map();
|
|
174
|
+
const taken = new Set();
|
|
175
|
+
for (const key of keys) {
|
|
176
|
+
const slot = previous.get(key);
|
|
177
|
+
if (slot !== undefined && !taken.has(slot)) {
|
|
178
|
+
slots.set(key, slot);
|
|
179
|
+
taken.add(slot);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const key of keys) {
|
|
183
|
+
if (slots.has(key))
|
|
184
|
+
continue;
|
|
185
|
+
let slot = 0;
|
|
186
|
+
while (taken.has(slot))
|
|
187
|
+
slot++;
|
|
188
|
+
slots.set(key, slot % exports.MAX_CHART_SERIES);
|
|
189
|
+
taken.add(slot);
|
|
190
|
+
}
|
|
191
|
+
return slots;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The CSS color of a series slot, from the theme's `--peers-viz-1` to `--peers-viz-8`.
|
|
195
|
+
*
|
|
196
|
+
* @param slot - 0 to 7.
|
|
197
|
+
*/
|
|
198
|
+
function seriesColor(slot) {
|
|
199
|
+
return `var(--peers-viz-${(slot % exports.MAX_CHART_SERIES) + 1})`;
|
|
200
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IHistogramBin } from "@peers-app/peers-sdk";
|
|
2
|
+
/** Props for {@link HistogramChart}. */
|
|
3
|
+
export interface HistogramChartProps {
|
|
4
|
+
bins: IHistogramBin[];
|
|
5
|
+
/** How a value reads (the bins' edges). */
|
|
6
|
+
formatValue: (value: number) => string;
|
|
7
|
+
/** What the chart shows, for screen readers. */
|
|
8
|
+
label: string;
|
|
9
|
+
height?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A distribution over a range: a column per bin on a log-scale value axis (bins are log-spaced,
|
|
13
|
+
* so each is as wide as the next), counts on a shared axis from zero. Each column shows its range
|
|
14
|
+
* and count on hover or focus.
|
|
15
|
+
*/
|
|
16
|
+
export declare function HistogramChart(props: HistogramChartProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
/**
|
|
18
|
+
* A column anchored square at the baseline, with a 4px rounded top.
|
|
19
|
+
*
|
|
20
|
+
* @param x - Left edge.
|
|
21
|
+
* @param top - The value's y.
|
|
22
|
+
* @param width - Column width.
|
|
23
|
+
* @param base - The baseline's y.
|
|
24
|
+
*/
|
|
25
|
+
export declare function columnPath(x: number, top: number, width: number, base: number): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HistogramChart = HistogramChart;
|
|
4
|
+
exports.columnPath = columnPath;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const chart_math_1 = require("./chart-math");
|
|
8
|
+
const use_width_1 = require("./use-width");
|
|
9
|
+
const MARGIN = { top: 8, right: 16, bottom: 26, left: 56 };
|
|
10
|
+
const MAX_BAR = 24;
|
|
11
|
+
const GAP = 2;
|
|
12
|
+
/**
|
|
13
|
+
* A distribution over a range: a column per bin on a log-scale value axis (bins are log-spaced,
|
|
14
|
+
* so each is as wide as the next), counts on a shared axis from zero. Each column shows its range
|
|
15
|
+
* and count on hover or focus.
|
|
16
|
+
*/
|
|
17
|
+
function HistogramChart(props) {
|
|
18
|
+
const boxRef = (0, react_1.useRef)(null);
|
|
19
|
+
const width = (0, use_width_1.useWidth)(boxRef);
|
|
20
|
+
const height = props.height ?? 200;
|
|
21
|
+
const [hover, setHover] = (0, react_1.useState)();
|
|
22
|
+
const bins = props.bins.filter((bin) => bin.count > 0);
|
|
23
|
+
if (bins.length === 0)
|
|
24
|
+
return (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary small", children: "No values in this range." });
|
|
25
|
+
const plotWidth = Math.max(10, width - MARGIN.left - MARGIN.right);
|
|
26
|
+
const plotHeight = height - MARGIN.top - MARGIN.bottom;
|
|
27
|
+
const low = bins[0].low;
|
|
28
|
+
const high = bins[bins.length - 1].high;
|
|
29
|
+
const log = low > 0;
|
|
30
|
+
const position = (v) => log ? Math.log(v / low) / Math.log(high / low || 2) : (v - low) / (high - low || 1);
|
|
31
|
+
const xAt = (v) => MARGIN.left + position(v) * plotWidth;
|
|
32
|
+
const y = (0, chart_math_1.niceTicks)(bins.map((bin) => bin.count));
|
|
33
|
+
const yAt = (v) => MARGIN.top + plotHeight - (v / (y.max || 1)) * plotHeight;
|
|
34
|
+
const edgeTicks = pickEdges(bins, Math.max(2, Math.floor(plotWidth / 90)));
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ref: boxRef, className: "position-relative", style: { width: "100%" }, children: [(0, jsx_runtime_1.jsxs)("svg", { role: "img", "aria-label": props.label, width: width, height: height, style: { display: "block" }, children: [y.ticks.map((tick) => ((0, jsx_runtime_1.jsxs)("g", { children: [(0, jsx_runtime_1.jsx)("line", { x1: MARGIN.left, x2: MARGIN.left + plotWidth, y1: yAt(tick), y2: yAt(tick), stroke: tick === 0 ? "var(--peers-viz-axis)" : "var(--peers-viz-grid)", strokeWidth: 1 }), (0, jsx_runtime_1.jsx)("text", { x: MARGIN.left - 8, y: yAt(tick), textAnchor: "end", dominantBaseline: "middle", fontSize: 11, fill: "var(--bs-secondary-color)", style: { fontVariantNumeric: "tabular-nums" }, children: tick.toLocaleString() })] }, tick))), edgeTicks.map((edge) => ((0, jsx_runtime_1.jsx)("text", { x: xAt(edge), y: height - 8, textAnchor: "middle", fontSize: 11, fill: "var(--bs-secondary-color)", children: props.formatValue(edge) }, edge))), bins.map((bin, i) => {
|
|
36
|
+
const left = xAt(bin.low);
|
|
37
|
+
const slot = Math.max(1, xAt(bin.high) - left);
|
|
38
|
+
const barWidth = Math.max(1, Math.min(MAX_BAR, slot - GAP));
|
|
39
|
+
const x0 = left + (slot - barWidth) / 2;
|
|
40
|
+
const top = yAt(bin.count);
|
|
41
|
+
const describe = `${props.formatValue(bin.low)} to ${props.formatValue(bin.high)}: ${bin.count.toLocaleString()}`;
|
|
42
|
+
return (
|
|
43
|
+
// biome-ignore lint/a11y/useSemanticElements: an SVG mark can't be a button element.
|
|
44
|
+
(0, jsx_runtime_1.jsxs)("g", { role: "button", tabIndex: 0, "aria-label": describe, onPointerEnter: () => setHover(i), onPointerLeave: () => setHover(undefined), onFocus: () => setHover(i), onBlur: () => setHover(undefined), style: { outline: "none" }, children: [(0, jsx_runtime_1.jsx)("rect", { x: left, y: MARGIN.top, width: slot, height: plotHeight, fill: "transparent" }), (0, jsx_runtime_1.jsx)("path", { d: columnPath(x0, top, barWidth, yAt(0)), fill: (0, chart_math_1.seriesColor)(0), opacity: hover === undefined || hover === i ? 1 : 0.55 })] }, bin.low));
|
|
45
|
+
})] }), hover !== undefined && hover < bins.length ? ((0, jsx_runtime_1.jsxs)("output", { className: "position-absolute card shadow-sm small py-1 px-2", style: { top: MARGIN.top, left: MARGIN.left + 8, pointerEvents: "none", zIndex: 2 }, children: [(0, jsx_runtime_1.jsx)("strong", { style: { fontVariantNumeric: "tabular-nums" }, children: bins[hover].count.toLocaleString() }), " ", (0, jsx_runtime_1.jsxs)("span", { className: "text-body-secondary", children: ["from ", props.formatValue(bins[hover].low), " to ", props.formatValue(bins[hover].high)] })] })) : null] }));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A column anchored square at the baseline, with a 4px rounded top.
|
|
49
|
+
*
|
|
50
|
+
* @param x - Left edge.
|
|
51
|
+
* @param top - The value's y.
|
|
52
|
+
* @param width - Column width.
|
|
53
|
+
* @param base - The baseline's y.
|
|
54
|
+
*/
|
|
55
|
+
function columnPath(x, top, width, base) {
|
|
56
|
+
const r = Math.min(4, width / 2, Math.max(0, base - top));
|
|
57
|
+
return [
|
|
58
|
+
`M${x},${base}`,
|
|
59
|
+
`V${top + r}`,
|
|
60
|
+
`Q${x},${top} ${x + r},${top}`,
|
|
61
|
+
`H${x + width - r}`,
|
|
62
|
+
`Q${x + width},${top} ${x + width},${top + r}`,
|
|
63
|
+
`V${base}`,
|
|
64
|
+
"Z",
|
|
65
|
+
].join("");
|
|
66
|
+
}
|
|
67
|
+
/** Bin edges to label: the first, the last, and evenly spaced ones between. */
|
|
68
|
+
function pickEdges(bins, count) {
|
|
69
|
+
const edges = [...bins.map((bin) => bin.low), bins[bins.length - 1].high];
|
|
70
|
+
if (edges.length <= count)
|
|
71
|
+
return edges;
|
|
72
|
+
const every = Math.ceil((edges.length - 1) / (count - 1));
|
|
73
|
+
return edges.filter((_, i) => i % every === 0 || i === edges.length - 1);
|
|
74
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type IChartSeries } from "./chart-math";
|
|
2
|
+
/** Props for {@link LineChart}. */
|
|
3
|
+
export interface LineChartProps {
|
|
4
|
+
/** Bucket starts, epoch ms, oldest first. */
|
|
5
|
+
times: number[];
|
|
6
|
+
/** The series to draw, each with its color slot. */
|
|
7
|
+
series: Array<IChartSeries & {
|
|
8
|
+
slot: number;
|
|
9
|
+
}>;
|
|
10
|
+
/** How a value reads on the axis and in the tooltip. */
|
|
11
|
+
formatValue: (value: number) => string;
|
|
12
|
+
/** What the chart shows, for screen readers. */
|
|
13
|
+
label: string;
|
|
14
|
+
height?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A time chart: one 2px line per series on a shared value axis from zero, a crosshair that
|
|
18
|
+
* snaps to the nearest bucket and lists every series' value there (also by arrow keys), and a
|
|
19
|
+
* legend when there's more than one series. A missing bucket breaks its line.
|
|
20
|
+
*/
|
|
21
|
+
export declare function LineChart(props: LineChartProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
/** A short stroke of a series' color, which keys it in legends and tooltips. */
|
|
23
|
+
export declare function LineKey(props: {
|
|
24
|
+
slot: number;
|
|
25
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* An SVG path through a series' values, broken where a value is missing.
|
|
28
|
+
*
|
|
29
|
+
* @param values - One per bucket.
|
|
30
|
+
* @param xAt - A bucket's x.
|
|
31
|
+
* @param yAt - A value's y.
|
|
32
|
+
*/
|
|
33
|
+
export declare function linePath(values: Array<number | undefined>, xAt: (i: number) => number, yAt: (v: number) => number): string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineChart = LineChart;
|
|
4
|
+
exports.LineKey = LineKey;
|
|
5
|
+
exports.linePath = linePath;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const chart_math_1 = require("./chart-math");
|
|
9
|
+
const use_width_1 = require("./use-width");
|
|
10
|
+
const MARGIN = { top: 8, right: 16, bottom: 26, left: 64 };
|
|
11
|
+
/**
|
|
12
|
+
* A time chart: one 2px line per series on a shared value axis from zero, a crosshair that
|
|
13
|
+
* snaps to the nearest bucket and lists every series' value there (also by arrow keys), and a
|
|
14
|
+
* legend when there's more than one series. A missing bucket breaks its line.
|
|
15
|
+
*/
|
|
16
|
+
function LineChart(props) {
|
|
17
|
+
const boxRef = (0, react_1.useRef)(null);
|
|
18
|
+
const width = (0, use_width_1.useWidth)(boxRef);
|
|
19
|
+
const height = props.height ?? 240;
|
|
20
|
+
const [hover, setHover] = (0, react_1.useState)();
|
|
21
|
+
const { times, series } = props;
|
|
22
|
+
const plotWidth = Math.max(10, width - MARGIN.left - MARGIN.right);
|
|
23
|
+
const plotHeight = height - MARGIN.top - MARGIN.bottom;
|
|
24
|
+
const y = (0, chart_math_1.niceTicks)(series.flatMap((s) => s.values));
|
|
25
|
+
const xAt = (i) => MARGIN.left + (times.length <= 1 ? plotWidth / 2 : (i / (times.length - 1)) * plotWidth);
|
|
26
|
+
const yAt = (v) => MARGIN.top + plotHeight - ((v - y.min) / (y.max - y.min || 1)) * plotHeight;
|
|
27
|
+
const x = (0, chart_math_1.timeTicks)(times, Math.max(2, Math.floor(plotWidth / 110)));
|
|
28
|
+
const indexOfTime = new Map(times.map((t, i) => [t, i]));
|
|
29
|
+
const nearest = (clientX) => {
|
|
30
|
+
const box = boxRef.current?.getBoundingClientRect();
|
|
31
|
+
if (!box || times.length === 0)
|
|
32
|
+
return undefined;
|
|
33
|
+
const fraction = (clientX - box.left - MARGIN.left) / plotWidth;
|
|
34
|
+
return Math.min(times.length - 1, Math.max(0, Math.round(fraction * (times.length - 1))));
|
|
35
|
+
};
|
|
36
|
+
const onPointerMove = (event) => setHover(nearest(event.clientX));
|
|
37
|
+
const onKeyDown = (event) => {
|
|
38
|
+
if (times.length === 0)
|
|
39
|
+
return;
|
|
40
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
const step = event.key === "ArrowLeft" ? -1 : 1;
|
|
43
|
+
setHover((i) => Math.min(times.length - 1, Math.max(0, (i ?? times.length - 1) + step)));
|
|
44
|
+
}
|
|
45
|
+
else if (event.key === "Escape") {
|
|
46
|
+
setHover(undefined);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const readout = hover === undefined
|
|
50
|
+
? []
|
|
51
|
+
: series
|
|
52
|
+
.map((s) => ({ s, value: s.values[hover] }))
|
|
53
|
+
.filter((row) => row.value !== undefined)
|
|
54
|
+
.sort((a, b) => b.value - a.value);
|
|
55
|
+
const tooltipLeft = hover === undefined ? 0 : xAt(hover);
|
|
56
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-line-chart", children: [(0, jsx_runtime_1.jsxs)("div", { ref: boxRef, className: "position-relative", style: { width: "100%" }, children: [(0, jsx_runtime_1.jsxs)("svg", { role: "img", "aria-label": props.label, width: width, height: height, style: { display: "block" }, children: [y.ticks.map((tick) => ((0, jsx_runtime_1.jsxs)("g", { children: [(0, jsx_runtime_1.jsx)("line", { x1: MARGIN.left, x2: MARGIN.left + plotWidth, y1: yAt(tick), y2: yAt(tick), stroke: tick === y.min ? "var(--peers-viz-axis)" : "var(--peers-viz-grid)", strokeWidth: 1 }), (0, jsx_runtime_1.jsx)("text", { x: MARGIN.left - 8, y: yAt(tick), textAnchor: "end", dominantBaseline: "middle", fontSize: 11, fill: "var(--bs-secondary-color)", style: { fontVariantNumeric: "tabular-nums" }, children: props.formatValue(tick) })] }, tick))), x.ticks.map((tick) => {
|
|
57
|
+
const i = indexOfTime.get(tick) ?? 0;
|
|
58
|
+
return ((0, jsx_runtime_1.jsx)("text", { x: xAt(i), y: height - 8, textAnchor: "middle", fontSize: 11, fill: "var(--bs-secondary-color)", children: x.label(tick) }, tick));
|
|
59
|
+
}), series.map((s) => ((0, jsx_runtime_1.jsx)("path", { d: linePath(s.values, xAt, yAt), fill: "none", stroke: (0, chart_math_1.seriesColor)(s.slot), strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round" }, s.key))), series.map((s) =>
|
|
60
|
+
// A bucket with no neighbors draws no line, so give it a dot.
|
|
61
|
+
s.values.map((v, i) => v !== undefined && s.values[i - 1] === undefined && s.values[i + 1] === undefined ? ((0, jsx_runtime_1.jsx)("circle", { cx: xAt(i), cy: yAt(v), r: 3, fill: (0, chart_math_1.seriesColor)(s.slot) }, `${s.key}:${i}`)) : null)), hover !== undefined && hover < times.length ? ((0, jsx_runtime_1.jsxs)("g", { pointerEvents: "none", children: [(0, jsx_runtime_1.jsx)("line", { x1: xAt(hover), x2: xAt(hover), y1: MARGIN.top, y2: MARGIN.top + plotHeight, stroke: "var(--bs-secondary-color)", strokeWidth: 1 }), readout.map(({ s, value }) => ((0, jsx_runtime_1.jsx)("circle", { cx: xAt(hover), cy: yAt(value), r: 4, fill: (0, chart_math_1.seriesColor)(s.slot), stroke: "var(--bs-body-bg)", strokeWidth: 2 }, s.key)))] })) : null] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "position-absolute border-0 p-0 bg-transparent", "aria-label": `${props.label}: use the left and right arrow keys to read each time's values`, style: {
|
|
62
|
+
left: MARGIN.left,
|
|
63
|
+
top: MARGIN.top,
|
|
64
|
+
width: plotWidth,
|
|
65
|
+
height: plotHeight,
|
|
66
|
+
cursor: "crosshair",
|
|
67
|
+
touchAction: "pan-y",
|
|
68
|
+
}, onPointerMove: onPointerMove, onPointerLeave: () => setHover(undefined), onKeyDown: onKeyDown, onBlur: () => setHover(undefined) }), hover !== undefined && hover < times.length ? ((0, jsx_runtime_1.jsxs)("output", { className: "position-absolute card shadow-sm small py-1 px-2", style: {
|
|
69
|
+
top: MARGIN.top,
|
|
70
|
+
left: tooltipLeft > width / 2 ? undefined : tooltipLeft + 12,
|
|
71
|
+
right: tooltipLeft > width / 2 ? width - tooltipLeft + 12 : undefined,
|
|
72
|
+
pointerEvents: "none",
|
|
73
|
+
maxWidth: 280,
|
|
74
|
+
zIndex: 2,
|
|
75
|
+
}, children: [(0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: new Date(times[hover]).toLocaleString() }), readout.length === 0 ? (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "No data" }) : null, readout.map(({ s, value }) => ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2", children: [(0, jsx_runtime_1.jsx)(LineKey, { slot: s.slot }), (0, jsx_runtime_1.jsx)("strong", { style: { fontVariantNumeric: "tabular-nums" }, children: props.formatValue(value) }), (0, jsx_runtime_1.jsx)("span", { className: "text-body-secondary text-truncate", children: s.label })] }, s.key)))] })) : null] }), series.length > 1 ? (0, jsx_runtime_1.jsx)(Legend, { series: series }) : null] }));
|
|
76
|
+
}
|
|
77
|
+
/** A short stroke of a series' color, which keys it in legends and tooltips. */
|
|
78
|
+
function LineKey(props) {
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)("svg", { width: 14, height: 8, "aria-hidden": "true", style: { flex: "0 0 auto" }, children: (0, jsx_runtime_1.jsx)("line", { x1: 1, x2: 13, y1: 4, y2: 4, stroke: (0, chart_math_1.seriesColor)(props.slot), strokeWidth: 2, strokeLinecap: "round" }) }));
|
|
80
|
+
}
|
|
81
|
+
function Legend(props) {
|
|
82
|
+
return ((0, jsx_runtime_1.jsx)("ul", { className: "list-unstyled d-flex flex-wrap gap-3 small mb-0 mt-2 ms-5", children: props.series.map((s) => ((0, jsx_runtime_1.jsxs)("li", { className: "d-flex align-items-center gap-1 text-body-secondary", children: [(0, jsx_runtime_1.jsx)(LineKey, { slot: s.slot }), (0, jsx_runtime_1.jsx)("span", { className: "text-break", children: s.label })] }, s.key))) }));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* An SVG path through a series' values, broken where a value is missing.
|
|
86
|
+
*
|
|
87
|
+
* @param values - One per bucket.
|
|
88
|
+
* @param xAt - A bucket's x.
|
|
89
|
+
* @param yAt - A value's y.
|
|
90
|
+
*/
|
|
91
|
+
function linePath(values, xAt, yAt) {
|
|
92
|
+
let d = "";
|
|
93
|
+
let drawing = false;
|
|
94
|
+
values.forEach((v, i) => {
|
|
95
|
+
if (v === undefined) {
|
|
96
|
+
drawing = false;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
d += `${drawing ? "L" : "M"}${xAt(i).toFixed(1)},${yAt(v).toFixed(1)}`;
|
|
100
|
+
drawing = true;
|
|
101
|
+
});
|
|
102
|
+
return d;
|
|
103
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** A tile's trend: a value per bucket and when each bucket starts. */
|
|
2
|
+
export interface ITrend {
|
|
3
|
+
/** One per bucket, oldest first; `undefined` where there's no data. */
|
|
4
|
+
values: Array<number | undefined>;
|
|
5
|
+
/** Each bucket's start, epoch ms. */
|
|
6
|
+
times: number[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A trend in words: its peak and when, and the latest value ("peak 12 at 14:00, latest 3 at
|
|
10
|
+
* 15:00"). `undefined` with fewer than two values, when no line is drawn.
|
|
11
|
+
*
|
|
12
|
+
* @param trend - The trend.
|
|
13
|
+
* @param formatValue - How a value reads.
|
|
14
|
+
* @param now - The current time (for tests).
|
|
15
|
+
*/
|
|
16
|
+
export declare function describeTrend(trend: ITrend, formatValue: (value: number) => string, now?: number): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* A tile's trend: a small line in the secondary ink, no axes, with the latest value's dot in the
|
|
19
|
+
* accent. A missing bucket breaks the line. Hovering shows its peak and latest value; the tile
|
|
20
|
+
* names them to keyboard and screen-reader users, and opens the full chart.
|
|
21
|
+
*
|
|
22
|
+
* @param props.values - One per bucket, oldest first.
|
|
23
|
+
* @param props.times - Each bucket's start.
|
|
24
|
+
* @param props.label - What it shows ("Errors per hour").
|
|
25
|
+
* @param props.formatValue - How a value reads.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Sparkline(props: ITrend & {
|
|
28
|
+
label: string;
|
|
29
|
+
formatValue: (value: number) => string;
|
|
30
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeTrend = describeTrend;
|
|
4
|
+
exports.Sparkline = Sparkline;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const format_1 = require("../format");
|
|
7
|
+
const line_chart_1 = require("./line-chart");
|
|
8
|
+
/**
|
|
9
|
+
* A trend in words: its peak and when, and the latest value ("peak 12 at 14:00, latest 3 at
|
|
10
|
+
* 15:00"). `undefined` with fewer than two values, when no line is drawn.
|
|
11
|
+
*
|
|
12
|
+
* @param trend - The trend.
|
|
13
|
+
* @param formatValue - How a value reads.
|
|
14
|
+
* @param now - The current time (for tests).
|
|
15
|
+
*/
|
|
16
|
+
function describeTrend(trend, formatValue, now = Date.now()) {
|
|
17
|
+
let peak;
|
|
18
|
+
let latest;
|
|
19
|
+
let found = 0;
|
|
20
|
+
trend.values.forEach((value, i) => {
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return;
|
|
23
|
+
found++;
|
|
24
|
+
if (peak === undefined || value > trend.values[peak])
|
|
25
|
+
peak = i;
|
|
26
|
+
latest = i;
|
|
27
|
+
});
|
|
28
|
+
if (found < 2 || peak === undefined || latest === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
const at = (i) => (0, format_1.formatClock)(trend.times[i], now);
|
|
31
|
+
const value = (i) => formatValue(trend.values[i]);
|
|
32
|
+
if (trend.values[peak] === 0)
|
|
33
|
+
return `${value(peak)} throughout`;
|
|
34
|
+
return `peak ${value(peak)} at ${at(peak)}, latest ${value(latest)} at ${at(latest)}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A tile's trend: a small line in the secondary ink, no axes, with the latest value's dot in the
|
|
38
|
+
* accent. A missing bucket breaks the line. Hovering shows its peak and latest value; the tile
|
|
39
|
+
* names them to keyboard and screen-reader users, and opens the full chart.
|
|
40
|
+
*
|
|
41
|
+
* @param props.values - One per bucket, oldest first.
|
|
42
|
+
* @param props.times - Each bucket's start.
|
|
43
|
+
* @param props.label - What it shows ("Errors per hour").
|
|
44
|
+
* @param props.formatValue - How a value reads.
|
|
45
|
+
*/
|
|
46
|
+
function Sparkline(props) {
|
|
47
|
+
const width = 120;
|
|
48
|
+
const height = 28;
|
|
49
|
+
const finite = props.values.filter((v) => v !== undefined);
|
|
50
|
+
if (finite.length < 2)
|
|
51
|
+
return null;
|
|
52
|
+
const max = Math.max(...finite, 0);
|
|
53
|
+
const min = Math.min(...finite, 0);
|
|
54
|
+
const xAt = (i) => 2 + (i / (props.values.length - 1)) * (width - 4);
|
|
55
|
+
const yAt = (v) => height - 3 - ((v - min) / (max - min || 1)) * (height - 6);
|
|
56
|
+
const lastIndex = props.values.length - 1;
|
|
57
|
+
const last = props.values[lastIndex];
|
|
58
|
+
const summary = describeTrend(props, props.formatValue);
|
|
59
|
+
const text = summary ? `${props.label}: ${summary}` : props.label;
|
|
60
|
+
return ((0, jsx_runtime_1.jsxs)("svg", { width: width, height: height, role: "img", "aria-label": text, style: { display: "block" }, children: [(0, jsx_runtime_1.jsx)("title", { children: text }), (0, jsx_runtime_1.jsx)("path", { d: (0, line_chart_1.linePath)(props.values, xAt, yAt), fill: "none", stroke: "var(--bs-secondary-color)", strokeWidth: 1.5, strokeLinejoin: "round", strokeLinecap: "round" }), last !== undefined ? ((0, jsx_runtime_1.jsx)("circle", { cx: xAt(lastIndex), cy: yAt(last), r: 3, fill: "var(--peers-viz-1)" })) : null] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* An element's width, kept current as it resizes. Where `ResizeObserver` doesn't exist (tests),
|
|
4
|
+
* it stays at the first measure, or `fallback`.
|
|
5
|
+
*
|
|
6
|
+
* @param ref - The element to measure.
|
|
7
|
+
* @param fallback - The width before the first measure.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useWidth(ref: RefObject<HTMLElement | null>, fallback?: number): number;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useWidth = useWidth;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* An element's width, kept current as it resizes. Where `ResizeObserver` doesn't exist (tests),
|
|
7
|
+
* it stays at the first measure, or `fallback`.
|
|
8
|
+
*
|
|
9
|
+
* @param ref - The element to measure.
|
|
10
|
+
* @param fallback - The width before the first measure.
|
|
11
|
+
*/
|
|
12
|
+
function useWidth(ref, fallback = 600) {
|
|
13
|
+
const [width, setWidth] = (0, react_1.useState)(fallback);
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
const element = ref.current;
|
|
16
|
+
if (!element)
|
|
17
|
+
return;
|
|
18
|
+
const measure = () => {
|
|
19
|
+
const next = Math.floor(element.getBoundingClientRect().width);
|
|
20
|
+
if (next > 0)
|
|
21
|
+
setWidth(next);
|
|
22
|
+
};
|
|
23
|
+
measure();
|
|
24
|
+
if (typeof ResizeObserver === "undefined")
|
|
25
|
+
return;
|
|
26
|
+
const observer = new ResizeObserver(measure);
|
|
27
|
+
observer.observe(element);
|
|
28
|
+
return () => observer.disconnect();
|
|
29
|
+
}, [ref]);
|
|
30
|
+
return width;
|
|
31
|
+
}
|