-
Notifications
You must be signed in to change notification settings - Fork 19.7k
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 9265: Axis names overlap with labels #19534
Conversation
Thanks for your contribution! Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the |
bca793e
to
1422365
Compare
@gooroodev review |
Summary of Changes
Issues, Bugs, and Typos
Proposed Improvement: -import {isObject, each, indexOf, retrieve3, keys, reduce, map} from 'zrender/src/core/util';
+import {isObject, each, indexOf, retrieve3, keys, map} from 'zrender/src/core/util';
Proposed Improvement: -function isNameLocationCenter(nameLocation: string) {
- return nameLocation === 'middle' || nameLocation === 'center';
-} General Review of Code Quality and Style
Overall, the pull request addresses the issue effectively and maintains high code quality. The proposed improvements are minor and would enhance the clarity and efficiency of the code. Yours, Gooroo.dev. To receive reviews automatically, install Github App |
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.
Sorry for the late reply and thanks for your contribution!
I feel the changes are somewhat too complicated. Could we add the following code to the end of axisHelper.ts#estimateLabelUnionRect
?
...
const axisName = axisModel.get('name');
if (axisName) {
const nameLocation = axisModel.get('nameLocation');
const nameGap = axisModel.get('nameGap') || 0;
const nameRotate = axisModel.get('nameRotate') || 0;
const nameTruncate = axisModel.get('nameTruncate');
const textStyle = axisModel.getModel('nameTextStyle');
const unrotatedSingleRect = textStyle.getTextRect(axisName);
if (nameTruncate.maxWidth) {
unrotatedSingleRect.width = Math.min(unrotatedSingleRect.width, nameTruncate.maxWidth);
}
const singleRect = rotateTextRect(unrotatedSingleRect, nameRotate);
rect.union(singleRect);
// TODO: also consider nameLocation, nameGap and etc. to control the rect
}
return rect;
}
Hey @Ovilia, I just saw that you gave a thumbs up. What does that mean? Do you prefer the simpler not always working solution or should we go for the more complex solution? Greetings and thanks, |
Hey @Ovilia, sorry to ping you again, but it would be really really nice to get this into some new version soon. Let me know how we can help. Greetings, |
Hey, any updates on this one? Cheers, |
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.
Thanks for your contribution and sorry for the late reply. I don't check the notification regularly because there are too many messages. Please pin me by email oviliazhang at gmail.com if I haven't reply for some time.
This PR has changed a lot so it may be challenging for me to understand. I need you to provide some extra explanation on some of the comments.
if (axis.isHorizontal() && nameRotationIsMultipleOf90degrees | ||
|| !axis.isHorizontal() && nameRotationIsMultipleOf180degrees) { | ||
reservedSpace.name[namePositionOrthogonalAxis] = nameBoundingRectSize / 2 - reservedLabelSpace; | ||
} | ||
else if ( | ||
axis.isHorizontal() && ( | ||
nameLocationIsStart && orthogonalAxisPositionIsTop && nameRotationIsSecondOrFourthQuadrant | ||
|| nameLocationIsStart && orthogonalAxisPositionIsBottom && nameRotationIsFirstOrThirdQuadrant | ||
|| nameLocationIsEnd && orthogonalAxisPositionIsTop && nameRotationIsFirstOrThirdQuadrant | ||
|| nameLocationIsEnd && orthogonalAxisPositionIsBottom && nameRotationIsSecondOrFourthQuadrant | ||
) | ||
|| !axis.isHorizontal() && ( | ||
nameLocationIsStart && orthogonalAxisPositionIsLeft && nameRotationIsFirstOrThirdQuadrant | ||
|| nameLocationIsStart && orthogonalAxisPositionIsRight && nameRotationIsSecondOrFourthQuadrant | ||
|| nameLocationIsEnd && orthogonalAxisPositionIsLeft && nameRotationIsSecondOrFourthQuadrant | ||
|| nameLocationIsEnd && orthogonalAxisPositionIsRight && nameRotationIsFirstOrThirdQuadrant | ||
) | ||
) { | ||
reservedSpace.name[namePositionOrthogonalAxis] = reservedNameSpace; | ||
} | ||
} | ||
} |
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.
Can you explain the basic idea of these lines?
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.
Important to understand lines 527 to 548 are also lines 489-493 where the case for nameLocation: center
is handled. That means, lines 527 to 548 are only valid for nameLocation: start | end
.
The main reason for these conditions is the different anchoring of the axis names based on the rotation quadrant.
On a horizontal axis, all multiples of 90 degrees are anchored at their mid point, why it is necessary to reserve half of the length of the name. Additionally we need to remove the space needed by the labels since the grid will later be reduced by the sum of axisLabel.margin
, axis label size, nameGap
, and the axis name size. But, e.g., for nameLocation: start
and axis position: left
, the space needed for the labels to the left and the name to the left overlaps, since the labels are to the left of the axis and half of the name is left of the axis. (E.g. the name needs 50px left of the axis and the labels 30px. Since we sum up the reserved space, it would be 80px in total. However, the farthest point left of the axis is still the start of the name 50px to the left. So the name only needs an additional space of 50px-30px.)
The else if
contains all conditions for having the name rotation in different quadrants (excluding multiples of 90°). The different quadrants on different axes have different anchors resulting in a different reserved space. E.g. for axis with position: left
- 45°: Anchor is at end of the name and name is to the left of the axis => need to reserve space to the left
- 135°: Anchor is at end of the name and name is to the right of the axis => no need to reserve space to the right since there will be the plot
- 225°: Anchor is at start of the name and name is to the left of the axis => need to reserve space to the left
- 315°: Anchor is at start of the name and name is to the right of the axis => no need to reserve space to the right since there will be the plot
* The gap between the axis and the name gap. | ||
* Injected outside. | ||
*/ | ||
axisToNameGapStartGap: number = 0; |
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.
Can you further explain what is the gap between the axis and the name gap?
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.
There are 4 potential properties for each axis reducing the space of the grid. These are in order from the axis to the grid boundary: axisLabel.margin
, axis label size (determined by estimateLabelUnionRect
, axisHelper), nameGap
, and the axis name size (determined by computeNameBoundingRect
).
The axisToNameGapStart gap is the sum of the axisLabel.margin
and the axis label size, so from the axis to the start of the name gap.
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.
Thanks for your contribution! This PR should be released in our next major release 6.0.0 since it contains break changes that may change the position of grid area.
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-19534@ad4d68a |
Follow-up of #16825 and #12236
Brief Information
This pull request is in the type of:
What does this PR do?
This PR shrinks the grid size such that the axis labels and names are completely contained (Option (B) of #9265 (comment)).
Fixed issues
Details
Before: What was the problem?
When
grid.containLabel
is set to true, the axis names overlap with the labels, when there is no magical number fornameGap
specified. Furthermore, the names may be not visible when specifying thenameGap
, because the names get pushed out of the grid. Therefore, also the distance between the grid and the container needs to be adjusted.After: How does it behave after the fixing?
When
grid.containLabel
is set to true, the axis names do not overlap with labels and the grid size is shrinked such that the names are completely visible without the need to specify the grid to container distance ornameGap
.Document Info
One of the following should be checked.
Misc
ZRender Changes
Related test cases or examples to use the new APIs
N.A.
Others
Merging options
Other information