-
-
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] Improve the management of the text (legend only) #10138
Conversation
Deploy preview: https://deploy-preview-10138--material-ui-x.netlify.app/ Updated pages: |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
@@ -5,64 +5,23 @@ export const AxisRoot = styled('g', { | |||
name: 'MuiChartsAxis', | |||
slot: 'Root', | |||
overridesResolver: (props, styles) => styles.root, | |||
})({ |
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.
All the text alignments are moved from this CSS to the <Text/>
props
break; | ||
} | ||
|
||
// const transforms = []; |
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.
It is not implemented yet. It will mostly be helpful for axes ticks
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.
Great improvement! 🎉 Much better DX, 💙 the docs improvements
I left a few suggestions for the phrasing in the docs 🙈
About the reduced label font size, I agree that they are a bit too small. I would personally go with a middle ground of 14px
. WDYT?
Co-authored-by: Nora <[email protected]> Signed-off-by: Alexandre Fauquette <[email protected]>
3e788e9
to
fa118b6
Compare
fa118b6
to
dd7021a
Compare
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.
Looks great! 💯
Leaving some comments. 😉
The label vertical alignment is the culprit for not approving the PR yet as it seems like it would be a regression as compared to the current version. 🙈
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.
Looks great! 💯
Approving based on: #10138 (comment)
The few left nitpicks are just that - minor improvements.
Fix #9743
The target is to get access to the text size (height and width) to be able to place them nicely.
For now, the new
<Text />
component allows to get its size and to support multiline texts.It's used for
Discussion
Style
The placement of the legend has changed unintentionally. It now sticks to the border of the SVG instead of the border of the drawing area. Not a big deal, but I don't see one being better than the other
I changed a bit the default styling of legend text. I'm open to suggestions on this topic.
DevExp
For me the legend is much better now, but it opens the question about how to pass style the its labels. I went with
labelStyle
props. So you can do the following.But it could be done with other options to be able to manage states. But it feels overengineered. I don't know if you have ideas
Todo
In the axis adapt the number of ticks to label size\n
Todo next PRs
Trade-offs
There are a lot of styled components in axes, and most of their style will be useless with this
<Text/>
component. I removed all of them and only kept the root one. The default styling is done by CSS classesPreview is available in the demo of Legend docs page
Changelog
Breaking changes
The charts have a new text display mechanism.
It adds line break support and avoids overlapping text in the legend.
This comes with some breaking changes.
The DOM structure is modified. An intermediary
<tspan />
element has been added. This can impact how your style is applied.The top margin has been reduced from 100 to 50 to benefit form the denser legend.
To accurately compute the text size and then place it, styling should be provided as a JS object. For example, to set the legend font size, you should do:
Support for other text elements (axis labels and tick labels) will be implemented in follow-up PR.