-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[charts] Add bar gradient example #19174
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
Conversation
Deploy preview: https://deploy-preview-19174--material-ui-x.netlify.app/ Updated pages: Bundle size report
|
By default, a gradient's units are set to `objectBoundingBox`. | ||
When applied to a bar, the gradient will stretch to fill the entire size of the bar, regardless of the bar's value. | ||
|
||
Alternatively, you can set `gradientUnits` to `userSpaceOnUse`, which stretches the gradient to fill the entire size of the chart. |
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.
Would probably be nice to have a few words on how to achieve that and how to account for the legend/tooltip
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.
how to achieve that
Sure, I'll expand on this.
how to account for the legend/tooltip
No need to account for those since they are outside the SVG. We only need to account for the axes sizes + margins. I'll explain that
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, let me know if it's clearer or if I should rewrite it. I found it a bit hard to explain succinctly
The Demo looks good except for the tooltip which looks like a flag (red yellow green is the Guinea) ![]() Would it be possible to mix that with a continuouse colormap. ![]() While thinking about that edge case, I'm wondering if it should not just be an additional case we support. Because for a continuous color scale we already have a gradient computed (usefull for line and scatter charts https://deploy-preview-19174--material-ui-x.netlify.app/x/react-charts/scatter/#color-scale) |
You mean so that the tooltip color is the same as the color in the gradient that corresponds to the bar's value?
So basically allowing a gradient in a continuous color map instead? |
Yes, that would be more interesting to see in the tooltip that values are green or red instead of the gradient
I investigated a bit. The issue is that we have two places for color management
Charts with a mix of fix colors make their choice by picking the gradient if it exist and the |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
54aa235
to
1ebffaf
Compare
Yeah, makes sense. I'm not sure if it's doable in this demo, though. That would probably require our library to support it first-class.
Yeah, we'll need to make some changes. Do you think it still makes sense to merge this PR or should we skip it and develop gradient support? |
1ebffaf
to
7c4020f
Compare
CodSpeed Performance ReportMerging #19174 will improve performances by 8.16%Comparing Summary
Benchmarks breakdown
|
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.
Let's go with that one
docs/data/charts/bars/bars.md
Outdated
|
||
### Gradients | ||
|
||
By default, a gradient's units are set to `objectBoundingBox`. |
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.
By default, a gradient's units are set to `objectBoundingBox`. | |
By default, a gradient's units are set to [`objectBoundingBox`](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/gradientUnits#objectboundingbox). |
docs/data/charts/bars/bars.md
Outdated
|
||
{{"demo": "BarOECDHouseholdSavings.js"}} | ||
|
||
Note that, in the example above, we're using two separate gradients: |
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.
Note that, in the example above, we're using two separate gradients: | |
Note that, in the example above, there are two distinct gradients: |
docs/data/charts/bars/bars.md
Outdated
|
||
Note that, in the example above, we're using two separate gradients: | ||
|
||
- the series `color` property references the gradient with `gradientUnits="objectBoundingBox"`, so this will be applied to the tooltip, legend, and other elements that reference the series color. |
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.
- the series `color` property references the gradient with `gradientUnits="objectBoundingBox"`, so this will be applied to the tooltip, legend, and other elements that reference the series color. | |
- The series `color` property references the gradient with `gradientUnits="objectBoundingBox"`. This one is applied to the tooltip, legend, and other elements that reference the series color. |
docs/data/charts/bars/bars.md
Outdated
Note that, in the example above, we're using two separate gradients: | ||
|
||
- the series `color` property references the gradient with `gradientUnits="objectBoundingBox"`, so this will be applied to the tooltip, legend, and other elements that reference the series color. | ||
- the bar's `fill` property is overridden using CSS to reference the gradient with `gradientUnits="userSpaceOnUse"`. |
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.
- the bar's `fill` property is overridden using CSS to reference the gradient with `gradientUnits="userSpaceOnUse"`. | |
- The bar's `fill` property is overridden using CSS to reference the gradient with `gradientUnits="userSpaceOnUse"`. |
docs/data/charts/bars/bars.md
Outdated
- the series `color` property references the gradient with `gradientUnits="objectBoundingBox"`, so this will be applied to the tooltip, legend, and other elements that reference the series color. | ||
- the bar's `fill` property is overridden using CSS to reference the gradient with `gradientUnits="userSpaceOnUse"`. | ||
|
||
We do this because we want all elements to show the whole gradient, except the bars themselves, which should only show the part of the gradient that corresponds to their value. |
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.
We do this because we want all elements to show the whole gradient, except the bars themselves, which should only show the part of the gradient that corresponds to their value. | |
The first gradient is use for elements showing the whole gradient. | |
And the second one is for the bars themselves that show the part of the gradient that corresponds to their value. |
Co-authored-by: Jose C Quintas Jr <[email protected]> Signed-off-by: Bernardo Belchior <[email protected]>
Co-authored-by: Jose C Quintas Jr <[email protected]> Signed-off-by: Bernardo Belchior <[email protected]>
7c4020f
to
067a6e0
Compare
Signed-off-by: Bernardo Belchior <[email protected]> Co-authored-by: Jose C Quintas Jr <[email protected]>
Related to #19064.
Add example with a bar gradient that reflects the bar's value: