ui: add stacked histograms for token activity#826
Conversation
Add stacked histogram support to the UI token activity charts so histogram bars can be grouped by model (stacked) or shown as a flat distribution.
- Add calculateStackedHistogramData, StackedMetric and stackedHistogramColors to ui-svelte/src/lib/histogram.ts.
- Introduce StackedHistogramData/segments types in ui-svelte/src/lib/types.ts.
- Extend TokenHistogram.svelte to render stacked bars, legend, and a stacked/flat switch (prop: stacked); improve axis/legend layout and add safety checks for empty data.
- Update ActivityStats.svelte to compute stacked vs flat histogram data, add a UI toggle to switch modes, and keep the existing collapse control.
- Add comprehensive unit tests for calculateStackedHistogramData in ui-svelte/src/lib/histogram.test.ts.
ui: add stacked histograms for token activity
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR adds stacked-by-model histogram support alongside existing flat histograms. It introduces new types to model stacked bin/segment data, implements per-model histogram calculation and percentile logic, updates the TokenHistogram component to render both flat and stacked variants, and wires ActivityStats to toggle between modes with a persisted UI control. ChangesStacked histogram feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
❌ Failed to create PR with unit tests: AGENT_CHAT: Failed to open pull request |
|
The PR description image shows the llama-swap Activity page with two stacked histogram charts ("Prompt Processing" and "Token Generation") where bars are color-coded by model (chat=blue, smart=orange, task=green), along with summary stats (requests, cached/processed/generated tokens) and a detailed data table below. Apologies for the failed unit test generation, (´・ω・`) 🐇 ✅ Action performedFull review finished. |
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) |
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
❌ Failed to create PR with unit tests: AGENT_CHAT: Failed to open pull request |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ui-svelte/src/components/ActivityStats.svelte`:
- Around line 44-65: The icon-only toggle buttons that flip $histogramStacked
and $histogramCollapsed currently only use title for labeling; update each
button to include an explicit accessible name and state by adding an aria-label
(matching the user-facing title text) and aria-pressed bound to the
corresponding store boolean (aria-pressed={$histogramStacked} for the stacked
toggle and aria-pressed={$histogramCollapsed} for the collapsed toggle) so
assistive tech can identify and announce both the control and its current state.
In `@ui-svelte/src/components/TokenHistogram.svelte`:
- Around line 109-115: The per-segment minimum height (the ternary that returns
2px) inflates stacked bars and makes totals exceed barHeight; in
TokenHistogram.svelte change segHeight to use segFraction * barHeight (remove
the seg.count > 0 ? 2 : 0 fallback) and update the segY reducer to also sum
Math.max(frac * barHeight, 0) or simply frac * barHeight (remove the s.count > 0
? 2 : 0 logic) so segment heights and Y offsets are purely proportional and
stacked totals never exceed barHeight.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8ca927e4-8521-47af-bfa8-de8865e3d26a
📒 Files selected for processing (5)
ui-svelte/src/components/ActivityStats.svelteui-svelte/src/components/TokenHistogram.svelteui-svelte/src/lib/histogram.test.tsui-svelte/src/lib/histogram.tsui-svelte/src/lib/types.ts
Address two CodeRabbit review findings from PR mostlygeek#826. - Add aria-label and aria-pressed to icon-only toggle buttons in ActivityStats.svelte for screen reader support - Remove per-segment 2px minimum height in TokenHistogram.svelte that caused stacked bars to exceed barHeight; replace with purely proportional segment heights fixes review feedback on mostlygeek#826
…-stack-overflow ui: fix accessibility and stacked histogram overflow
Add stacked histogram support to the UI token activity charts so histogram bars can be grouped by model (stacked, new) or shown as a flat distribution (existing).
- Add calculateStackedHistogramData, StackedMetric and stackedHistogramColors to ui-svelte/src/lib/histogram.ts.
- Introduce StackedHistogramData/segments types in ui-svelte/src/lib/types.ts.
- Extend TokenHistogram.svelte to render stacked bars, legend, and a stacked/flat switch (prop: stacked); improve axis/legend layout and add safety checks for empty data.
- Update ActivityStats.svelte to compute stacked vs flat histogram data, add a UI toggle to switch modes, and keep the existing collapse control.
- Add comprehensive unit tests for calculateStackedHistogramData in ui-svelte/src/lib/histogram.test.ts.
Example:
