-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[charts-pro] Export charts as image #17353
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-pro] Export charts as image #17353
Conversation
Deploy preview: https://deploy-preview-17353--material-ui-x.netlify.app/ Updated pages: |
CodSpeed Performance ReportMerging #17353 will not alter performanceComparing Summary
|
42bb1c0
to
826c311
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
d270f5e
to
0fc2fcc
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Add options Add space Optional options Export `ChartApi` and `ChartProApi` Add print preview test Revert changes to tests Remove `@media not print` Rename to `exportAsPrint` Document export composition Generate files Update docs Update export composition example Add tests Improve print preview screenshot Improve data grid screenshot Increase width slightly Fix print test Address feedback Revert changes to tests
0fc2fcc
to
ef6ecec
Compare
packages/x-charts-pro/src/internals/plugins/useChartProExport/exportImage.ts
Outdated
Show resolved
Hide resolved
packages/x-charts-pro/src/internals/plugins/useChartProExport/exportImage.ts
Show resolved
Hide resolved
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.
Testing looks much easier than PDF ;)
packages/x-charts-pro/src/internals/plugins/useChartProExport/exportImage.ts
Show resolved
Hide resolved
packages/x-charts-pro/src/internals/plugins/useChartProExport/exportImage.ts
Outdated
Show resolved
Hide resolved
packages/x-charts-pro/src/internals/plugins/useChartProExport/exportImage.ts
Outdated
Show resolved
Hide resolved
packages/x-charts-pro/src/internals/plugins/useChartProExport/exportImage.ts
Show resolved
Hide resolved
packages/x-charts-pro/src/internals/plugins/useChartProExport/useChartProExport.ts
Outdated
Show resolved
Hide resolved
}) { | ||
const [type, setType] = React.useState('image/png'); | ||
const [rawQuality, setRawQuality] = React.useState('0.9'); | ||
const quality = Math.max(0, Math.min(1, Number.parseFloat(rawQuality))); |
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.
A slider woudl solve the need for such a validation :)
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.
Isn't a slider a bit harder to use when selecting a specific value? For floating point numbers we would have a step of 0.01, which wouldn't be great when selecting a number, right?
I suppose sliders work better for integers.
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.
I suppose sliders work better for integers.
If you consider this as a percentage, it becomes an integer equivalent to a step of 0.01 ;)
But the texfield is ok too 👍
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.
Just few feedback on the docs.
The external package is effectively downloaded only on the first click.
I'm surprised by the number of font downloads compared to the one downloaded in the PDF print. But that seems to come from the library side not sure we can reduce it
return iframeEl; | ||
} | ||
|
||
export function loadStyleSheets(document: Document, element: HTMLElement | SVGElement) { |
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.
This looks close to the data grid print logic, maybe something to share at one point.
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.
Yes, it's a direct copy. I'll look into how we can share this.
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.
Here it is: #17548
Part of #11746.
Export charts as image. PNG is supported across all browsers, JPEG and WEBP depend on the browser, but most major browsers support them
Benchmark
Changelog
Add API to export a chart as an image:
apiRef.exportAsImage
.Preview: https://deploy-preview-17353--material-ui-x.netlify.app/x/react-charts/export/