Skip to content

fix(app): label year-scale time charts by month and year - #3832

Open
MikeShi42 wants to merge 3 commits into
mainfrom
cursor/multi-year-chart-date-format-1e39
Open

MikeShi42 wants to merge 3 commits into
mainfrom
cursor/multi-year-chart-date-format-1e39

Conversation

@MikeShi42

@MikeShi42 MikeShi42 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Time charts covering a year or more were hard to read. X-axis ticks left out the year and sometimes included a time of day, because Recharts' automatic time ticks land at arbitrary instants on our seconds-valued axis. Hover and pinned tooltips also left out the year.

When the chart's date range is at least a year:

  • X-axis ticks sit on month starts in the display time zone and read like Mar 2024. The step (1/2/3/6/12… months) is the smallest one that fits the plot width. Recharts' minTickGap is lowered for these ticks so it doesn't drop some of them and leave the rest unevenly spaced. Compact-mode labels stay centered on these ticks.
  • Tooltips (hover and pinned) show 2024-03-18 for daily or coarser buckets that start at midnight in the display zone. Otherwise they show the date, year, and time, for example Nov 7 2025 7:00:00 PM for a UTC-aligned bucket viewed in New York. A date alone would name the previous day there without saying so.

Shorter ranges keep their current formats. The new monthYear and isoDate formats are added to formatDate in common-utils.

Screenshots or video

Dashboard tile, count of 2 years of synthetic logs, auto granularity, UTC:

Before After
Before: ticks without year After: month and year ticks
Before: tooltip without year After: tooltip with ISO date

Same point in America/New_York (after), where the bucket starts at 7 PM local time:

After: New York tooltip keeps the time

Expanded tile (after):

After: expanded tile with bimonthly ticks

Last 7 days, unchanged (after):

After: 7-day range keeps existing formats

How to reproduce

Starting point: yarn dev with synthetic logs spread over 2 years in otel_logs. The local table has a 1-day TTL, so remove it first (ALTER TABLE default.otel_logs REMOVE TTL). Any source with data covering a year or more also works.

On main:

  1. Create a dashboard with a line tile: Logs source, count, auto granularity.
  2. Set the time range to cover 2 years, for example a Start time two years ago.
  3. The x-axis ticks read like Nov 13, Jul 11 with no year, and hovering shows Nov 8 12:00:00 AM.

On this branch:

  1. Repeat the steps above.
  2. The ticks read Jan 2025, Jul 2025, Jan 2026, … and in UTC the hover and pinned tooltips read 2025-11-08.
  3. Switch the display time zone to America/New_York. The same point reads Nov 7 2025 7:00:00 PM.
  4. Switch to "Last 7 days". The formats are the same as on main.

How to test on Vercel preview

Preview routes: /chart

Steps:

  1. Choose the demo logs source and a line chart of count, with granularity set to auto.
  2. Set the time range to the last 2 years and run the query.
  3. Verify that the x-axis tick labels show a month and year (for example Jan 2026) and no time of day.
  4. Hover a point and verify that the tooltip header includes the year.
  5. Set the time range to the last 1 hour, run the query, and verify that the tick labels show times of day as before.

References

  • Related PRs: none
Open in Web Open in Cursor 

Fixes HDX-6198


Note

Low Risk
Chart labeling and formatting only; shorter time ranges keep existing behavior, with substantial unit test coverage for timezone and tick logic.

Reviewed by Cursor Bugbot for commit fa6af2f. Bugbot is set up for automated code reviews on this repo. Configure here.

Time charts spanning a year or more now place x-axis ticks on month starts
labelled like 'Mar 2024', and tooltips include the year ('2024-03-18' for
daily or coarser buckets). Shorter ranges keep their existing formats.

Co-authored-by: Mike Shi <mike@hyperdx.io>
@MikeShi42
MikeShi42 requested a review from a team as a code owner November 25, 2026 20:59
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 25, 2026 9:24pm UTC
hyperdx-storybook Ready Ready Preview Nov 25, 2026 9:24pm UTC

Request Review

@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Diff size: 281 production lines changed (Tier 2 max: < 250)
  • Cross-layer change: touches frontend (packages/app) + shared utils (packages/common-utils)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 10
  • Production lines changed: 281 (+ 207 in test files, excluded from tier calculation)
  • Branch: cursor/multi-year-chart-date-format-1e39
  • Author: MikeShi42

To override this classification, remove the review/tier-3 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.11%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

if (!isYearScaleRange(dateRange)) {
return 'normal';
}
return convertGranularityToSeconds(granularity) >= 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.

🔴 P1 — isoDate tooltip shows the wrong day for UTC-aligned daily buckets in zones west of UTC

Buckets are UTC-aligned (see the getXAxisTickDateFormat doc and its midnight check just below). So in America/New_York the 1 day bucket at 2025-11-08T00:00Z gets the tooltip 2025-11-07, with no time to show the shift, where main showed Nov 7 7:00:00 PM. Apply the same midnight-in-zone check the x-axis uses: return isoDate only when the label is at local midnight, otherwise withYear. That means getTooltipDateFormat needs the label seconds and the time zone, or it should return a formatter. Also add a non-UTC test case; the current tests only use dateRange and granularity.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in a250f8b. The tooltip now uses isoDate only when the bucket starts at midnight in the display zone, using the same check as the x-axis. Otherwise it shows withYear, so a New York user sees Nov 7 2025 7:00:00 PM. I added non-UTC test cases.

minTickGap={100}
minTickGap={xAxisTicks ? MONTH_TICK_MIN_GAP_PX : 100}
tick={
compactXAxisLabels

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 — Compact x-axis anchoring assumes the first and last ticks sit at the plot edges, which month-start ticks do not

renderCompactXTick uses compactTickAnchor, which left-anchors the first tick and right-anchors the last. With getMonthStartTicks those ticks are inside the plot (e.g. Jan 2025 on a Nov 2024–Nov 2026 range), so their labels drift off their tick marks. This is used via compactXAxisLabels (TraceRedMetricsChart). Center the labels when xAxisTicks is set, or anchor only ticks that fall on the domain bounds.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in a250f8b. Compact labels stay centered when month-start ticks are in use. Recharts' preserveStartEnd still shifts an edge label inward if it would overflow.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 1 P3

1 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom.

🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/app/src/components/DBTimeChart/DBTimeChart.tsx:662 — Tooltip date-format rule is computed separately in DBTimeChart and in MemoChart → MemoChart's getTooltipLabelDateFormat (MemoChart.tsx:607) already calls getTooltipDateFormat with isYearScaleRange(dateRange), granularity and useDisplayTimeZone(). DBTimeChart rebuilds the same call inline, with its own useDisplayTimeZone hook, just for the pinned overlay. That gives the hover and pinned tooltips two sources of truth that must be kept in sync by hand. Fix: have MemoChart expose its callback, either by putting the format on ActiveClickPayload or by passing getDateFormat up through the pin handler. DBTimeChart then reuses it instead of recomputing it.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 478 passed • 1 skipped • 1064s

Status Count
✅ Passed 478
❌ Failed 0
⚠️ Flaky 10
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is a presentation-only change (x-axis tick + tooltip date labels for charts spanning ≥ 1 year) with no auth, data, query, or contract surface touched. Both prior Cursor Bugbot findings (year-scale tooltip date, compact-tick edge clipping) are confirmed resolved in the current HEAD. The new date math is well covered by unit tests, including DST and non-UTC zones.

🟡 P2 — recommended

  • packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts:458 — the step-selection loop in getMonthStartTicks only escalates through MONTH_TICK_STEPS up to 120 months, then returns the last computed set even when it still exceeds maxTicks; rendered with the tightened MONTH_TICK_MIN_GAP_PX of 16, the MMM yyyy labels can overlap. The oversized-return branch is also untested. Reachable only on multi-decade ranges (~20–30yr) at narrow plot widths, which is unrealistic for observability data, but the branch is an unguarded new code path.
    • Fix: when no step brings the count to <= maxTicks, subsample the coarsest step's ticks down to maxTicks (or return undefined to defer to Recharts' width-based gap), and add a test for that branch.
    • adversarial, testing, correctness
🔵 P3 nitpicks (5)
  • packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts:478 — isYearScaleRange's parameter type readonly [Date, Date] | Readonly<[Date, Date]> writes the same type twice (Readonly<[Date, Date]> resolves to readonly [Date, Date]).
    • Fix: collapse the union to a single readonly [Date, Date], which already accepts the mutable tuples callers pass.
    • kieran-typescript
  • packages/app/src/HDXMultiSeriesTimeChart/axisTicks.ts:390 — MIN_MONTH_TICK_SPACING_PX (100, tick-capacity math) and MONTH_TICK_MIN_GAP_PX (16, Recharts minTickGap) share the MONTH_TICK_*_PX shape but serve unrelated roles, and MemoChart.tsx:943 hardcodes a separate literal 100 for the non-year-scale gap.
    • Fix: rename the constants by role and name the inline 100 so the distinction is explicit.
    • maintainability
  • packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx:607 — three near-identical names describe one concept: the prop getDateFormat, the local callback getTooltipLabelDateFormat, and the helper getTooltipDateFormat.
    • Fix: align the prop and local callback names so the indirection reads as a single concept.
    • maintainability
  • packages/app/src/components/DBTimeChart/DBTimeChart.tsx:667 — the hover path (MemoChart) and pinned path (DBTimeChart) each independently assemble the same { yearScale: isYearScaleRange(dateRange), granularity, timeZone } argument for getTooltipDateFormat, so a signature change must be mirrored in two places.
    • Fix: extract a single wrapper that derives the date-format getter from (dateRange, granularity, timeZone) and reuse it in both call sites.
    • maintainability
  • packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx:471 — before the chart is measured (containerWidth === 0), getMonthStartTicks returns undefined, so Recharts picks arbitrary-instant ticks while xTickFormatter still applies monthYear, briefly labeling mid-month instants as e.g. Mar 2024; it self-corrects on the next (debounced) resize. Cosmetic first-paint transient.
    • Fix: suppress the monthYear label (or the XAxis) until xAxisTicks is defined.
    • correctness, julik-frontend-races

Reviewers (10): correctness, adversarial, testing, maintainability, project-standards, agent-native, learnings-researcher, kieran-typescript, julik-frontend-races, previous-comments.

Testing gaps:

  • No test exercises the getMonthStartTicks no-step-fits fallback branch, nor the Math.max(2, …) maxTicks floor for sub-200px plots.
  • The renderCompactXTick month-start edge-anchor override (middle for interior ticks, compactTickAnchor for domain-bound ticks) is render-callback logic with no coverage; extracting it to a pure helper would make it unit-testable.
  • The DBTimeChart pinned-tooltip dateFormat wiring (the activeLabel != null branch) is integration-only; both callees are unit-tested in isolation.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

…cal midnight

UTC-aligned daily buckets start before midnight in zones west of UTC, so a
date-only tooltip named the previous day. Show the date only when the bucket
starts at midnight in the display zone, and center compact x-axis labels on
month-start ticks.

Co-authored-by: Mike Shi <mike@hyperdx.io>
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fa6af2f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Patch
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

granularity,
timeZone: displayTimeZone,
}),
[dateRange, granularity, displayTimeZone],

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 — Making the tooltip callback depend on the dateRange array undoes the memoized tooltip element

getTooltipLabelDateFormat depends on dateRange. DBTimeChart.tsx:224 notes the tile config is a fresh object on every render, and useTimeChartSettings memoizes on that config, so dateRange is a new array each time the parent renders. That rebuilds the tooltip content element whose memo exists to avoid exactly this (comment at MemoChart.tsx:613). Fix: depend on the yearScale boolean (already computed at line 468) plus granularity and time zone, and pass yearScale to the helper instead of dateRange.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in fa6af2f. getTooltipDateFormat now takes the yearScale boolean, and the resolver depends on yearScale, granularity and time zone instead of the dateRange array.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a250f8b. Configure here.

…emo stable

Compact month-start labels that land on a domain bound are anchored to it
again so they don't clip. The tooltip format resolver now depends on the
year-scale flag rather than the dateRange array, which is a new array on
each parent render.

Co-authored-by: Mike Shi <mike@hyperdx.io>
}: XAxisTickContentProps) => {
const textAnchor = compactTickAnchor(index, visibleTicksCount);
const tickSeconds = Number(payload.value);
const textAnchor =

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 — Compact mode centres month ticks that sit near, but not on, a domain bound, so edge labels clip on narrow charts

Compact mode exists so edge labels stay inside narrow plots, such as the side-by-side RED tiles. With month ticks, only a tick exactly equal to xAxisDomain[0] or xAxisDomain[1] keeps the start/end anchor. Take "Last 1 year" ending Nov 25: the last tick is Nov 1, about 6% of the plot width from the right edge, roughly 18px on a 300px plot. A centred label like Nov 2026 (about 55px) then runs past the SVG's right edge. Fix: keep compactTickAnchor for the first and last ticks whenever the tick is within half a label width (or about 50px) of the plot bound, and centre only the interior ticks.

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

@security-ai-gate-reviewer security-ai-gate-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto-approved by the AI review gate on fa6af2f. Details in the approver's comment on this pull request.

@security-ai-gate-reviewer

Copy link
Copy Markdown

AI review gate — auto-approved

fa6af2fedbf1 is approved by security-ai-gate-reviewer[bot], an automated identity, not a human. The approval stands on the required AI review: Cursor Bugbot concluded green on this commit and the AI review gate is SUCCESS (its own comment has the verdict), and the change touches no path that requires a human reviewer. It is bound to this commit: a new push dismisses it and the approver re-evaluates.

History (latest 5 heads, newest first)

  • fa6af2fedbf1 approved — green: Cursor Bugbot

This branch was successfully deployed

2 active deployments
Preview – hyperdx-storybook — fa6af2fe Deployed Nov 25, 2026 by vercel[bot]
Preview – hyperdx-oss — fa6af2fe Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants