Repository navigation
feat(render): list_ranking renderer for Bars shape - #125
Conversation
Top-N ranking treatment for the existing `Bars` shape. Sibling to `chart_bar`: same data, text-first presentation with rank prefix and right-aligned value column. Reuses `style` / `max_items` / `align` options on `RenderOptions` (no new fields). `style = "medal"` decorates the top three with 🥇 / 🥈 / 🥉. Refs #41 / #61 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new list-ranking renderer for Bars that sorts bars descending, optionally truncates to max items, and emits aligned per-row text with configurable rank prefix (number/medal/none) and horizontal alignment. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 #125 +/- ##
==========================================
+ Coverage 78.74% 79.00% +0.25%
==========================================
Files 96 97 +1
Lines 17935 18191 +256
==========================================
+ Hits 14123 14371 +248
- Misses 3812 3820 +8
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/render/list_ranking.rs (1)
142-156: Optional: label/value width measured in chars, prefix in display cells — wide-char labels misalign the value column.
column_widthsusesdisplay_widthfor the prefix (treats medals as 2 cells) butchars().count()forlabelandvalue.pad_right/pad_leftare also char-count-based, so the renderer is internally consistent for ASCII. As soon as a label contains a wide codepoint (CJK ingit_contributorsnames, an emoji language flag fromgithub_languages, etc.), one char ≠ one cell and the right-aligned value column will visually drift across rows.If you'd rather not pull in
unicode-width, consider routing label/value through the samedisplay_widthhelper (extending it as needed) so all three columns share one width model.♻️ Sketch
fn column_widths(prefixes: &[String], rows: &[(String, u64)]) -> Widths { Widths { prefix: prefixes.iter().map(|p| display_width(p)).max().unwrap_or(0), label: rows .iter() - .map(|(l, _)| l.chars().count()) + .map(|(l, _)| display_width(l)) .max() .unwrap_or(0), value: rows .iter() - .map(|(_, v)| v.to_string().chars().count()) + .map(|(_, v)| display_width(&v.to_string())) .max() .unwrap_or(0), } }
pad_left/pad_rightwould need the same swap to keep the math honest.As per coding guidelines: "Use minimal comments; well-named functions should explain the code. Add comments only when the why is non-obvious: hidden constraints, subtle invariants, or workarounds" — the existing
display_widthcomment already calls out the wcwidth assumption, so reusing it here keeps that invariant in one place.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/render/list_ranking.rs` around lines 142 - 156, column_widths currently computes prefix width with display_width but uses chars().count() for label and value, causing misalignment with wide characters; update column_widths to call display_width for the label and value arms (use display_width(l) and display_width(&v.to_string())) so all three columns share the same cell-width model, and then update pad_left/pad_right to measure padding using display_width rather than char counts to keep alignment consistent; reference functions: column_widths, display_width, pad_left, pad_right.
🤖 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/list_ranking.rs`:
- Around line 142-156: column_widths currently computes prefix width with
display_width but uses chars().count() for label and value, causing misalignment
with wide characters; update column_widths to call display_width for the label
and value arms (use display_width(l) and display_width(&v.to_string())) so all
three columns share the same cell-width model, and then update
pad_left/pad_right to measure padding using display_width rather than char
counts to keep alignment consistent; reference functions: column_widths,
display_width, pad_left, pad_right.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e33f4233-36a2-4b7a-8083-2d69d3d1a281
📒 Files selected for processing (2)
src/render/list_ranking.rssrc/render/mod.rs
CI clippy enforces `unnecessary_sort_by` which my local toolchain didn't trigger. Stable-sort semantics are preserved so the ties-preserve-input-order test still holds. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
list_rankingrenderer (familylist_*) consuming the existingBarsshape.<rank> <label> <value>rows with rank-prefix and value columns aligned across rows. Sibling tochart_bar— same shape, text-first treatment.style/max_items/alignonRenderOptions(no new fields, no shape changes).style = "medal"decorates the podium with 🥇 / 🥈 / 🥉, falling back to numeric prefixes for 4th place onward.Ticks the
list_rankingcheckbox underlist_*in #61. Refs #41.Reference (auto-generated)
barsOptions
max_itemsstylenumber(default) emits1./2./3..medalemits 🥇 / 🥈 / 🥉 for the top three then numbers for the rest.noneomits the prefix.alignTheme tokens
texttext_dimCompatible fetchers
barsbasic_read_store,code_todos,git_contributors,github_contributors_monthly,github_languages,system_disk_usageOut of scope
▲ +3) —BarsData::Bardoesn't carry a delta field today, so this would require a shape extension. Deferred for a follow-up if/when fetchers want to emit period-over-period change.████ 142) — keepslist_rankingfocused on the text-rank treatment; visual bars stay withchart_bar.Test plan
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test(601 passed)git_contributorsacrossstyle = number / medal / none / align = center. Columns aligned, dim rank prefix renders, medal fallback to numeric works at row 4+.🤖 Generated with Claude Code
Summary by CodeRabbit