Skip to content

feat(render): add pie_chart renderer over Bars shape - #49

Merged
unhappychoice merged 6 commits into
mainfrom
feat/pie-chart-renderer
Apr 21, 2026
Merged

unhappychoice merged 6 commits into
mainfrom
feat/pie-chart-renderer

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Apr 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Renderer: pie_chart

  • New PieChartRenderer wrapping tui-piechart 0.2.8, registered as pie_chart. Accepts Shape::Bars, so the same Bars payload can be rendered as bar_chart or pie_chart purely via config.
  • Slice colours cycle through a fixed 10-entry palette in input order; legend + percentages come from the widget itself.
  • tui-piechart is pinned to =0.2.8 — 0.2.9 bumped the upstream dep to ratatui ^0.30 while we're on 0.29, so loose semver silently resolves into a compile error.
  • Empty Bars short-circuits through the shared empty-state placeholder in render_payload.

Addresses the pie_chart checkbox in #41.

Runtime: clip hint

  • Adding pie_chart to the dogfood config pushed total row height past ~60, exposing a pre-existing footgun: configured heights taller than the terminal were silently clipped by ratatui/crossterm — widgets below the fold just disappeared.
  • Runtime now clamps the inline viewport to term_rows - 1 and, when clipping would occur, sacrifices the bottom row for a right-aligned … +N rows (terminal too short) hint in dim italic. When everything fits, rendering is unchanged.

Dogfood layout

  • bar_chart + pie_chart get their own 2-col row at height 11 so the pie has readable dimensions.
  • sparkline joins the disk row as a 3rd column — gauges + sparklines coexist fine at height 3.

Test plan

  • cargo test — 206 passed (6 new in render::pie_chart, 3 new in runtime::tests for clip hint)
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • Eyeball in a real TTY — pie renders, clip hint appears at the bottom when the terminal is too short

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@unhappychoice has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 30 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 30 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa402723-7590-4a68-89e5-135a094142bb

📥 Commits

Reviewing files that changed from the base of the PR and between 7402f7e and 0a8e2da.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • .splashboard/config.toml
  • Cargo.toml
  • src/render/mod.rs
  • src/render/pie_chart.rs
  • src/runtime.rs
📝 Walkthrough

Walkthrough

The pull request adds a new pie chart rendering capability to the application by introducing the tui-piechart dependency and implementing a PieChartRenderer that converts bar-shaped data into pie chart visualizations with colored slices, labels, and percentage display.

Changes

Cohort / File(s) Summary
Dependency Addition
Cargo.toml
Added tui-piechart dependency pinned to version 0.2.8 as a runtime dependency.
Renderer Registration
src/render/mod.rs
Declared new pie_chart module and registered PieChartRenderer in Registry::with_builtins alongside existing renderers. Updated registry resolution test to assert presence of "pie_chart" in built-in set.
Pie Chart Renderer Implementation
src/render/pie_chart.rs
Implemented PieChartRenderer that accepts Shape::Bars, iterates through bar entries to create PieSlice objects with labels and values, assigns colors from a fixed palette (cycling via modulo), enables legend and percentage display. Includes comprehensive unit tests validating rendering behavior, empty-state handling, shape contract, registry registration, and multi-bar scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

No related PRs were identified in the search results.

Poem

🐰 Bars bow down to pie's sweet charm,
Slices circle, colored warm,
Palette spinning, round and round,
New chart magic comes to town! 🥧✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: adding a new pie_chart renderer for the Bars shape, which aligns with all three modified files (Cargo.toml dependency, module registration, and renderer implementation).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pie-chart-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.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/render/pie_chart.rs`:
- Around line 33-37: The render method currently silently ignores non-Bars
bodies; update the render(&self, frame: &mut Frame, area: Rect, body: &Body,
_opts: &RenderOptions) function to handle mismatched Body variants by rendering
an in-band error string instead of no-oping. Keep the existing match for
Body::Bars to call render_pie(frame, area, d), and add an else/default branch
that draws a visible error message into the provided area (e.g., using the same
Frame drawing/text utilities your renderers use) indicating the unexpected Body
variant; ensure no panics are introduced and the message clearly names the
renderer (pie) and the received Body variant so users see the misconfiguration.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17a654c4-7269-4347-8289-3026319ee738

📥 Commits

Reviewing files that changed from the base of the PR and between 4a32239 and 7402f7e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml
  • src/render/mod.rs
  • src/render/pie_chart.rs

Comment thread src/render/pie_chart.rs
Comment on lines +33 to +37
fn render(&self, frame: &mut Frame, area: Rect, body: &Body, _opts: &RenderOptions) {
if let Body::Bars(d) = body {
render_pie(frame, area, d);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Render an in-band error for unexpected bodies.

Line 34 silently no-ops for non-Bars bodies. render_payload normally prevents this, but the renderer contract still expects visible misconfiguration feedback if called with a mismatched body.

Proposed fix
-use ratatui::{Frame, layout::Rect, style::Color};
+use ratatui::{Frame, layout::Rect, style::Color, widgets::Paragraph};
@@
     fn render(&self, frame: &mut Frame, area: Rect, body: &Body, _opts: &RenderOptions) {
-        if let Body::Bars(d) = body {
-            render_pie(frame, area, d);
-        }
+        let Body::Bars(d) = body else {
+            frame.render_widget(Paragraph::new("pie_chart renderer requires Bars data"), area);
+            return;
+        };
+        render_pie(frame, area, d);
     }
 }

As per coding guidelines, “Renderers must never panic on unknown shapes or mismatches; instead render an in-band error string so users can see misconfiguration without crashing.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/render/pie_chart.rs` around lines 33 - 37, The render method currently
silently ignores non-Bars bodies; update the render(&self, frame: &mut Frame,
area: Rect, body: &Body, _opts: &RenderOptions) function to handle mismatched
Body variants by rendering an in-band error string instead of no-oping. Keep the
existing match for Body::Bars to call render_pie(frame, area, d), and add an
else/default branch that draws a visible error message into the provided area
(e.g., using the same Frame drawing/text utilities your renderers use)
indicating the unexpected Body variant; ensure no panics are introduced and the
message clearly names the renderer (pie) and the received Body variant so users
see the misconfiguration.

unhappychoice and others added 6 commits April 22, 2026 06:17
Wraps `tui-piechart` 0.2.8 (pinned — 0.2.9+ bumps to ratatui 0.30) as a
second renderer on the existing `Bars` shape, so the same fetcher can be
swapped between `render = "bar_chart"` and `render = "pie_chart"` purely
in config. Slice colours cycle through a fixed 10-entry palette in
input order; legend and percentage labels come from the widget itself.

Empty `Bars` payloads continue to short-circuit through the shared
empty-state placeholder in `render_payload`, so pie_chart never has to
handle that case itself.

Addresses the pie_chart checkbox in #41.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Same fetcher, two renderers in one row — the sharpest visual proof of
shape/renderer decoupling since Bars was just a single-renderer shape
before. Row height bumped 5 → 7 to give the pie enough vertical space
for a readable circle; sparkline and bar_chart absorb the extra height
without looking stretched.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bar_chart + pie_chart become a 2-col row at height 11 so the pie has
enough horizontal and vertical room to look like a pie instead of a
smudge. sparkline joins the disk row as a third column — gauges and
sparklines coexist fine at height 3 since both are naturally thin.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Previously, a configured height taller than the terminal was silently
clipped by ratatui/crossterm — widgets below the fold just disappeared
with no indication. The dogfood config grew past ~60 rows as renderers
piled up, making this surprise likely to hit real users too.

Runtime now measures terminal height, clamps the inline viewport to
`term_rows - 1`, and when clipping would occur sacrifices the bottom
row of the viewport to a right-aligned `… +N rows (terminal too short)`
hint in dim italic. When everything fits, rendering is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two clocks in the splash is one clock too many — the quadrant one
already shows the ascii_art renderer on the Lines shape. Saves 6 rows
of total viewport height.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
tui-piechart hides the legend when the inner area is under 10 rows
tall (lib.rs:878). Rounded border eats 2 rows, so h=11 outer → 9
inner → no legend. h=12 brings inner to 10, legend renders.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@unhappychoice
unhappychoice force-pushed the feat/pie-chart-renderer branch from b87737d to 0a8e2da Compare April 21, 2026 21:18
@unhappychoice
unhappychoice merged commit 1a755fd into main Apr 21, 2026
5 checks passed
@unhappychoice
unhappychoice deleted the feat/pie-chart-renderer branch April 21, 2026 21:28
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