Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/multi-day-axis-date-ticks.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
11 changes: 9 additions & 2 deletions packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — On a multi-day range the first tick uses a different date-time format from every other tick

In the multi-day branch, return 'short' for index 0 as well, so the whole axis uses one date-time format. The daily-or-coarser branch below already does this. As written, the first tick still returns 'normal' (with seconds and a space before AM/PM), so the axis reads Nov 23 12:00:00 AM, Nov 23 12:00PM, Nov 24 12:00AM, … (the PR description's own 'After' row shows this). Update the test at HDXMultiSeriesTimeChart.test.ts:1398 to expect 'short' for index 0.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

return rangeSeconds != null && rangeSeconds > SECONDS_PER_DAY

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Multi-day sub-daily axis mixes normal and short label formats (first tick has seconds, others don't)

When rangeSeconds > SECONDS_PER_DAY, the first tick still returns 'normal' (Nov 23 12:00:00 AM) while every later tick returns 'short' (Nov 23 12:00PM). The axis then shows two different date/time styles, and the widest label sits at the preserved start position (MemoChart.tsx:970 interval="preserveStartEnd"). Every tick already carries the date in this mode, so the first one doesn't need the fuller format. Return 'short' for every index in the multi-day branch, as the daily-granularity branch below already does, and update the unit test (format(0, sevenDays)) and the e2e assertion on first to match.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

? 'short'
: 'time';
}
const wallClock = toWallClock(
new Date(tickSeconds * 1000),
Expand Down
24 changes: 22 additions & 2 deletions packages/app/tests/e2e/features/chart-explorer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
});
},
);

Expand Down
Loading