-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[charts] Add minTickLabelGap
to x-axis
#16548
[charts] Add minTickLabelGap
to x-axis
#16548
Conversation
Deploy preview: https://deploy-preview-16548--material-ui-x.netlify.app/ Updated pages: |
c5e1697
to
14d559b
Compare
packages/x-charts/src/models/axis.ts
Outdated
/** | ||
* The minimum gap in pixels between two tick labels. | ||
* @default 8 | ||
*/ | ||
minTickLabelGap?: number; |
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.
Added this only for the x-axis because the y-axis doesn't accept discrete data.
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.
what do you mean that the y-axis doesn't accept discrete data? 🤔
Wouldn't it depend on the chart type and orientation?
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.
Wouldn't it depend on the chart type and orientation?
This gap only makes sense for cartesian axes, and I'm assuming that the Y axis represents the second coordinate, regardless of orientation. Is that assumption wrong?
Highcharts does the same. In this example, the x-axis on the left and the y-axis is at the bottom.
Do you think we should not follow this convention? I see some benefits, namely having correct types for the x- and y-axes: since the x-axis is the only one that can accept discrete data, we don't need props related to discrete data in the y-axis.
Let me know your thoughts, maybe I'm missing something or there are some less conventional charts where my assumption is wrong.
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.
Is that assumption wrong?
Yes, and we have a nice counter example for that: the heatmap which is made of two band axes
If you only want to add something to some scale type (point and band in your case) you have the AxisScaleConfig
.
Notice this property will only apply on the x-axis because it's the only one to hide some labels.
The reason behind that is not the continuouse/categorical data. It's because x-axis labels are more likely to overflow since they are impacted by labels length
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.
Good points, hadn't thought of that.
So, in theory, the minTickLabelGap
can also be applied to the y-axis. However, it seems unlikely we'll need it because of the reason you delineated, so I'm going to assume we're only going to implement this for the x-axis for now.
52b38e3
to
c549b8e
Compare
@alexfauquette @JCQuintas just realized that we have an issue in our measuring code and it doesn't properly measure text sizes when classes are applied. What do you think? |
Are you suggesting that we should get the measurements from the actual tick label element instead of a mock element?
Is ResizeObserver correct here? You might want a |
Yes.
Yeah, I meant a I don't think a |
Ok, I don't see an issue with using the elements themselves, but I didn't build that feature, so maybe @alexfauquette has other concerns |
c549b8e
to
511dcb8
Compare
044d0c5
to
4c8e50c
Compare
@@ -96,6 +100,7 @@ const defaultProps = { | |||
disableLine: false, | |||
disableTicks: false, | |||
tickSize: 6, | |||
tickLabelMinGap: 4, |
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.
@alexfauquette @JCQuintas this is a breaking change in the sense that the previous behavior has been altered, but there's no way to get the exact previous behavior back. We can suggest setting As such, this isn't codemod-able, so where should I write documentation to inform users of this change? Is it enough to add a changelog entry or should I also write a section in |
CodSpeed Performance ReportMerging #16548 will improve performances by 17.31%Comparing Summary
Benchmarks breakdown
|
Usually we add it on both. The |
packages/x-charts/src/models/axis.ts
Outdated
* The minimum gap in pixels between two tick labels. | ||
* @default 8 |
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.
Probably good to mention that if two tick labels overlap, one of them will be hidden.
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.
Done 👍
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.
Comments are about
- A slightly less verbose default. But the way it's defined is less obvious, so feel free to ignore
- The update of the
@default
(will require to run scripts again)
Other than that it looks ready to merge 👍
@@ -39,10 +39,14 @@ function addLabelDimension( | |||
{ | |||
tickLabelStyle: style, | |||
tickLabelInterval, | |||
tickLabelMinGap, |
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.
tickLabelMinGap, | |
tickLabelMinGap = 4, |
@@ -39,10 +39,14 @@ function addLabelDimension( | |||
{ | |||
tickLabelStyle: style, | |||
tickLabelInterval, | |||
tickLabelMinGap, | |||
reverse, | |||
isMounted, | |||
}: Pick<ChartsXAxisProps, 'tickLabelInterval' | 'tickLabelStyle'> & |
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.
}: Pick<ChartsXAxisProps, 'tickLabelInterval' | 'tickLabelStyle'> & | |
}: Pick<ChartsXAxisProps, 'tickLabelInterval' | 'tickLabelStyle' | 'tickLabelMinGap'> & |
Pick<AxisDefaultized, 'reverse'> & { isMounted: boolean }, | ||
Pick<AxisDefaultized<ScaleName, any, ChartsXAxisProps>, 'reverse'> & { | ||
isMounted: boolean; | ||
tickLabelMinGap: NonNullable<ChartsXAxisProps['tickLabelMinGap']>; |
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.
tickLabelMinGap: NonNullable<ChartsXAxisProps['tickLabelMinGap']>; |
@@ -96,6 +101,7 @@ const defaultProps = { | |||
disableLine: false, | |||
disableTicks: false, | |||
tickSize: 6, | |||
tickLabelMinGap: 4, |
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.
tickLabelMinGap: 4, |
I had it this way before, but I changed it to be more in line with other defaults. It probably makes sense to have the defaults in the same place so it's easier to understand where they come from, or do you see any drawbacks with that? |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
d6ce934
to
e701067
Compare
Part of #10928.
Changelog
minTickLabelGap
to x-axis, which allows users to define the minimum gap, in pixels, between two tick labels. The default value is 4px. Make sure to check your charts as the spacing between tick labels might have changed.