Skip to content

fix(Legend): when name ratio is 0 display abnormality - #433

Open
ader-h wants to merge 1 commit into
opentiny:devfrom
ader-h:fix-svglegend-260407
Open

fix(Legend): when name ratio is 0 display abnormality#433
ader-h wants to merge 1 commit into
opentiny:devfrom
ader-h:fix-svglegend-260407

Conversation

@ader-h

@ader-h ader-h commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced legend display to show ellipsis/dropdown controls for items that would be completely truncated, preventing blank spaces in the legend.

@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown

Walkthrough

The legend truncation control flow now handles a "pre-truncation" state by examining the previous item's truncation status. The createLegend and createItem functions are modified to detect when text would be fully truncated, remove the corresponding SVG elements, and trigger ellipsis/dropdown rendering at the appropriate point during iteration.

Changes

Cohort / File(s) Summary
Legend Truncation Logic
src/feature/svgLegend/index.js
Modified createLegend to capture and inspect previous item truncation state (preItem), detecting pre-truncation cases to set truncateIndex. Modified createItem to detect zero-length truncated text, remove created SVG groups, and return preTruncation flag alongside width metrics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A legend grows, but some must bow,
When text shrinks down to naught somehow,
We peek behind at what came before,
And trim the rest with ellipsis… more!
Pre-truncation caught, the flow runs true,
Legend rendered fresh and new. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(Legend): when name ratio is 0 display abnormality' directly addresses the core issue being fixed—a legend display problem when the name ratio is zero—which aligns with the code changes that handle text truncation edge cases.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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/feature/svgLegend/index.js`:
- Around line 119-128: Handle the edge case when preTruncation is true for the
very first item (preItem undefined): set truncateIndex = 0, set style.x =
startX, and call createEllipsis(g, type, style, svgNS, name, index) and
createDropDown(container, legend, legendData, index, iChartOption,
chartInstance) so the first-item ellipsis/dropdown is rendered; also prevent the
removed first item's width from being added to startX/totalWidth by toggling a
flag (e.g., skipAddWidth) or branching where startX/totalWidth are updated to
skip that update when truncateIndex was set for the first item. Ensure you
reference preTruncation, preItem, truncateIndex, createEllipsis, createDropDown,
startX and totalWidth in the fix.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2b34e97-a83f-4e5a-965f-c949859b0f45

📥 Commits

Reviewing files that changed from the base of the PR and between 2d30e28 and 81a530a.

📒 Files selected for processing (1)
  • src/feature/svgLegend/index.js

Comment on lines +119 to +128
// 这个节点文本都没有足够宽度渲染
if(itemConfig.preTruncation && preItem){
truncateIndex = index - 1;
if (secondaryRender) {
style.x = startX;
createEllipsis(g, type, style, svgNS, name, index+1);
createDropDown(container, legend, legendData, index+1, iChartOption, chartInstance);
}
break;
}

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

Edge case: preTruncation at index === 0 not handled.

When the first legend item (index === 0) triggers preTruncation, preItem is undefined, so this block doesn't execute. The item's SVG group was already removed in createItem, but:

  1. No ellipsis/dropdown is created for the first item
  2. Lines 129-132 still execute, adding the removed item's width to startX and totalWidth

This could result in the first legend item silently disappearing without showing a dropdown.

Proposed fix
     // 这个节点文本都没有足够宽度渲染
-    if(itemConfig.preTruncation && preItem){
+    if(itemConfig.preTruncation){
+      // When index is 0, treat as truncation starting from the beginning
       truncateIndex = index - 1;
       if (secondaryRender) {
         style.x = startX;
-        createEllipsis(g, type, style, svgNS, name, index+1);
-        createDropDown(container, legend, legendData, index+1, iChartOption, chartInstance);
+        createEllipsis(g, type, style, svgNS, name, index === 0 ? 0 : index+1);
+        createDropDown(container, legend, legendData, index === 0 ? 0 : index+1, iChartOption, chartInstance);
       }
       break;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/feature/svgLegend/index.js` around lines 119 - 128, Handle the edge case
when preTruncation is true for the very first item (preItem undefined): set
truncateIndex = 0, set style.x = startX, and call createEllipsis(g, type, style,
svgNS, name, index) and createDropDown(container, legend, legendData, index,
iChartOption, chartInstance) so the first-item ellipsis/dropdown is rendered;
also prevent the removed first item's width from being added to
startX/totalWidth by toggling a flag (e.g., skipAddWidth) or branching where
startX/totalWidth are updated to skip that update when truncateIndex was set for
the first item. Ensure you reference preTruncation, preItem, truncateIndex,
createEllipsis, createDropDown, startX and totalWidth in the fix.

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