-
Notifications
You must be signed in to change notification settings - Fork 19.8k
fix(axis): fix time axis labels and ticks being overlapped #17311
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your contribution! The pull request is marked to be |
|
I'm not sure but this issue seems to have been addressed in #15583 |
|
#15583 's fixing may have a potential problem that the ticks of the overlapped labels are not hidden, so that the ticks are not always the same with the labels. @pissang Do you think it a better idea to avoid overlapping as in this PR so that the ticks are always the same with the labels? And after the change in #15712, it requires |
|
@pissang If you think I'm on the right track, I can keep fixing this PR. For now, this PR has a problem that when calculating the bounding box of each label, the unparsed text is used. For example, If you think it is not a big deal if the ticks are not always the same as the labels, we can keep the current code and discuss if it's better to make |
Ticks lines can follow the visibility of labels. It should be easy. But the current design is not following it.
Adding an extra option is what I suggested. Because the overlapping issue is brought by the new time axis refactoring in the 5.0 version. The best way to fix it is to optimize the interval strategy of the new time axis. Current strategy may give too many ticks than the specified splitNumber. Hiding overlapped labels is just a workaround. |
|
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 |
|
|
||
| getViewLabels(): ReturnType<typeof createAxisLabels>['labels'] { | ||
| return createAxisLabels(this).labels; | ||
| const labels = createAxisLabels(this).labels; |
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.
This change should be reverted in later commits.

Brief Information
This pull request is in the type of:
What does this PR do?
Fix the cases when time axis labels and ticks being overlapped.
Fixed issues
#17198
Details
Before: What was the problem?
Some of the labels are too close to each other.
After: How does it behave after the fixing?
Change 1. Labels with priority
Before: Labels with different levels (year/month/day/...) have the same priority. So even #15583 can help remove the labels when overlapped (BWT, it seems not always remove overlapped labels), more important information can be lost.
After: Labels with larger level (e.g., year labels have larger levels than month labels) are displayed with higher priority and then display labels with smaller levels when there is enough space.
Change 2. A new option
axisLabel.formatterMinUnitBefore: If a developer want to display year labels when zoomed out and day labels when zoomed in but never display hour/minute/... level labels, the only thing can be done is by setting
formatterto be:This is not intuitive and it cannot help remove these ticks.
After: By setting
axisLabel.formatterMinUnitto be'day', ticks with levels smaller than'day'will not be displayed.Change 3. Align
showMinLabel/showMaxLabellogic with other types of axisBefore: The default value of
showMinLabel/showMaxLabelof time axis is set to befalsewhile other types axis is set to benullas the document states:showMinLabel/showMaxLabelis set to befalseby default because time axis may have min values like2022-10-12 12:34:23 123, which is formatted to be12:34:23 123and we don't expect the start/end values to be like this. Instead, developers may expect to display2022-10-12or10-12, etc.After: The default value of
showMinLabel/showMaxLabelof time axis is set to be null and the first/last label is displayed when there is enough space. Since we now haveformatterMinUnit, developers can easily set it to be'day'to hide it when its level is less than day level.Another useful way to use it is to set
showMinLabel/showMaxLabelto betrueso that the first/last label should always be displayed. But don't worry. In this case, if the level of the label is less thanformatterMinUnit, then the formatter offormatterMinUnitis used. For example, if we setformatterMinUnitto be'day'and the start label value is2022-10-12 12:34:23 123, then the formatter of day is used so it's formatted to be10-12:Change 4:
Before:
axisLabel.paddingis not considered when checking overlapping.After:
axisLabel.paddingis considered when checking overlapping.Change 5:
Before: When in day unit, the time labels are too crowded.
After: Use a larger approximate interval for day unit even if they don't overlap.
Document Info
One of the following should be checked.
Misc
ZRender Changes
Related test cases or examples to use the new APIs
Others
Merging options
Other information