fix(Legend): when name ratio is 0 display abnormality - #433
Conversation
WalkthroughThe legend truncation control flow now handles a "pre-truncation" state by examining the previous item's truncation status. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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/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
📒 Files selected for processing (1)
src/feature/svgLegend/index.js
| // 这个节点文本都没有足够宽度渲染 | ||
| 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; | ||
| } |
There was a problem hiding this comment.
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:
- No ellipsis/dropdown is created for the first item
- Lines 129-132 still execute, adding the removed item's width to
startXandtotalWidth
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.
Summary by CodeRabbit