feat(chart-pie): support avoidLabelOverlap for pie chart#182
feat(chart-pie): support avoidLabelOverlap for pie chart#182Aarebecca merged 6 commits intoantvis:mainfrom
Conversation
Summary of ChangesHello @xxMudCloudxx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant enhancements to the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a sophisticated label overlap avoidance algorithm for pie charts, which is a great feature. It also adds a minShowLabelPercent prop to filter out insignificant labels. The implementation is well-structured and commented. My review includes a few suggestions to improve code quality: refactoring some duplicated logic in a utility function, avoiding mutation in the new layout algorithm to make it a pure function, and replacing magic numbers with named constants for better readability and maintainability.
cf2f5e8 to
4fc732b
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new feature to avoid label overlapping in pie charts, which is a great addition. The implementation uses a spider leg layout algorithm and adds avoidLabelOverlap and minShowLabelPercent props. The code is generally well-structured.
I've found a couple of issues in the new layout algorithm logic:
- The
distributeLabelsfunction incorrectly mixes up top-based and center-basedycoordinates for labels, leading to incorrect positioning. - The calculation of the maximum
yboundary (labelMaxY) for labels seems to be incorrect, potentially allowing labels to be drawn outside the visible area.
I've provided detailed comments and suggestions to fix these issues. Once addressed, this will be a solid feature.
- Implement spider leg layout algorithm (distributeLabels) to prevent
label overlapping
- Add dynamic extension logic for dense labels
- Add `avoidLabelOverlap` prop to ChartPie component (default false)
- Add `minShowLabelPercent` props to ChartPie component (default 0),
accepting number | string (2 | "2%").
- Fix issue antvis#107
- Add normalizePercent util to handle both "2%" string and numeric inputs.
BREAKING CHANGE: None
4fc732b to
4fad948
Compare
- Add comprehensive test suite for Spider Leg Layout algorithm - Cover edge cases: empty array, single item, no overlap scenarios - Test boundary clamping: upper/lower boundary, push-back behavior - Test spacing compression when space is insufficient - Verify sorting behavior and originalIndex preservation - Add idempotency tests: running twice gives same result - Add calculation correctness tests: verify exact positions - Add extreme input tests: NaN, Infinity, inverted viewport, zero height - Export LabelItem interface for test accessibility - Fix actualSpacing calculation parentheses bug Total: 31 test cases covering all algorithm branches
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an excellent feature to avoid label overlapping in pie charts using a spider leg layout algorithm. The implementation is well-structured, and the new distributeLabels function is accompanied by a very comprehensive set of unit tests, which is commendable. I've identified a couple of edge-case bugs in the new layout algorithm and a minor opportunity to improve maintainability by removing magic numbers. Overall, this is a great contribution that significantly enhances the pie chart component.
Extract hardcoded magic numbers to named constants for better maintainability: - CONNECTOR_STROKE_OPACITY = 0.45 - CONNECTOR_STROKE_WIDTH = 2
|
@xxMudCloudxx You did an outstanding job. Additionally, do you think it would be appropriate to set |
|
我觉得也许minShowLabelPercent用户自己来设置比较好,不然用户可能会发现会有一部分标签不显示而不知道原因是什么? |
|
我建议 |
|
不好意思点错了,我修复一下 |
c984785 to
94657db
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #182 +/- ##
==========================================
+ Coverage 44.76% 44.81% +0.05%
==========================================
Files 330 332 +2
Lines 26291 26438 +147
Branches 2051 2072 +21
==========================================
+ Hits 11768 11849 +81
- Misses 14513 14579 +66
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Implement spider leg layout algorithm (distributeLabels) to prevent label overlapping
avoidLabelOverlapprop to ChartPie component (default false)minShowLabelPercentprops to ChartPie component (default 0)BREAKING CHANGE: None
before:
Note on Extreme Cases: When the data items exceed the canvas's physical capacity, the layout algorithm prioritizes visibility (non-overlapping) over aesthetic curvature. To mitigate this, users are recommended to use the minShowLabelPercent prop to hide insignificant data labels:
