100pah commented on code in PR #20184:
URL: https://github.com/apache/echarts/pull/20184#discussion_r1828322172
##########
src/coord/polar/polarCreator.ts:
##########
@@ -102,9 +102,15 @@ function updatePolarScale(this: Polar, ecModel:
GlobalModel, api: ExtensionAPI)
// Fix extent of category angle axis
if (angleAxis.type === 'category' && !angleAxis.onBand) {
const extent = angleAxis.getExtent();
- const diff = 360 / (angleAxis.scale as OrdinalScale).count();
- angleAxis.inverse ? (extent[1] += diff) : (extent[1] -= diff);
- angleAxis.setExtent(extent[0], extent[1]);
+ const angleModel = angleAxis.model;
+ const endAngle = angleModel.get('endAngle');
+ const spanAngle = (endAngle == null ? 360 : endAngle -
angleModel.get('startAngle'))
+ * (angleAxis.inverse ? -1 : 1);
+ const diff = spanAngle / (angleAxis.scale as OrdinalScale).count();
+ if (Math.abs(spanAngle + diff) >= 360) {
+ extent[1] += Math.abs(diff);
+ angleAxis.setExtent(extent[0], extent[1]);
Review Comment:
In the current modified approach, this cases are not reasonable enougth:
<img width="983" alt="image"
src="https://github.com/user-attachments/assets/3a6c182d-8de9-4fbb-b0d1-62b026e10065">
(already have a overlap between bar C and bar D)
<img width="987" alt="image"
src="https://github.com/user-attachments/assets/18924196-5cff-4666-8bf9-f7e62c56d647">
(endAngle changes a little (from -195 to -198) but the appearance changes
significantly.)
I think the "adjusting the extent" is a compromise. It's counter intuitive
(the adjusted endAngle is not what use specified) but with out that user have
avoid overlap manually.
I just try to modify it: make it keep at a "max span" when there is no
enough space.
```js
// Fix extent of category angle axis
if (angleAxis.type === 'category' && !angleAxis.onBand) {
const extent = angleAxis.getExtent();
let spanAngle = normalizeAngle((normalizeAngle(extent[1]) + 360 -
normalizeAngle(extent[0])));
if (angleAxis.inverse) {
spanAngle = 360 - spanAngle;
}
const spanLimit = 360 - 360 / (angleAxis.scale as
OrdinalScale).count();
if (spanAngle >= spanLimit) {
extent[1] = extent[0] + (angleAxis.inverse ? -1 : 1) * spanLimit;
angleAxis.setExtent(extent[0], extent[1]);
}
}
// FIXME: this kind of function should be placed in some common util
file? (or similar one already exists?)
// Normalize an angle value to `[0, 360)`.
function normalizeAngle(val: number) {
val = val % 360;
val < 0 && (val += 360);
return val;
}
```
(it's just a illustrative code to show my current understanding.)
But about clockwise (inverse). I haven't understood the logic yet.
The current behavior (before this PR modified) seems weird:
<img width="1046" alt="image"
src="https://github.com/user-attachments/assets/18454e8c-f6a8-49d1-a59c-43e348a7204e">
--
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]