Skip to content

feat(render): add chart_histogram - #122

Merged
unhappychoice merged 3 commits into
mainfrom
feat/chart-histogram-renderer
Apr 26, 2026
Merged

unhappychoice merged 3 commits into
mainfrom
feat/chart-histogram-renderer

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Apr 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds chart_histogram, a new renderer for the existing NumberSeries shape. Where chart_sparkline plots values along a time axis (position → value), chart_histogram plots their distribution (bucket → count). Same data, complementary lens.

Ticks the chart_histogram checkbox under the chart_* family in #61. No new shape, no new dependencies.

Reference

  • Accepts: number_series
  • Animates: no

Options

Option Type Required Default Description
label string no — Optional inline prefix rendered to the left of the histogram bars.
bins positive integer no auto Number of buckets the input is binned into. Auto picks ceil(sqrt(n)) clamped to [5, area width]; explicit values clamp to [1, area width].
axis_labels bool no false Render the value range (min / max) along the bottom edge and the peak bucket count along the top edge. Auto-skipped when the chart area is shorter than 4 rows so bars keep usable space.

Theme tokens

Key Description
text Bar fill colour.
text_dim Axis label colour (when axis_labels = true).

Compatible fetchers

Shape Fetchers
number_series basic_read_store, git_commits_activity, github_action_history

Notes

  • NumberSeries default renderer stays chart_sparkline; histogram is opt-in via render = "chart_histogram".
  • Bars stretch to fill the slot (bar_width = bars_area.width / bins) so the histogram occupies its column instead of clustering at one cell per bar.
  • Long-tail bins below ratatui's sub-cell render threshold (count * 8 * height < peak) get lifted to the smallest visible value, so a count=1 bin under a peak=51 mid-bin still shows as ▁ instead of vanishing into space and making the max axis label point at empty padding.
  • min == max collapses to a single bar so degenerate inputs render rather than vanish.
  • Color stays neutral (theme.text for bars, theme.text_dim for axis labels) — no fill/drain tone semantics, 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 warnings
  • cargo fmt --all -- --check
  • cargo run --bin splashboard -- catalog renderer chart_histogram lists the options + compatible fetchers
  • Smoke-tested via .splashboard/dashboard.toml against synthetic right-skewed data (clear histogram silhouette, axis labels visible, long-tail bins rendered) and git_commits_activity (zero-skewed real data — known pathological case)

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A 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

Cohort / File(s) Summary
Histogram Renderer Implementation
src/render/chart_histogram.rs
New ChartHistogramRenderer struct implementing the Renderer trait. Handles bucketing u64 values into equal-width ranges, converting buckets to ratatui Bars, rendering via themed BarChart, with optional labels and configurable/auto-clamped bin counts. Includes comprehensive unit tests for rendering safety, bucket correctness, clamping logic, and option parsing.
Renderer System Integration
src/render/mod.rs
Registers ChartHistogramRenderer in the builtin Registry, adds module declaration, updates registry tests, and introduces bins: Option<u16> field to RenderOptions for histogram bin configuration via render.bins.
Snapshot Testing Config
xtask/src/snapshots.rs
Adds canvas sizing match arm for histogram renderer previews to use (40, 6) dimensions instead of default (40, 5).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A histogram hops into view,
With bars that buckle and bin anew,
Labels dance left, colors theme-bright,
Numbers series rendered just right! 📊✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(render): add chart_histogram' clearly and directly describes the main change: adding a new chart_histogram renderer. It is concise, specific, and accurately reflects the primary objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/chart-histogram-renderer

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.46835% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.59%. Comparing base (6dd5606) to head (9db60bf).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/render/chart_histogram.rs 97.45% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
src/render/mod.rs 89.38% <100.00%> (+0.05%) ⬆️
src/render/chart_histogram.rs 97.45% <97.45%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai 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.

🧹 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 in render_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

📥 Commits

Reviewing files that changed from the base of the PR and between 7e6d795 and db3f15c.

📒 Files selected for processing (3)
  • src/render/chart_histogram.rs
  • src/render/mod.rs
  • xtask/src/snapshots.rs

unhappychoice and others added 2 commits April 26, 2026 09:33
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]>
@unhappychoice
unhappychoice merged commit 21f8596 into main Apr 26, 2026
7 checks passed
@unhappychoice
unhappychoice deleted the feat/chart-histogram-renderer branch April 26, 2026 01:14
@unhappychoice unhappychoice mentioned this pull request Apr 26, 2026
28 of 73 tasks
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.

1 participant