From f6ca10186fc6361859dfe0d86b3e6f937e14bc75 Mon Sep 17 00:00:00 2001 From: jplorier Date: Mon, 30 Nov 2026 15:47:56 -0300 Subject: [PATCH 1/2] fix(app): show dates on x-axis ticks over multi-day ranges below daily granularity Below daily granularity only the first x-axis tick carried the date, so on a range longer than a day (e.g. last 7 days at 12 hour granularity) every later tick repeated a bare time of day. getXAxisTickDateFormat now takes the chart's range and, when it spans more than a day, formats every tick after the first with the date and time ('short'). Ranges within a day are unchanged. Follow-up to #3779, which fixed daily granularity and left this case out of scope. Fixes #3867 --- .changeset/multi-day-axis-date-ticks.md | 8 +++++ .../src/HDXMultiSeriesTimeChart/MemoChart.tsx | 4 ++- .../__tests__/HDXMultiSeriesTimeChart.test.ts | 29 +++++++++++++++++++ .../src/HDXMultiSeriesTimeChart/axisTicks.ts | 11 +++++-- 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 .changeset/multi-day-axis-date-ticks.md diff --git a/.changeset/multi-day-axis-date-ticks.md b/.changeset/multi-day-axis-date-ticks.md new file mode 100644 index 000000000..753cee2a3 --- /dev/null +++ b/.changeset/multi-day-axis-date-ticks.md @@ -0,0 +1,8 @@ +--- +'@hyperdx/app': patch +--- + +fix: show the date on every x-axis tick of time charts below daily granularity +when the range spans more than a day (e.g. last 7 days at 12 hour granularity). +Those ticks repeated only the time of day after the first one; they now show the +date and time. diff --git a/packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx b/packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx index 09d364016..3b6c460f8 100644 --- a/packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx +++ b/packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx @@ -503,6 +503,7 @@ export const MemoChart = memo(function MemoChart({ const formatTime = useFormatTime(); const displayTimeZone = useDisplayTimeZone(); + const rangeSeconds = (dateRange[1].getTime() - dateRange[0].getTime()) / 1000; const xTickFormatter = useCallback( (value: number, index: number) => { return formatTime(value * 1000, { @@ -511,10 +512,11 @@ export const MemoChart = memo(function MemoChart({ index, granularity, timeZone: displayTimeZone, + rangeSeconds, }), }); }, - [formatTime, granularity, displayTimeZone], + [formatTime, granularity, displayTimeZone, rangeSeconds], ); // Compact mode: anchor the first label to the start and the last to the end diff --git a/packages/app/src/HDXMultiSeriesTimeChart/__tests__/HDXMultiSeriesTimeChart.test.ts b/packages/app/src/HDXMultiSeriesTimeChart/__tests__/HDXMultiSeriesTimeChart.test.ts index 23fe5c85c..8f2f7a4cf 100644 --- a/packages/app/src/HDXMultiSeriesTimeChart/__tests__/HDXMultiSeriesTimeChart.test.ts +++ b/packages/app/src/HDXMultiSeriesTimeChart/__tests__/HDXMultiSeriesTimeChart.test.ts @@ -1385,6 +1385,35 @@ describe('getXAxisTickDateFormat', () => { expect(format(1)).toBe('time'); }); + it('adds the date to every tick below daily granularity over a multi-day range', () => { + const format = (index: number, rangeSeconds: number) => + getXAxisTickDateFormat({ + tickSeconds: utcMidnight, + index, + granularity: '12 hour', + timeZone: 'Etc/UTC', + rangeSeconds, + }); + const sevenDays = 7 * 24 * 60 * 60; + expect(format(0, sevenDays)).toBe('normal'); + expect(format(1, sevenDays)).toBe('short'); + expect(format(5, sevenDays)).toBe('short'); + }); + + it('keeps time-only ticks below daily granularity when the range fits in a day', () => { + for (const rangeSeconds of [60 * 60, 24 * 60 * 60]) { + expect( + getXAxisTickDateFormat({ + tickSeconds: utcMidnight, + index: 1, + granularity: '1 hour', + timeZone: 'Etc/UTC', + rangeSeconds, + }), + ).toBe('time'); + } + }); + it.each(['1 day', '7 day', '30 day'])( 'shows only the date on every midnight tick at %s granularity', granularity => { diff --git a/packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts b/packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts index 16e9ea370..1216fc076 100644 --- a/packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts +++ b/packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts @@ -370,7 +370,9 @@ const SECONDS_PER_DAY = 24 * 60 * 60; /** * Format for an x-axis tick label. Below daily granularity the first tick - * carries the date and the rest only the time. At daily granularity or coarser + * carries the date and the rest only the time, unless the chart's range + * (`rangeSeconds`) spans more than a day: then the time of day repeats across + * ticks, so every tick carries the date and time. At daily granularity or coarser * every tick carries the date, plus the time when the bucket does not start at * midnight in `timeZone` (buckets are UTC-aligned, so this happens in most * zones). An undefined `timeZone` means the browser's zone. @@ -380,14 +382,19 @@ export function getXAxisTickDateFormat({ index, granularity, timeZone, + rangeSeconds, }: { tickSeconds: number; index: number; granularity: string; timeZone: string | undefined; + rangeSeconds?: number; }): DateFormat { if (convertGranularityToSeconds(granularity) < SECONDS_PER_DAY) { - return index === 0 ? 'normal' : 'time'; + if (index === 0) return 'normal'; + return rangeSeconds != null && rangeSeconds > SECONDS_PER_DAY + ? 'short' + : 'time'; } const wallClock = toWallClock( new Date(tickSeconds * 1000), From 50d794b1bd87d12bf3a10fb4893e3c54e444e8a3 Mon Sep 17 00:00:00 2001 From: Drew Davis Date: Tue, 1 Dec 2026 13:20:19 -0500 Subject: [PATCH 2/2] fix: Fix test --- .../tests/e2e/features/chart-explorer.spec.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/app/tests/e2e/features/chart-explorer.spec.ts b/packages/app/tests/e2e/features/chart-explorer.spec.ts index 5c8713282..b2bf6747d 100644 --- a/packages/app/tests/e2e/features/chart-explorer.spec.ts +++ b/packages/app/tests/e2e/features/chart-explorer.spec.ts @@ -531,11 +531,11 @@ test.describe( expect(new Set(labels).size).toBe(labels.length); }); - test('keeps time-only ticks after the first below daily granularity', async ({ + test('keeps time-only ticks after the first below daily granularity within a day', async ({ page, }) => { const chartExplorerPage = new ChartExplorerPage(page); - await runTimeChart(chartExplorerPage, 2, '1 Hour Granularity'); + await runTimeChart(chartExplorerPage, 0.5, '1 Hour Granularity'); await expect .poll( @@ -550,6 +550,26 @@ test.describe( expect(label).toMatch(TIME_ONLY_LABEL); } }); + + test('shows the date on every tick below daily granularity over a multi-day range', async ({ + page, + }) => { + const chartExplorerPage = new ChartExplorerPage(page); + await runTimeChart(chartExplorerPage, 2, '1 Hour Granularity'); + + await expect + .poll( + async () => (await chartExplorerPage.getTimeChartXAxisLabels())[1], + { timeout: 15000 }, + ) + .toMatch(DATE_AND_SHORT_TIME_LABEL); + const [first, ...rest] = + await chartExplorerPage.getTimeChartXAxisLabels(); + expect(first).toMatch(DATE_AND_TIME_LABEL); + for (const label of rest) { + expect(label).toMatch(DATE_AND_SHORT_TIME_LABEL); + } + }); }, );