Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Label the alert frequency axis with round local times

rcourtman590355bcab12
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index a4790de047..76e951c32b 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -1567,6 +1567,17 @@ exact counts. The legend counts critical, warnings and info (info only when
present) over the current window and bar selection
(`AlertHistoryFrequencyCard.test.tsx`, `alertHistoryModel.test.ts`).
+The chart's axis names round local times. Buckets start at the window start
+(now minus the range), so labelling bucket edges printed times such as
+`11:50`, and an hour without minutes reads as a bare number in 24-hour
+locales (`8 Oct, 11`). `formatAlertAxisTickLabel` writes an hour with its
+minutes, and `buildAlertAxisTicks` moves each inner tick to
+`nextAlertAxisBoundary`, the next whole bucket step within the day (or the
+next local midnight for date-only labels), at that time's true position. The
+first tick keeps the exact window start the range line shows, the last reads
+`Now`, and the buckets, bar tooltips and counts are unchanged
+(`alertHistoryModel.test.ts`).
+
The desktop alert history table sizes each column for its content instead of
giving all visible columns an equal share. Each density is sized for the
narrowest card it serves (600px, 800px, 1024px and 1280px): Time (the column
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 3a76dcb893..cf4bed8717 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -8955,6 +8955,14 @@ cover desktop, intermediate, phone and short landscape layouts. These checks
establish presentation and interaction, not installed Proxmox permissions or
released acceptance.
+### Time axes label round times
+
+A chart axis built from fixed-width buckets anchored at "now minus the range"
+labels its inner ticks at the next round local time at their true positions,
+not at the raw bucket edges, and any label that shows an hour shows its
+minutes, so 24-hour locales never print a bare hour after a date
+(`nextAlertAxisBoundary` in `alertHistoryModel.ts`).
+
### Docker drawers expose reduced helper coverage without actions
The Docker host drawer consumes the canonical optional `collectionMode` field.
diff --git a/frontend-modern/browser-verification/a6ceac933a5824c7.json b/frontend-modern/browser-verification/a6ceac933a5824c7.json
new file mode 100644
index 0000000000..2a71a4abb2
--- /dev/null
+++ b/frontend-modern/browser-verification/a6ceac933a5824c7.json
@@ -0,0 +1,36 @@
+{
+ "version": 1,
+ "base_sha": "e669e825d4a34f8979d60eec7962561bd6927bef",
+ "verified_at": "2026-10-15T11:00:00Z",
+ "result": "passed",
+ "changed_paths": [
+ "frontend-modern/src/features/alerts/alertHistoryModel.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/features/alerts/alertHistoryModel.ts": "83da081f99c2b5c0f64aecbd8c73813a38d2388f88117c8f5109c27b2b68a6ed"
+ },
+ "routes": [
+ "/alerts/history"
+ ],
+ "viewports": [
+ {
+ "width": 1280,
+ "height": 800
+ },
+ {
+ "width": 375,
+ "height": 812
+ }
+ ],
+ "states": [
+ "Before (main, en-GB): the default 7-day axis read \"8 Oct, 11 | 10 Oct, 05 | 11 Oct, 23\" and the range line \"8 Oct, 11 -> Now\"; 30-day ticks sat at bucket edges near noon",
+ "After: 7d \"8 Oct, 11:54 | 10 Oct, 06:00 | 12 Oct, 00:00 | 13 Oct, 18:00 | Now\"; 24h ticks on the hour; 30d \"15 Sept | 24 Sept | 2 Oct | 10 Oct | Now\" at local midnights; all time dated with the year",
+ "No label overlap at 640px or 1280px (the chart keeps a minimum width and scrolls); US-length labels measured at the same positions keep 75px or more apart",
+ "Phone 375px shows three ticks (8 Oct, 11:55 | 12 Oct, 00:00 | Now) with no page-level horizontal overflow",
+ "A clock change that repeats an hour no longer stacks two ticks on one boundary (unit test under Europe/London)"
+ ],
+ "interactions": [
+ "Switched Last 24h, Last 7d, Last 30d and All time and read every visible axis label and its bounds",
+ "Resized to 640px and 375px and re-read the labels"
+ ]
+}
diff --git a/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov0712.test.ts b/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov0712.test.ts
index 7d42d01f66..f63f6ddf86 100644
--- a/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov0712.test.ts
+++ b/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov0712.test.ts
@@ -781,11 +781,31 @@ describe('formatAlertAxisTickLabel', () => {
locale: 'en-US',
});
expect(label).toContain('Mar 22');
- // The mid-range branch sets only `hour` (no `minute`), so the time-of-day
- // token is a bare hour like "09 AM" with no colon.
- expect(label).toMatch(/09/);
expect(label).toMatch(/AM|PM/);
- expect(label).not.toMatch(/\d{1,2}:\d{2}/);
+ expect(label).toMatch(/\d{1,2}:\d{2}/);
+ });
+
+ // The default 7-day chart labels its axis by hour. With only the hour, a
+ // 24-hour locale printed "8 Oct, 11", a date followed by a bare number.
+ it('writes the hour as a time in 24-hour locales', () => {
+ const ts = new Date(2026, 9, 8, 11, 0, 0).getTime();
+ for (const locale of ['en-GB', 'fr-FR', 'en-US']) {
+ const label = formatAlertAxisTickLabel({
+ timestamp: ts,
+ bucketHours: 6,
+ totalHours: 7 * 24,
+ locale,
+ });
+ expect(label).toMatch(/11:00/);
+ }
+ expect(
+ formatAlertAxisTickLabel({
+ timestamp: ts,
+ bucketHours: 6,
+ totalHours: 7 * 24,
+ locale: 'en-GB',
+ }),
+ ).toBe('8 Oct, 11:00');
});
it('omits the hour for a mid-range total with a large bucket and long span', () => {
diff --git a/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov2.test.ts b/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov2.test.ts
index ef0d600bfc..c88f25f83a 100644
--- a/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov2.test.ts
+++ b/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.branchcov2.test.ts
@@ -780,11 +780,9 @@ describe('formatAlertAxisTickLabel', () => {
locale: 'en-US',
});
expect(label).toContain('Mar 22');
- // The mid-range branch sets only `hour` (no `minute`), so the time-of-day
- // token is a bare hour like "09 AM" with no colon.
- expect(label).toMatch(/09/);
+ // The hour carries its minutes so it reads as a time in every locale.
expect(label).toMatch(/AM|PM/);
- expect(label).not.toMatch(/\d{1,2}:\d{2}/);
+ expect(label).toMatch(/\d{1,2}:\d{2}/);
});
it('omits the hour for a mid-range total with a large bucket and long span', () => {
diff --git a/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.test.ts b/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.test.ts
index 7e58376b64..7f62e0a08c 100644
--- a/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.test.ts
+++ b/frontend-modern/src/features/alerts/__tests__/alertHistoryModel.test.ts
@@ -5,6 +5,7 @@ import type { Resource } from '@/types/resource';
import {
applyAlertHistoryWindow,
+ buildAlertAxisTicks,
buildAlertHistoryItems,
buildAlertHistoryParams,
buildAlertTrends,
@@ -12,6 +13,7 @@ import {
formatAlertHistoryDuration,
getAlertBucketDurationLabel,
getAlertHistoryRowCopy,
+ nextAlertAxisBoundary,
type HistoryItem,
} from '../alertHistoryModel';
@@ -254,3 +256,84 @@ describe('alert history rows for held threshold alerts', () => {
expect(getAlertHistoryRowCopy(item, () => NOW).text).toBe('Node temperature at 95.0°C');
});
});
+
+// The frequency axis labelled raw bucket edges, which follow the window start
+// (now minus the range): the default week read "8 Oct, 11" in 24-hour locales
+// and a 30-day bar dated "1 Oct" began at 1 Oct 11:50.
+describe('alert frequency axis', () => {
+ const at = (month: number, day: number, hour: number, minute = 0) =>
+ new Date(2026, month - 1, day, hour, minute).getTime();
+
+ it('finds the next round local time an axis label can name exactly', () => {
+ expect(nextAlertAxisBoundary(at(10, 8, 11, 50), 6, 168)).toBe(at(10, 8, 12));
+ expect(nextAlertAxisBoundary(at(10, 8, 12), 6, 168)).toBe(at(10, 8, 12));
+ expect(nextAlertAxisBoundary(at(10, 8, 23, 50), 6, 168)).toBe(at(10, 9, 0));
+ expect(nextAlertAxisBoundary(at(10, 14, 18, 50), 1, 24)).toBe(at(10, 14, 19));
+ expect(nextAlertAxisBoundary(at(10, 1, 11, 50), 24, 720)).toBe(at(10, 2, 0));
+ });
+
+ it('labels inner ticks with round times at their true positions', () => {
+ vi.useFakeTimers();
+ const now = at(10, 15, 11, 50);
+ vi.setSystemTime(now);
+ try {
+ for (const [range, expectTime] of [
+ ['24h', true],
+ ['7d', true],
+ ['30d', false],
+ ] as const) {
+ const trends = buildAlertTrends([], range, now);
+ const ticks = buildAlertAxisTicks(trends, 'en-GB');
+ const start = trends.bucketTimes[0];
+ const total = trends.buckets.length * trends.bucketSize * 60 * 60 * 1000;
+ expect(ticks.at(-1)?.label).toBe('Now');
+ const inner = ticks.slice(1, -1);
+ expect(inner.length).toBeGreaterThan(0);
+ for (const tick of inner) {
+ const time = new Date(Math.round(start + tick.position * total));
+ expect(time.getMinutes()).toBe(0);
+ if (expectTime) {
+ expect(tick.label).toMatch(/\d{2}:00$/);
+ } else {
+ expect(time.getHours()).toBe(0);
+ expect(tick.label).not.toMatch(/:/);
+ }
+ }
+ }
+ // The first tick is the window start the range line names.
+ const week = buildAlertAxisTicks(buildAlertTrends([], '7d', now), 'en-GB');
+ expect(week[0]).toMatchObject({ position: 0, label: '8 Oct, 11:50' });
+ expect(week[1].label).toBe('10 Oct, 06:00');
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ // When clocks go back, 01:30 happens twice and both bucket edges snap to
+ // 02:00; the axis must not draw two ticks on top of each other.
+ it('keeps ticks apart across a repeated hour', () => {
+ const previousTz = process.env.TZ;
+ process.env.TZ = 'Europe/London';
+ vi.useFakeTimers();
+ const now = Date.parse('2026-10-25T04:30:00Z');
+ vi.setSystemTime(now);
+ try {
+ const earliest: HistoryItem = {
+ id: 'a-1',
+ startTime: '2026-10-24T23:30:00Z',
+ } as HistoryItem;
+ const trends = buildAlertTrends([earliest], 'all', now);
+ expect(trends.bucketSize).toBe(1);
+ const ticks = buildAlertAxisTicks(trends, 'en-GB');
+ const positions = ticks.map((tick) => tick.position);
+ for (let index = 1; index < positions.length; index += 1) {
+ expect(positions[index]).toBeGreaterThan(positions[index - 1]);
+ }
+ expect(new Set(ticks.map((tick) => tick.label)).size).toBe(ticks.length);
+ } finally {
+ vi.useRealTimers();
+ if (previousTz === undefined) delete process.env.TZ;
+ else process.env.TZ = previousTz;
+ }
+ });
+});
diff --git a/frontend-modern/src/features/alerts/alertHistoryModel.ts b/frontend-modern/src/features/alerts/alertHistoryModel.ts
index 0ddb250cf3..9c6de73654 100644
--- a/frontend-modern/src/features/alerts/alertHistoryModel.ts
+++ b/frontend-modern/src/features/alerts/alertHistoryModel.ts
@@ -576,6 +576,40 @@ export function getAlertBucketDurationLabel(bucketHours: number) {
return `${bucketHours} hour${bucketHours === 1 ? '' : 's'}`;
}
+// Whether an axis label at this scale names a time of day as well as a date.
+const axisLabelShowsTime = (bucketHours: number, totalHours: number): boolean =>
+ totalHours <= 48 || (totalHours <= 24 * 90 && (bucketHours <= 12 || totalHours <= 24 * 14));
+
+/**
+ * The first round local time at or after `timestamp` that an axis label can
+ * name exactly: the next whole step of `bucketHours` within the day when the
+ * label shows a time, otherwise the next local midnight. Bucket edges follow
+ * the window start (now minus the range), so labelling them directly printed
+ * times such as "11:50" and dated a day bar from its noon-ish edge.
+ */
+export function nextAlertAxisBoundary(
+ timestamp: number,
+ bucketHours: number,
+ totalHours: number,
+): number {
+ const date = new Date(timestamp);
+ const stepHours =
+ axisLabelShowsTime(bucketHours, totalHours) && bucketHours < 24 && 24 % bucketHours === 0
+ ? bucketHours
+ : 24;
+ const midnight = new Date(date.getFullYear(), date.getMonth(), date.getDate());
+ for (let hour = 0; hour <= 24; hour += stepHours) {
+ const boundary = new Date(
+ midnight.getFullYear(),
+ midnight.getMonth(),
+ midnight.getDate(),
+ hour,
+ ).getTime();
+ if (boundary >= timestamp) return boundary;
+ }
+ return new Date(midnight.getFullYear(), midnight.getMonth(), midnight.getDate() + 1).getTime();
+}
+
export function formatAlertAxisTickLabel({
timestamp,
bucketHours,
@@ -600,16 +634,14 @@ export function formatAlertAxisTickLabel({
const date = new Date(timestamp);
const options: Intl.DateTimeFormatOptions = {};
- if (totalHours <= 48) {
- options.month = 'short';
- options.day = 'numeric';
- options.hour = '2-digit';
- options.minute = '2-digit';
- } else if (totalHours <= 24 * 90) {
+ if (totalHours <= 24 * 90) {
options.month = 'short';
options.day = 'numeric';
- if (bucketHours <= 12 || totalHours <= 24 * 14) {
+ if (axisLabelShowsTime(bucketHours, totalHours)) {
+ // Minutes make the hour read as a time: 24-hour locales render a
+ // bare hour as "8 Oct, 11", which looks like a stray number.
options.hour = '2-digit';
+ options.minute = '2-digit';
}
} else {
options.year = 'numeric';
@@ -663,8 +695,17 @@ export function buildAlertAxisTicks(trends: AlertTrendSeries, locale: string): A
const ticks: Array<{ position: number; label: string }> = [];
for (let index = 0; index < trends.bucketTimes.length; index += step) {
- const ts = trends.bucketTimes[index];
+ // Inner ticks sit at the round time they name, at its true position; the
+ // first tick below keeps the exact window start the range line shows.
+ const ts =
+ index === 0
+ ? trends.bucketTimes[index]
+ : nextAlertAxisBoundary(trends.bucketTimes[index], bucketHours, totalHours);
const position = Math.min(1, Math.max(0, (ts - start) / (totalDurationMs || 1)));
+ // Two edges can snap to one boundary when a clock change repeats an hour;
+ // keep inner ticks clear of each other and of the end tick.
+ const previous = ticks.at(-1)?.position ?? -1;
+ if (index > 0 && (position >= 0.97 || position <= previous + 0.02)) continue;
ticks.push({
position,
label: formatAlertAxisTickLabel({