Repository navigation
feat(render): add chart_histogram - #122
Conversation
Adds `chart_histogram`, a `NumberSeries` renderer that visualises the distribution of values (count per bucket) instead of the time-axis sequence that `chart_sparkline` shows. Same shape, complementary view. Bins auto-sized to `ceil(sqrt(n))` clamped to `[5, area width]`; an explicit `bins = N` overrides. Adds an optional inline `label` prefix matching `chart_sparkline`'s convention. `min == max` series collapse to a single bar so degenerate inputs still render. Closes the `chart_histogram` checkbox under the `chart_*` family in #61. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughA new histogram chart renderer is added to visualize numeric series data with configurable labels and bin counts. The renderer integrates into the existing rendering system, includes unit tests, and updates snapshot testing configuration. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #122 +/- ##
==========================================
+ Coverage 78.37% 78.59% +0.21%
==========================================
Files 95 96 +1
Lines 17312 17858 +546
==========================================
+ Hits 13569 14036 +467
- Misses 3743 3822 +79
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/render/chart_histogram.rs (1)
66-97: Histogram rendering logic is correct; minor readability nit.
opts.label.as_deref()is called twice (Line 73 and Line 74). Binding once keeps intent obvious and avoids relying on the optimizer:♻️ Optional refactor
- let (label_area, chart_area) = split_for_label(area, opts.label.as_deref()); - if let Some(label) = opts.label.as_deref() { + let label = opts.label.as_deref(); + let (label_area, chart_area) = split_for_label(area, label); + if let Some(label) = label { frame.render_widget( Paragraph::new(Line::from(format!("{label} "))).style(Style::default().fg(theme.text)), label_area, ); }Otherwise: bar styling, layout split, and the chart-area early-return ordering all check out. The
data.values.is_empty()guard duplicates the centralized check inrender_payload, but it’s justified for direct invocation in tests, so leaving it is fine.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/render/chart_histogram.rs` around lines 66 - 97, In render_histogram, avoid calling opts.label.as_deref() twice: bind it once (e.g., let label = opts.label.as_deref()) and use that variable in the split_for_label call and the subsequent if block; update the split_for_label invocation to use label and the Paragraph::new/if-check to reference label so the code is clearer and does not duplicate the as_deref() call.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/render/chart_histogram.rs`:
- Around line 66-97: In render_histogram, avoid calling opts.label.as_deref()
twice: bind it once (e.g., let label = opts.label.as_deref()) and use that
variable in the split_for_label call and the subsequent if block; update the
split_for_label invocation to use label and the Paragraph::new/if-check to
reference label so the code is clearer and does not duplicate the as_deref()
call.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 772be2c1-5abe-4225-9c6d-58e56cf06ccd
📒 Files selected for processing (3)
src/render/chart_histogram.rssrc/render/mod.rsxtask/src/snapshots.rs
Adds an opt-in `axis_labels = true` option to `chart_histogram`. When on, the renderer reserves the top row for the peak bucket count and the bottom row for the min / max value range, so readers can recover the numeric axis without inspecting the input. Auto-skipped when the chart area is shorter than 4 rows so the bars themselves keep usable space — narrow widgets degrade gracefully back to "shape-only" display. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two follow-up fixes in one: - Stretch each bar to `bars_area.width / bins` cells so the histogram occupies its slot instead of clustering one cell per bar at the left edge. Axis labels (when on) align to `bins * bar_width`, so `max` sits at the rightmost bar's right edge rather than past empty padding. - Lift every non-zero count up to `ceil(peak / (8 * height))` before passing it to ratatui's `BarChart`. ratatui floors `count * 8 * height / peak` for sub-cell glyphs, so a single sample under a peak of 51 in a 4-row chart used to round to zero and disappear, leaving the long tail of a skewed distribution invisible while the `max` axis label still pointed at it. Trade 1-vs-2 resolution at sub-cell heights for "this bin has data" being readable. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Adds
chart_histogram, a new renderer for the existingNumberSeriesshape. Wherechart_sparklineplots values along a time axis (position → value),chart_histogramplots their distribution (bucket → count). Same data, complementary lens.Ticks the
chart_histogramcheckbox under thechart_*family in #61. No new shape, no new dependencies.Reference
number_seriesOptions
labelbinsceil(sqrt(n))clamped to[5, area width]; explicit values clamp to[1, area width].axis_labelsTheme tokens
texttext_dimaxis_labels = true).Compatible fetchers
number_seriesbasic_read_store,git_commits_activity,github_action_historyNotes
NumberSeriesdefault renderer stayschart_sparkline; histogram is opt-in viarender = "chart_histogram".bar_width = bars_area.width / bins) so the histogram occupies its column instead of clustering at one cell per bar.count * 8 * height < peak) get lifted to the smallest visible value, so acount=1bin under apeak=51mid-bin still shows as▁instead of vanishing into space and making themaxaxis label point at empty padding.min == maxcollapses to a single bar so degenerate inputs render rather than vanish.theme.textfor bars,theme.text_dimfor axis labels) — no fill/draintonesemantics, since "value distribution" has no canonical good/bad direction.Test plan
cargo test(23 chart_histogram tests + the rest of the suite green)cargo clippy --all-targets -- -D warningscargo fmt --all -- --checkcargo run --bin splashboard -- catalog renderer chart_histogramlists the options + compatible fetchers.splashboard/dashboard.tomlagainst synthetic right-skewed data (clear histogram silhouette, axis labels visible, long-tail bins rendered) andgit_commits_activity(zero-skewed real data — known pathological case)🤖 Generated with Claude Code