Skip to content

Conversation

bernardobelchior
Copy link
Member

@bernardobelchior bernardobelchior commented Jul 7, 2025

Related to https://github.com/mui/mui-x/pull/17447/files#r2180308840.

Add onBeforeExport callback that is called with the iframe used to export the chart.

This is useful when users want to fully customize what will be exported.

@mui-bot
Copy link

mui-bot commented Jul 7, 2025

Deploy preview: https://deploy-preview-18722--material-ui-x.netlify.app/

Updated pages:

Bundle size report

Total Size Change: 🔺+520B(0.00%) - Total Gzip Change: 🔺+248B(+0.01%)
Files: 122 total (0 added, 0 removed, 18 changed)

Show details for 100 more bundles (22 more not shown)

@mui/x-charts-proparsed: 🔺+52B(+0.01%) gzip: 🔺+22B(+0.02%)
@mui/x-charts-pro/BarChartProparsed: 🔺+52B(+0.02%) gzip: 🔺+22B(+0.03%)
@mui/x-charts-pro/ChartContainerProparsed: 🔺+52B(+0.03%) gzip: 🔺+30B(+0.05%)
@mui/x-charts-pro/ChartDataProviderProparsed: 🔺+52B(+0.03%) gzip: 🔺+27B(+0.05%)
@mui/x-charts-pro/FunnelChartparsed: 🔺+52B(+0.02%) gzip: 🔺+25B(+0.03%)
@mui/x-charts-pro/Heatmapparsed: 🔺+52B(+0.02%) gzip: 🔺+28B(+0.04%)
@mui/x-charts-pro/LineChartProparsed: 🔺+52B(+0.02%) gzip: 🔺+24B(+0.03%)
@mui/x-charts-pro/PieChartProparsed: 🔺+52B(+0.02%) gzip: 🔺+28B(+0.04%)
@mui/x-charts-pro/RadarChartProparsed: 🔺+52B(+0.03%) gzip: 🔺+28B(+0.04%)
@mui/x-charts-pro/ScatterChartProparsed: 🔺+52B(+0.02%) gzip: 🔺+20B(+0.02%)
@mui/x-chartsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts-pro/ChartsToolbarProparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts-pro/ChartZoomSliderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/BarChartparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartContainerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartDataProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsAxisparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsAxisHighlightparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsClipPathparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsGridparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsLabelparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsLegendparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsLocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsOverlayparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsReferenceLineparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsSurfaceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsTextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsTooltipparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsXAxisparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ChartsYAxisparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/Gaugeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/LineChartparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/PieChartparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/RadarChartparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/ScatterChartparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/SparkLineChartparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-charts/Toolbarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-gridparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid-premiumparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid-premium/DataGridPremiumparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid-proparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid-pro/DataGridProparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-data-grid/DataGridparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickersparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-proparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterDateFnsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterDateFnsJalaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterDayjsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterLuxonparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterMomentparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterMomentHijriparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/AdapterMomentJalaaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateRangeCalendarparsed: 0B(0.00%) gzip: ▼-1B(0.00%)
@mui/x-date-pickers-pro/DateRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateRangePickerDayparsed: 0B(0.00%) gzip: 🔺+1B(+0.01%)
@mui/x-date-pickers-pro/DateRangePickerDay2parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DateTimeRangePickerparsed: 0B(0.00%) gzip: ▼-1B(0.00%)
@mui/x-date-pickers-pro/DesktopDateRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/DesktopDateTimeRangePickerparsed: 0B(0.00%) gzip: ▼-1B(0.00%)
@mui/x-date-pickers-pro/DesktopTimeRangePickerparsed: 0B(0.00%) gzip: ▼-1B(0.00%)
@mui/x-date-pickers-pro/LocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MobileDateRangePickerparsed: 0B(0.00%) gzip: ▼-1B(0.00%)
@mui/x-date-pickers-pro/MobileDateTimeRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MobileTimeRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MultiInputDateRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MultiInputDateTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/MultiInputTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/PickersRangeCalendarHeaderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/SingleInputDateRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/SingleInputDateTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/SingleInputTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers-pro/StaticDateRangePickerparsed: 0B(0.00%) gzip: ▼-1B(0.00%)
@mui/x-date-pickers-pro/TimeRangePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDateFnsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDateFnsBaseparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDateFnsJalaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterDayjsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterLuxonparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterMomentparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterMomentHijriparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/AdapterMomentJalaaliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateCalendarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DatePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateTimeFieldparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DayCalendarSkeletonparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DesktopDatePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DesktopDateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DesktopTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/DigitalClockparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/LocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MobileDatePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MobileDateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MobileTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MonthCalendarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/MultiSectionDigitalClockparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/PickerDay2parsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/PickersActionBarparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/x-date-pickers/PickersCalendarHeaderparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 66402a7

@bernardobelchior bernardobelchior added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: charts Changes related to the charts. labels Jul 7, 2025
Copy link

codspeed-hq bot commented Jul 7, 2025

CodSpeed Performance Report

Merging #18722 will degrade performances by 82.31%

Comparing bernardobelchior:charts-export-on-before-export (66402a7) with master (de05657)

Summary

❌ 5 (👁 5) regressions
✅ 2 untouched benchmarks
🆕 3 new benchmarks
⁉️ 2 (👁 2) dropped benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
👁 BarChart with big data amount 391.3 ms 1,761 ms -77.78%
👁 BarChartPro with big data amount 592.6 ms 1,041.4 ms -43.1%
🆕 Area chart with big data amount (no marks) N/A 101.8 ms N/A
👁 LineChart with big data amount 221.9 ms N/A N/A
🆕 LineChart with big data amount (with marks) N/A 1.3 s N/A
👁 LineChartPro with big data amount 102 ms N/A N/A
🆕 LineChartPro with big data amount and zoomed in (with marks) N/A 420.1 ms N/A
👁 ScatterChart with big data amount 470.7 ms 771.7 ms -39%
👁 ScatterChartPro with big data amount 69.6 ms 393.8 ms -82.31%
👁 ScatterChartPro with big data amount and zoomed in 57.1 ms 64.6 ms -11.69%

@bernardobelchior bernardobelchior marked this pull request as ready for review July 7, 2025 15:05
* removing elements, etc.
* @param {HTMLIFrameElement} iframe containing the chart to be exported.
*/
onBeforeExport?: (iframe: HTMLIFrameElement) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should also accept async functions.

Suggested change
onBeforeExport?: (iframe: HTMLIFrameElement) => void;
onBeforeExport?: (iframe: HTMLIFrameElement) => Promise<void> | void;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍

@bernardobelchior bernardobelchior force-pushed the charts-export-on-before-export branch from 3c4769e to 1a83847 Compare July 8, 2025 06:29
@@ -80,6 +80,18 @@ Additionally, the name of the exported file has been customized to resemble the
If the browser does not support a requested image format, the export defaults to PNG.
:::

### `onBeforeExport`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe adding a H3 title "export format" at this level

image

Comment on lines 85 to 91
When exporting, the chart is rendered onto an iframe and then exported as an image or PDF.

You can modify the iframe before the export process starts by using the `onBeforeExport` callback.

This can be useful to add custom styles or modify the chart's appearance before exporting.

For example, you can hide the toolbar when exporting the chart, as shown below:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proposal to focus first on what the reader might be looking for before the technical explainination

Suggested change
When exporting, the chart is rendered onto an iframe and then exported as an image or PDF.
You can modify the iframe before the export process starts by using the `onBeforeExport` callback.
This can be useful to add custom styles or modify the chart's appearance before exporting.
For example, you can hide the toolbar when exporting the chart, as shown below:
To add custom styles or modify the chart's appearance before exporting, use the `onBeforeExport` callback.
When exporting, the chart is rendered onto an iframe and then exported as an image or PDF.
The `onBeforeExport` callback gives you access to the iframe before the export process starts.
For example, you can hide the toolbar when exporting the chart, as shown below:

@bernardobelchior bernardobelchior enabled auto-merge (squash) July 8, 2025 08:06
@bernardobelchior bernardobelchior merged commit dcee0d9 into mui:master Jul 8, 2025
23 checks passed
@bernardobelchior bernardobelchior deleted the charts-export-on-before-export branch July 8, 2025 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants