-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[charts] Fix spark line not having clip path #17501
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?
[charts] Fix spark line not having clip path #17501
Conversation
Thanks for adding a type label to the PR! 👍 |
Deploy preview: https://deploy-preview-17501--material-ui-x.netlify.app/ |
CodSpeed Performance ReportMerging #17501 will not alter performanceComparing Summary
|
An unfortunate consequence of this change is the problem we see in this visual test. Since lines have a stroke width of 2, a line that links two points whose y-coordinate is 0 will only have a stroke width of 1 because it will be clipped. We can probably figure out some ways to solve this issue, but I'm not sure if it would make sense as the clip path is working as expected. Would appreciate some feedback on this. |
Does changing the baseline on the bar affects anything? We could have the clippath on the AreaPlot only, not the line 🤔, but I'm not sure how it would affect the lines with baseline, would we plot things out of the chart? 🤔 |
What do you mean by changing the baseline on the bar?
Yeah, if we don't apply the clip path to the line plot then this issue won't surface, but then there would still be some bleeding outside the drawing area, which is what this PR is supposed to fix. This is hard to fix because if we change the clip path based on stroke width, we might have weird edge cases when a user uses their own line component instead of the default one. An option we could consider is having a prop for clipping the path? |
Nvm baseline is not present on bar not sparkline 😆 Yeah it is kinda tricky |
Only clipping the area could solve also this issue {plotType === 'bar' && <g clipPath={`url(#${clipPathId})`}><BarPlot skipAnimation slots={slots} slotProps={slotProps} /></g>}
{plotType === 'line' && (
<React.Fragment>
<g clipPath={`url(#${clipPathId})`}>
<AreaPlot skipAnimation slots={slots} slotProps={slotProps} />
</g>
<LinePlot skipAnimation slots={slots} slotProps={slotProps} />
<LineHighlightPlot slots={slots} slotProps={slotProps} />
</React.Fragment>
)} But it opens question about when user set the A solution could be to add 1 extra pixels top the clipfor line and area |
The problem of only clipping the area is that
I considered that. It's a bit hacky because as soon as the stroke width changes (or the user uses a custom component), those extra pixels are wrong, but it would the fix the issue for now. I'm ok with this, but it would be nice to add a warning in the docs and a escape hatch in case users aren't using the defaults. Not sure how to do it, though 🤔 should we provide It wouldn't fix the issue with the highlight, though. |
In all cases, the line highlight element should be outside of the clip-path
What about adding those props to the sparlkline specifically
|
Fixes #15221.
Before we weren't respecting the margin because the drawing area wasn't being clipped, but it is now. The examples below have a margin of 5px, which wasn't respected before.
Before:
After: