-
Notifications
You must be signed in to change notification settings - Fork 19.7k
fix: xAxis label overflow fixed when containLabel=true #16880
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?
Changes from 4 commits
c80f015
c2bb3b0
6b57c89
c8a4906
21b4380
f00c4ec
f53c271
7ee50c2
b30b557
0fc9077
22d6449
095110e
eb5be1e
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 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,12 +24,12 @@ | |||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import {isObject, each, indexOf, retrieve3, keys} from 'zrender/src/core/util'; | ||||||||||||||||||||||||||||||||
import {getLayoutRect, LayoutRect} from '../../util/layout'; | ||||||||||||||||||||||||||||||||
import {box, getLayoutRect, LayoutRect} from '../../util/layout'; | ||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||
createScaleByModel, | ||||||||||||||||||||||||||||||||
ifAxisCrossZero, | ||||||||||||||||||||||||||||||||
niceScaleExtent, | ||||||||||||||||||||||||||||||||
estimateLabelUnionRect, | ||||||||||||||||||||||||||||||||
estimateLabelRect, | ||||||||||||||||||||||||||||||||
getDataDimensionsOnAxis | ||||||||||||||||||||||||||||||||
} from '../../coord/axisHelper'; | ||||||||||||||||||||||||||||||||
import Cartesian2D, {cartesian2DDimensions} from './Cartesian2D'; | ||||||||||||||||||||||||||||||||
|
@@ -179,16 +179,14 @@ class Grid implements CoordinateSystemMaster { | |||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
this._rect = gridRect; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
const axesList = this._axesList; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
adjustAxes(); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
// Minus label size | ||||||||||||||||||||||||||||||||
if (isContainLabel) { | ||||||||||||||||||||||||||||||||
each(axesList, function (axis) { | ||||||||||||||||||||||||||||||||
if (!axis.model.get(['axisLabel', 'inside'])) { | ||||||||||||||||||||||||||||||||
const labelUnionRect = estimateLabelUnionRect(axis); | ||||||||||||||||||||||||||||||||
const labelUnionRect = estimateLabelRect(axis).rect; | ||||||||||||||||||||||||||||||||
if (labelUnionRect) { | ||||||||||||||||||||||||||||||||
const dim: 'height' | 'width' = axis.isHorizontal() ? 'height' : 'width'; | ||||||||||||||||||||||||||||||||
const margin = axis.model.get(['axisLabel', 'margin']); | ||||||||||||||||||||||||||||||||
|
@@ -202,10 +200,32 @@ class Grid implements CoordinateSystemMaster { | |||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
//Adjust grid.width to keep xAxis labels in dom | ||||||||||||||||||||||||||||||||
const [xAxis, yAxis] = axesList[0].isHorizontal() ? axesList : axesList.slice().reverse(); | ||||||||||||||||||||||||||||||||
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. I think we don't need complex logic to check the first label and last label here. In the echarts/src/coord/cartesian/Grid.ts Line 193 in c8a4906
x /width based on the labels of yAxis. We can also check if the union rect of xAxis labels excced the canvas size. Then adjust x /width to avoid labels overflow.
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 function 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 method
I'm not sure what do you mean by clip labels. Correct me if I'm wrong. Indeed we only pick some of the labels if there are amount of theme, especially in category axis. echarts/src/coord/axisHelper.ts Line 324 in 4a52199
Perhaps the last label will also be skipped. We can add some extra logic to ensure the first label and last label are also included. 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. Also the current logic of estimating Line 223 in 4a52199
Using this method to get all formatted labels will be more accurate and performant. 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 logic of function echarts/src/coord/axisHelper.ts Lines 327 to 338 in 4a52199
This doesn't result in errors for now because only x/height and y/width is used in older version, and they are the same for union rect and largest rect.
However, thanks to your suggestion, I double-checked Axis.ts and found the function P.S. Do you mind telling me how to get the dom size in Echarts? I struggled to get dom attributes but failed. 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. So what I want to emphasize is right-most DISPLAYED label. The function 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. Of course, 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.
I think that's not the difference. The union bounding rect should also be from the displayed labels . 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. Hmmm, do you mean use 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.
However the |
||||||||||||||||||||||||||||||||
const {firstLabelRect, lastLabelRect} = estimateLabelRect(xAxis); | ||||||||||||||||||||||||||||||||
const labelUnionRect = estimateLabelRect(yAxis).rect; | ||||||||||||||||||||||||||||||||
const margin = xAxis.model.get(['axisLabel', 'margin']); | ||||||||||||||||||||||||||||||||
//When yAxis is on the right, check the left margin instead | ||||||||||||||||||||||||||||||||
if (yAxis.position === 'right') { | ||||||||||||||||||||||||||||||||
if (firstLabelRect.width / 2 >= boxLayoutParams.left) { | ||||||||||||||||||||||||||||||||
gridRect.width -= firstLabelRect.width / 2 - Number(boxLayoutParams.left) + margin; | ||||||||||||||||||||||||||||||||
gridRect.x += firstLabelRect.width / 2 - Number(boxLayoutParams.left) + margin; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||
//Long last label exceeds the right boundary | ||||||||||||||||||||||||||||||||
if (lastLabelRect.width / 2 >= boxLayoutParams.right) { | ||||||||||||||||||||||||||||||||
gridRect.width -= lastLabelRect.width / 2 - Number(boxLayoutParams.right) + margin; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
//Long first label still exceeds the left boundary even when yAxis on the left | ||||||||||||||||||||||||||||||||
let leftMargin = Number(boxLayoutParams.left); | ||||||||||||||||||||||||||||||||
if (firstLabelRect.width / 2 >= leftMargin + labelUnionRect.width) { | ||||||||||||||||||||||||||||||||
gridRect.width -= firstLabelRect.width / 2 - leftMargin - labelUnionRect.width + margin; | ||||||||||||||||||||||||||||||||
gridRect.x += firstLabelRect.width / 2 - leftMargin - labelUnionRect.width + margin; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
adjustAxes(); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
each(this._coordsList, function (coord) { | ||||||||||||||||||||||||||||||||
// Calculate affine matrix to accelerate the data to point transform. | ||||||||||||||||||||||||||||||||
// If all the axes scales are time or value. | ||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.