-
Notifications
You must be signed in to change notification settings - Fork 19.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(polar): angleAxis extent when boundaryGap is false #20184
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The conditional operator has lower precedence than arithmetic operator. This should be a "famous" and commonly occurring mistake in not only JS but also Java, c++, ... And why there is null checker for only And should we retrieve value from |
||
* (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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current modified approach, this cases are not reasonable enougth: (already have a overlap between bar C and bar D) (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. // 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. |
||
} | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can see that the old code takes
360
as the range ofendAngle
tostartAngle
, which is not always the case.