Skip to content

feat(render): list_ranking renderer for Bars shape - #125

Merged
unhappychoice merged 2 commits into
mainfrom
feat/list-ranking-renderer
Apr 26, 2026
Merged

unhappychoice merged 2 commits into
mainfrom
feat/list-ranking-renderer

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Apr 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • New list_ranking renderer (family list_*) consuming the existing Bars shape.
  • Sorts descending and prints <rank> <label> <value> rows with rank-prefix and value columns aligned across rows. Sibling to chart_bar — same shape, text-first treatment.
  • Reuses style / max_items / align on RenderOptions (no new fields, no shape changes).
  • style = "medal" decorates the podium with 🥇 / 🥈 / 🥉, falling back to numeric prefixes for 4th place onward.

Ticks the list_ranking checkbox under list_* in #61. Refs #41.

Reference (auto-generated)

  • Accepts: bars
  • Animates: no

Options

Option Type Required Default Description
max_items positive integer no all bars Cap on rendered ranks. Keeps the top N by value when the input has more bars than the cap.
style "number" | "medal" | "none" no "number" Rank-prefix glyph. number (default) emits 1. / 2. / 3.. medal emits 🥇 / 🥈 / 🥉 for the top three then numbers for the rest. none omits the prefix.
align "left" | "center" | "right" no "left" Horizontal alignment of the whole ranking within its cell.

Theme tokens

Key Description
text Primary body text colour. Used for label and value columns.
text_dim Rank-prefix colour — sinks the rank into the chrome so the label reads first.

Compatible fetchers

Shape Fetchers
bars basic_read_store, code_todos, git_contributors, github_contributors_monthly, github_languages, system_disk_usage

Out of scope

  • Delta marker (▲ +3) — BarsData::Bar doesn'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.
  • Inline magnitude bar (████ 142) — keeps list_ranking focused on the text-rank treatment; visual bars stay with chart_bar.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test (601 passed)
  • Smoke-tested locally with git_contributors across style = 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

  • New Features
    • Introduced a new "list_ranking" renderer for bar visualizations that automatically sorts items by descending value (stable for ties), supports optional truncation to limit displayed results, shows configurable rank prefixes (numeric, medal icons, or none), aligns value column for neat right alignment, and offers configurable horizontal alignment (left/center/right) with themed dimming for rank prefixes.

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

coderabbitai Bot commented Apr 26, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4450bef7-ac6c-4e4f-8170-3be90791150d

📥 Commits

Reviewing files that changed from the base of the PR and between f432bac and 8fda1cd.

📒 Files selected for processing (1)
  • src/render/list_ranking.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/render/list_ranking.rs

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
List Ranking Renderer Implementation
src/render/list_ranking.rs
New ListRankingRenderer implementing Renderer for Shape::Bars: sorts bars descending (stable for ties), optional max_items truncation, rank prefix modes (number/medal/none), computes column widths (counts medal glyphs as double-width), applies horizontal alignment and dim styling for prefixes, includes unit tests (ordering, truncation, medals, alignment, stable ties, zero-area).
Renderer Registry Integration
src/render/mod.rs
Declares mod list_ranking; and registers ListRankingRenderer in the built-in renderer registry; updates test asserting built-in renderer resolvability.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰
I hop through ranks with a twitchy nose,
Sorting bars where the leaderboard grows,
Medals that sparkle, numbers in line,
Labels aligned, values that shine,
A tiny rabbit cheers: "This list looks fine!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.93% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(render): list_ranking renderer for Bars shape' is specific and directly describes the main change—adding a new list_ranking renderer for the Bars shape.
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.

✏️ 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/list-ranking-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 96.87500% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.00%. Comparing base (dfd3021) to head (8fda1cd).

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

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
src/render/mod.rs 89.44% <100.00%> (+0.05%) ⬆️
src/render/list_ranking.rs 96.85% <96.85%> (ø)
🚀 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/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_widths uses display_width for the prefix (treats medals as 2 cells) but chars().count() for label and value. pad_right / pad_left are also char-count-based, so the renderer is internally consistent for ASCII. As soon as a label contains a wide codepoint (CJK in git_contributors names, an emoji language flag from github_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 same display_width helper (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_right would 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_width comment 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

📥 Commits

Reviewing files that changed from the base of the PR and between dfd3021 and f432bac.

📒 Files selected for processing (2)
  • src/render/list_ranking.rs
  • src/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]>
@unhappychoice
unhappychoice merged commit 5c774bd into main Apr 26, 2026
7 checks passed
@unhappychoice
unhappychoice deleted the feat/list-ranking-renderer branch April 26, 2026 03:16
@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