Nas01010101 opened a new pull request, #21711:
URL: https://github.com/apache/echarts/pull/21711
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Makes `sunburst.minAngle` shrink the sibling sectors that are large enough,
so that a group of children still fits exactly inside its parent.
### Fixed issues
- #20602
## Details
### Before: What was the problem?
`sunburstLayout` enlarged any sector smaller than `minAngle` up to
`minAngle`, but never took the extra angle back from the other sectors. The
code that was supposed to do so was left commented out:
```js
if (angle < minAngle) {
angle = minAngle;
// restAngle -= minAngle;
}
// else {
// valueSumLargerThanMinAngle += value;
// }
```
So the children of a node could add up to more than the node itself. In the
demo of #20602, hovering `c` shows it overlapping `d`. With four children of
`100 / 1 / 1 / 1` and `minAngle: 30`, a parent spanning 360 degrees gets
children spanning 439.5 degrees.
### After: How does it behave after the fixing?
`getChildrenAngles()` now lays out a whole sibling group at once, in the
same two passes `pieLayout` already uses:
1. compute each child's angle, raise the ones below `minAngle`, subtract
what they took from the angle left over, and total the values of the ones left
untouched;
2. share the remaining angle among those untouched children in proportion to
their values, or, if `minAngle` cannot be satisfied at all, split the parent
evenly.
Because a sunburst is nested, this runs per sibling group with the parent's
own angle as the budget, rather than once over a flat list as in a pie.
Uncommenting the two lines above would not have been enough: they were reaching
for a single series-wide `restAngle`, which would let a shortfall in one
subtree be paid for by an unrelated subtree elsewhere in the ring.
Using the parent's assigned angle as the budget also fixes the second-order
case: when a node is itself enlarged to `minAngle`, its children are
redistributed into the enlarged span instead of leaving a gap in the outer
ring. With the group's natural sum as the budget instead, a node with a natural
span of 21.3 degrees enlarged to 30 degrees still had children totalling only
21.3.
`minAngle` defaults to `0`, and with `minAngle: 0` nothing is ever clamped,
so the redistribution pass is skipped entirely and existing charts lay out
bit-for-bit as before.
### Document Info
- [ ] I've updated the document
- [x] Doesn't need document change
`sunburst.minAngle` is currently not documented (only
`sunburst.label.minAngle` is), so nothing needs updating, though it may be
worth documenting separately now that it behaves like `pie.minAngle`.
## Others
### Merging options
- [x] Please squash the commits into one
- [ ] I'd like to squash the commits myself
### Other information
Added `test/ut/spec/series/sunburst.test.ts` with five cases: the overflow
itself, the nested/enlarged-parent case, the zero-sum case (20 zero-value nodes
with `minAngle: 30` spanned 600 degrees before), that small sectors are still
enlarged, and that `minAngle: 0` is unchanged.
Verified on Linux x86_64, node 22:
```
# with this change reverted
Tests: 3 failed, 2 passed, 5 total
# with this change
Tests: 5 passed, 5 total
# full unit suite, with this change
TZ=Asia/Shanghai npx jest --config test/ut/jest.config.cjs
Test Suites: 27 passed, 27 total
Tests: 199 passed, 199 total
```
Without `TZ` set, `spec/util/time.test.ts` fails on a locale-dependent
assertion unrelated to this change.
Possible conflict: open PRs #21687 and #21598 each also create
`test/ut/spec/series/sunburst.test.ts`, so whichever lands second will need a
trivial merge.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]