Skip to content

fix(model-usage): keep the daily tooltip inside the chart, and scope a day from the date range - #427

Merged
Yuyz0112 merged 5 commits into
mainfrom
fix/model-usage-chart-tooltip-and-day-scope
Sep 19, 2026
Merged

Yuyz0112 merged 5 commits into
mainfrom
fix/model-usage-chart-tooltip-and-day-scope

Conversation

@0065paula

Copy link
Copy Markdown
Contributor

The daily chart rendered one line and one tooltip row per API key. A workspace with 15+ keys on a day grew the tooltip to roughly twice the 240px chart, so it covered the plot and spilled out of the card. This rework folds the chart series, moves the day breakdown out of the tooltip, and stops the tables from rendering every row.

Supersedes #417 (top-8 truncation inside the tooltip) — same goal, different lever: #417 trims the tooltip list, this folds the series so the tooltip cannot grow at all. Please close #417 rather than landing both.

What changes

Chart

  • Draws the 8 biggest API keys and folds the rest into one "Other N API keys" series, so the tooltip is bounded at 9 rows (~183px inside the 240px chart) instead of growing with the workspace.
  • Tooltip rows are a single line ("name · description"). The previous two-line row doubled the tooltip height.
  • Clicking a day narrows the date range to that day; the old focusDate state is gone. Chart, both summary cards and the detail table share one scope, and the date control is both the state and the way back (the chart header also offers "Back to ..." — the preset the reader came from, or their own custom window).
  • A single day switches the chart to a distribution across API keys (models when one key is selected): prompt/completion stack as two steps of the same series hue, the tail folds into one grey "Other N (total)" bar, and the chart-type toggle stays for the trend view. Selecting an API key still switches to its model mix.
  • Long user-written key names/descriptions truncate in the axis, legend, tooltip and tables instead of stretching the layout.

Tables

  • By key / by model / per-record page instead of rendering every row — 50+ keys on a day had made the page thousands of pixels tall. The two breakdown cards page at 10 (a glanceable ranking), the per-record table at 50 (a place to hunt for one request).
  • Paging resets on scope changes only, never on the 60s usage poll.
  • PaginationControls gains showPageSize for callers that own the page size, and DateRangePicker shows a single day as one date.

Structure — aggregation lives in pages/model-usage/lib/usage-series.ts (unit tested); the chart moves to pages/model-usage/components/UsageChart.tsx; the page keeps the data, filters and tables.

Verification

  • yarn typecheck, yarn lint, yarn dep-check, knip, node tools/i18n-tracker.cjs, node tools/check-i18n-keys.cjs all pass (the pre-commit hook runs the same set).
  • New tests: 4 for the aggregation/fold, 4 for the page (paging, day scope, returning to a custom window) — 9 total, all passing.
  • yarn test: 1891 passed, 2 failed. Both failures are Timestamp.render.test.tsx (fixed-date/timezone expectations) and fail identically on main at 2dcdde8 — unrelated to this change.

Notes for review

  • Palette: the page keeps its existing 10-colour SERIES_COLORS; with TOP_K = 8 plus "other" nothing repeats. The style guide only defines five --nt-chart-series-* tokens, so whether this page should adopt them (and with which extended set) is a separate decision — flagging rather than deciding it here.
  • Overlap with fix(model-usage,ai-traces): show an API key as one line in the filter #423: both touch pages/model-usage/list.tsx. This branch is based on main, so whichever merges second needs a small rebase.

@codecov-commenter

codecov-commenter commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

codex and others added 5 commits September 19, 2026 17:52
…a day from the date range

The daily chart rendered one line and one tooltip row per API key. A workspace
with 15+ keys on a day grew the tooltip to twice the 240px chart, so it covered
the plot and spilled out of the card.

Chart
- Draw the eight biggest API keys and fold the rest into a single "Other N API
  keys" series, so the tooltip is bounded at nine rows (~183px) instead of
  growing with the workspace.
- Tooltip rows are one line each ("name · description"); the previous two-line
  row doubled the tooltip height.
- Drop the old `focusDate` state: clicking a day now narrows the date range to
  that day, so the chart, both summary cards and the detail table share one
  scope, and the date control is both the state and the way back.
- A single day switches the chart to a distribution across API keys (or models
  when one key is selected): prompt/completion stack in two steps of the series
  hue, the tail folds into "Other N (total)", and the header offers the range
  back — the preset the reader came from, or their own custom window. The
  chart-type toggle stays for the trend view, and picking an API key still
  switches to its model mix.
- Long user-written key names/descriptions truncate in the axis, legend,
  tooltip and tables instead of stretching the layout.

Tables
- The by-key, by-model and per-record tables page instead of rendering every
  row: 50+ keys on one day had made the page thousands of pixels tall. The two
  breakdown cards page at 10, the per-record table at 50, and paging resets on
  scope changes only — never on the 60s usage poll.
- `PaginationControls` gains `showPageSize` for callers that own the page size,
  and the date control shows a single day as one date instead of a range.

Aggregation lives in `pages/model-usage/lib/usage-series.ts` with unit tests;
the chart moves to `pages/model-usage/components/UsageChart.tsx`.
Patch coverage on the usage-page rework sat at 74%, with the chart tooltips,
the legend/axis callbacks, the filter controls and `PaginationControls`'s
page-size branch never executed.

- `UsageChart.test.tsx` renders both tooltips directly: contributor ordering
  with "other" pinned last, a series recharts reports without a dataKey, a
  missing value, a category with and without a description, and the inactive
  state. `shortLabel` is checked on both sides of its length cutoff.
- The page test fakes recharts with the smallest objects that still call back
  into the page, so the day-click handler, the legend toggle (including the
  empty-key guard), the axis formatters and the chart-type switch are exercised
  through the page rather than mocked out. It also covers the three
  `EndpointTypeBadge` states, the model-name filter, the endpoint-type filter
  and a workspace row with no display name, description, model or endpoint.
- `PaginationControls.test.tsx` covers first/previous/next/last and the
  rows-per-page control, plus the hidden variant the usage cards use.

The reworked files now report 100% of statements, functions and lines, and 83%
of branches, when the four focused test files run.
The tracker keeps a content-hash ledger of every tracked file, and the previous
commit staged `src/` only, so the updated `.i18n-tracker.lock` was left behind
and CI read the file as un-reviewed. No source change.
…or states

The remaining patch coverage gaps were state combinations the page fakes never
reached:

- a single day scoped to one key, which titles the chart by model;
- the first load, when the chart shows its loader and the tables are empty;
- a window with no usage at all, which every panel and table has to render;
- a failed usage request, which surfaces above the tables.

The usage hook is now stubbed through a reassignable state object so each case
can render the page in the state it is about.
Keep #423's reviewed hashes for ai-traces/list.tsx and ApiKeyLabel.tsx,
which this branch does not touch, and record the merged model-usage
list.tsx.
@Yuyz0112
Yuyz0112 force-pushed the fix/model-usage-chart-tooltip-and-day-scope branch from 303da62 to 3d18c12 Compare September 19, 2026 09:54
@Yuyz0112
Yuyz0112 merged commit 61a069b into main Sep 19, 2026
1 check passed
@Yuyz0112
Yuyz0112 deleted the fix/model-usage-chart-tooltip-and-day-scope branch September 19, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants