Repository navigation
feat(render): add pie_chart renderer over Bars shape - #49
Conversation
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe pull request adds a new pie chart rendering capability to the application by introducing the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRsNo related PRs were identified in the search results. Poem
🚥 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 |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (3)
Cargo.tomlsrc/render/mod.rssrc/render/pie_chart.rs
| fn render(&self, frame: &mut Frame, area: Rect, body: &Body, _opts: &RenderOptions) { | ||
| if let Body::Bars(d) = body { | ||
| render_pie(frame, area, d); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
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]>
b87737d to
0a8e2da
Compare
Summary
Renderer: pie_chart
PieChartRendererwrappingtui-piechart0.2.8, registered aspie_chart. AcceptsShape::Bars, so the sameBarspayload can be rendered asbar_chartorpie_chartpurely via config.tui-piechartis pinned to=0.2.8— 0.2.9 bumped the upstream dep toratatui ^0.30while we're on 0.29, so loose semver silently resolves into a compile error.Barsshort-circuits through the shared empty-state placeholder inrender_payload.Addresses the
pie_chartcheckbox in #41.Runtime: clip hint
pie_chartto 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.term_rows - 1and, 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_chartget their own 2-col row at height 11 so the pie has readable dimensions.sparklinejoins the disk row as a 3rd column — gauges + sparklines coexist fine at height 3.Test plan
cargo test— 206 passed (6 new inrender::pie_chart, 3 new inruntime::testsfor clip hint)cargo clippy --all-targets -- -D warnings— cleancargo fmt --all -- --check— clean🤖 Generated with Claude Code