@mui/x-charts-pro 8.0.0 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/BarChartPro/BarChartPro.js +7 -1
  2. package/BarChartPro/BarChartPro.plugins.d.ts +2 -1
  3. package/BarChartPro/BarChartPro.plugins.js +2 -1
  4. package/CHANGELOG.md +230 -5
  5. package/ChartContainerPro/ChartContainerPro.d.ts +1 -0
  6. package/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
  7. package/ChartDataProviderPro/ChartDataProviderPro.js +11 -2
  8. package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +3 -2
  9. package/ChartDataProviderPro/useChartDataProviderProProps.js +2 -0
  10. package/FunnelChart/FunnelChart.js +12 -1
  11. package/FunnelChart/FunnelPlot.d.ts +5 -0
  12. package/FunnelChart/FunnelPlot.js +13 -16
  13. package/FunnelChart/curves/bump.d.ts +24 -0
  14. package/FunnelChart/curves/bump.js +82 -0
  15. package/FunnelChart/curves/curve.types.d.ts +8 -0
  16. package/FunnelChart/curves/curve.types.js +5 -0
  17. package/FunnelChart/curves/funnelStep.d.ts +25 -0
  18. package/FunnelChart/{funnelStepCurve.js → curves/funnelStep.js} +32 -19
  19. package/FunnelChart/curves/getFunnelCurve.d.ts +3 -0
  20. package/FunnelChart/curves/getFunnelCurve.js +22 -0
  21. package/FunnelChart/curves/index.d.ts +2 -0
  22. package/FunnelChart/curves/index.js +27 -0
  23. package/FunnelChart/curves/linear.d.ts +24 -0
  24. package/FunnelChart/curves/linear.js +113 -0
  25. package/FunnelChart/funnel.types.d.ts +2 -2
  26. package/FunnelChart/funnelPlotSlots.types.d.ts +1 -1
  27. package/FunnelChart/funnelSectionClasses.d.ts +1 -1
  28. package/FunnelChart/index.d.ts +3 -2
  29. package/FunnelChart/useFunnelChartProps.d.ts +1 -1
  30. package/FunnelChart/useFunnelChartProps.js +7 -4
  31. package/Heatmap/Heatmap.js +5 -1
  32. package/Heatmap/HeatmapItem.js +1 -1
  33. package/LineChartPro/LineChartPro.js +7 -1
  34. package/LineChartPro/LineChartPro.plugins.d.ts +2 -1
  35. package/LineChartPro/LineChartPro.plugins.js +2 -1
  36. package/ScatterChartPro/ScatterChartPro.js +7 -1
  37. package/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -1
  38. package/ScatterChartPro/ScatterChartPro.plugins.js +2 -1
  39. package/esm/BarChartPro/BarChartPro.js +7 -1
  40. package/esm/BarChartPro/BarChartPro.plugins.d.ts +2 -1
  41. package/esm/BarChartPro/BarChartPro.plugins.js +2 -1
  42. package/esm/ChartContainerPro/ChartContainerPro.d.ts +1 -0
  43. package/esm/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
  44. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +11 -2
  45. package/esm/ChartDataProviderPro/useChartDataProviderProProps.d.ts +3 -2
  46. package/esm/ChartDataProviderPro/useChartDataProviderProProps.js +2 -0
  47. package/esm/FunnelChart/FunnelChart.js +12 -1
  48. package/esm/FunnelChart/FunnelPlot.d.ts +5 -0
  49. package/esm/FunnelChart/FunnelPlot.js +14 -17
  50. package/esm/FunnelChart/curves/bump.d.ts +24 -0
  51. package/esm/FunnelChart/curves/bump.js +75 -0
  52. package/esm/FunnelChart/curves/curve.types.d.ts +8 -0
  53. package/esm/FunnelChart/curves/curve.types.js +1 -0
  54. package/esm/FunnelChart/curves/funnelStep.d.ts +25 -0
  55. package/esm/FunnelChart/{funnelStepCurve.js → curves/funnelStep.js} +32 -19
  56. package/esm/FunnelChart/curves/getFunnelCurve.d.ts +3 -0
  57. package/esm/FunnelChart/curves/getFunnelCurve.js +15 -0
  58. package/esm/FunnelChart/curves/index.d.ts +2 -0
  59. package/esm/FunnelChart/curves/index.js +2 -0
  60. package/esm/FunnelChart/curves/linear.d.ts +24 -0
  61. package/esm/FunnelChart/curves/linear.js +106 -0
  62. package/esm/FunnelChart/funnel.types.d.ts +2 -2
  63. package/esm/FunnelChart/funnelPlotSlots.types.d.ts +1 -1
  64. package/esm/FunnelChart/funnelSectionClasses.d.ts +1 -1
  65. package/esm/FunnelChart/index.d.ts +3 -2
  66. package/esm/FunnelChart/useFunnelChartProps.d.ts +1 -1
  67. package/esm/FunnelChart/useFunnelChartProps.js +7 -4
  68. package/esm/Heatmap/Heatmap.js +5 -1
  69. package/esm/Heatmap/HeatmapItem.js +1 -1
  70. package/esm/LineChartPro/LineChartPro.js +7 -1
  71. package/esm/LineChartPro/LineChartPro.plugins.d.ts +2 -1
  72. package/esm/LineChartPro/LineChartPro.plugins.js +2 -1
  73. package/esm/ScatterChartPro/ScatterChartPro.js +7 -1
  74. package/esm/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -1
  75. package/esm/ScatterChartPro/ScatterChartPro.plugins.js +2 -1
  76. package/esm/index.d.ts +1 -0
  77. package/esm/index.js +2 -1
  78. package/esm/internals/plugins/allPlugins.d.ts +5 -4
  79. package/esm/internals/plugins/allPlugins.js +3 -2
  80. package/esm/internals/plugins/useChartProExport/common.d.ts +1 -0
  81. package/esm/internals/plugins/useChartProExport/common.js +8 -0
  82. package/esm/internals/plugins/useChartProExport/exportImage.d.ts +3 -0
  83. package/esm/internals/plugins/useChartProExport/exportImage.js +85 -0
  84. package/esm/internals/plugins/useChartProExport/index.d.ts +2 -0
  85. package/esm/internals/plugins/useChartProExport/index.js +2 -0
  86. package/esm/internals/plugins/useChartProExport/print.d.ts +4 -0
  87. package/esm/internals/plugins/useChartProExport/print.js +28 -0
  88. package/esm/internals/plugins/useChartProExport/useChartProExport.d.ts +3 -0
  89. package/esm/internals/plugins/useChartProExport/useChartProExport.js +65 -0
  90. package/esm/internals/plugins/useChartProExport/useChartProExport.types.d.ts +67 -0
  91. package/esm/internals/plugins/useChartProExport/useChartProExport.types.js +1 -0
  92. package/esm/internals/plugins/useChartProZoom/useChartProZoom.d.ts +2 -1
  93. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +54 -30
  94. package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +25 -25
  95. package/esm/locales/index.d.ts +1 -0
  96. package/esm/locales/index.js +1 -0
  97. package/esm/themeAugmentation/components.d.ts +0 -4
  98. package/esm/themeAugmentation/components.js +1 -0
  99. package/esm/themeAugmentation/index.d.ts +3 -3
  100. package/esm/themeAugmentation/overrides.d.ts +0 -3
  101. package/esm/themeAugmentation/overrides.js +2 -0
  102. package/esm/themeAugmentation/props.d.ts +0 -6
  103. package/esm/themeAugmentation/props.js +2 -0
  104. package/index.d.ts +1 -0
  105. package/index.js +12 -1
  106. package/internals/plugins/allPlugins.d.ts +5 -4
  107. package/internals/plugins/allPlugins.js +3 -2
  108. package/internals/plugins/useChartProExport/common.d.ts +1 -0
  109. package/internals/plugins/useChartProExport/common.js +14 -0
  110. package/internals/plugins/useChartProExport/exportImage.d.ts +3 -0
  111. package/internals/plugins/useChartProExport/exportImage.js +95 -0
  112. package/internals/plugins/useChartProExport/index.d.ts +2 -0
  113. package/internals/plugins/useChartProExport/index.js +27 -0
  114. package/internals/plugins/useChartProExport/print.d.ts +4 -0
  115. package/internals/plugins/useChartProExport/print.js +35 -0
  116. package/internals/plugins/useChartProExport/useChartProExport.d.ts +3 -0
  117. package/internals/plugins/useChartProExport/useChartProExport.js +73 -0
  118. package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +67 -0
  119. package/internals/plugins/useChartProExport/useChartProExport.types.js +5 -0
  120. package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +2 -1
  121. package/internals/plugins/useChartProZoom/useChartProZoom.js +54 -30
  122. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +25 -25
  123. package/locales/index.d.ts +1 -0
  124. package/locales/index.js +16 -0
  125. package/package.json +7 -4
  126. package/themeAugmentation/components.d.ts +0 -4
  127. package/themeAugmentation/components.js +5 -0
  128. package/themeAugmentation/index.d.ts +3 -3
  129. package/themeAugmentation/overrides.d.ts +0 -3
  130. package/themeAugmentation/overrides.js +5 -0
  131. package/themeAugmentation/props.d.ts +0 -6
  132. package/themeAugmentation/props.js +5 -0
  133. package/FunnelChart/funnelStepCurve.d.ts +0 -4
  134. package/esm/FunnelChart/funnelStepCurve.d.ts +0 -4
@@ -13,7 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  const HeatmapCell = styled('rect', {
14
14
  name: 'MuiHeatmap',
15
15
  slot: 'Cell',
16
- overridesResolver: (_, styles) => styles.arc
16
+ overridesResolver: (_, styles) => styles.arc // FIXME: Inconsistent naming with slot
17
17
  })(({
18
18
  ownerState
19
19
  }) => ({
@@ -89,6 +89,8 @@ process.env.NODE_ENV !== "production" ? LineChartPro.propTypes = {
89
89
  // ----------------------------------------------------------------------
90
90
  apiRef: PropTypes.shape({
91
91
  current: PropTypes.shape({
92
+ exportAsImage: PropTypes.func.isRequired,
93
+ exportAsPrint: PropTypes.func.isRequired,
92
94
  setZoomData: PropTypes.func.isRequired
93
95
  })
94
96
  }),
@@ -165,6 +167,10 @@ process.env.NODE_ENV !== "production" ? LineChartPro.propTypes = {
165
167
  * @default false
166
168
  */
167
169
  loading: PropTypes.bool,
170
+ /**
171
+ * Localized text for chart components.
172
+ */
173
+ localeText: PropTypes.object,
168
174
  /**
169
175
  * The margin between the SVG and the drawing area.
170
176
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
@@ -185,7 +191,7 @@ process.env.NODE_ENV !== "production" ? LineChartPro.propTypes = {
185
191
  * The function called for onClick events.
186
192
  * The second argument contains information about all line/bar elements at the current mouse position.
187
193
  * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
188
- * @param {null | AxisData} data The data about the clicked axis and items associated with it.
194
+ * @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
189
195
  */
190
196
  onAxisClick: PropTypes.func,
191
197
  /**
@@ -1,4 +1,5 @@
1
1
  import { UseChartZAxisSignature, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, ConvertSignaturesIntoPlugins } from '@mui/x-charts/internals';
2
+ import { UseChartProExportSignature } from "../internals/plugins/useChartProExport/index.js";
2
3
  import { UseChartProZoomSignature } from "../internals/plugins/useChartProZoom/index.js";
3
- export type LineChartProPluginsSignatures = [UseChartZAxisSignature, UseChartCartesianAxisSignature<'line'>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature];
4
+ export type LineChartProPluginsSignatures = [UseChartZAxisSignature, UseChartCartesianAxisSignature<'line'>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature, UseChartProExportSignature];
4
5
  export declare const LINE_CHART_PRO_PLUGINS: ConvertSignaturesIntoPlugins<LineChartProPluginsSignatures>;
@@ -1,3 +1,4 @@
1
1
  import { useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight } from '@mui/x-charts/internals';
2
+ import { useChartProExport } from "../internals/plugins/useChartProExport/index.js";
2
3
  import { useChartProZoom } from "../internals/plugins/useChartProZoom/index.js";
3
- export const LINE_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartProZoom];
4
+ export const LINE_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartProZoom, useChartProExport];
@@ -83,6 +83,8 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
83
83
  // ----------------------------------------------------------------------
84
84
  apiRef: PropTypes.shape({
85
85
  current: PropTypes.shape({
86
+ exportAsImage: PropTypes.func.isRequired,
87
+ exportAsPrint: PropTypes.func.isRequired,
86
88
  setZoomData: PropTypes.func.isRequired
87
89
  })
88
90
  }),
@@ -160,6 +162,10 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
160
162
  * @default false
161
163
  */
162
164
  loading: PropTypes.bool,
165
+ /**
166
+ * Localized text for chart components.
167
+ */
168
+ localeText: PropTypes.object,
163
169
  /**
164
170
  * The margin between the SVG and the drawing area.
165
171
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
@@ -176,7 +182,7 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
176
182
  * The function called for onClick events.
177
183
  * The second argument contains information about all line/bar elements at the current mouse position.
178
184
  * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
179
- * @param {null | AxisData} data The data about the clicked axis and items associated with it.
185
+ * @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
180
186
  */
181
187
  onAxisClick: PropTypes.func,
182
188
  /**
@@ -1,4 +1,5 @@
1
1
  import { UseChartZAxisSignature, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartVoronoiSignature, ConvertSignaturesIntoPlugins } from '@mui/x-charts/internals';
2
+ import { UseChartProExportSignature } from "../internals/plugins/useChartProExport/index.js";
2
3
  import { UseChartProZoomSignature } from "../internals/plugins/useChartProZoom/index.js";
3
- export type ScatterChartProPluginsSignatures = [UseChartZAxisSignature, UseChartCartesianAxisSignature<'scatter'>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartVoronoiSignature, UseChartProZoomSignature];
4
+ export type ScatterChartProPluginsSignatures = [UseChartZAxisSignature, UseChartCartesianAxisSignature<'scatter'>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartVoronoiSignature, UseChartProZoomSignature, UseChartProExportSignature];
4
5
  export declare const SCATTER_CHART_PRO_PLUGINS: ConvertSignaturesIntoPlugins<ScatterChartProPluginsSignatures>;
@@ -1,3 +1,4 @@
1
1
  import { useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartVoronoi } from '@mui/x-charts/internals';
2
+ import { useChartProExport } from "../internals/plugins/useChartProExport/index.js";
2
3
  import { useChartProZoom } from "../internals/plugins/useChartProZoom/index.js";
3
- export const SCATTER_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartVoronoi, useChartProZoom];
4
+ export const SCATTER_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartVoronoi, useChartProZoom, useChartProExport];
package/esm/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from '@mui/x-charts/ChartsGrid';
13
13
  export * from '@mui/x-charts/ChartsText';
14
14
  export * from '@mui/x-charts/ChartsTooltip';
15
15
  export * from '@mui/x-charts/ChartsLegend';
16
+ export * from '@mui/x-charts/ChartsLocalizationProvider';
16
17
  export * from '@mui/x-charts/ChartsAxisHighlight';
17
18
  export * from '@mui/x-charts/BarChart';
18
19
  export * from '@mui/x-charts/LineChart';
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts-pro v8.0.0
2
+ * @mui/x-charts-pro v8.2.0
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -22,6 +22,7 @@ export * from '@mui/x-charts/ChartsGrid';
22
22
  export * from '@mui/x-charts/ChartsText';
23
23
  export * from '@mui/x-charts/ChartsTooltip';
24
24
  export * from '@mui/x-charts/ChartsLegend';
25
+ export * from '@mui/x-charts/ChartsLocalizationProvider';
25
26
  export * from '@mui/x-charts/ChartsAxisHighlight';
26
27
  export * from '@mui/x-charts/BarChart';
27
28
  export * from '@mui/x-charts/LineChart';
@@ -1,8 +1,9 @@
1
1
  import { ChartSeriesType, ConvertSignaturesIntoPlugins, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartZAxisSignature, UseChartHighlightSignature, UseChartPolarAxisSignature } from '@mui/x-charts/internals';
2
+ import { UseChartProExportSignature } from "./useChartProExport/index.js";
2
3
  import { UseChartProZoomSignature } from "./useChartProZoom/index.js";
3
- export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature];
4
+ export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature, UseChartProExportSignature];
4
5
  export type AllPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<AllPluginSignatures<TSeries>>;
5
- export declare const ALL_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>> | import("@mui/x-charts/internals").ChartPlugin<UseChartPolarAxisSignature<any>>)[];
6
- export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature];
6
+ export declare const ALL_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartProExportSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>> | import("@mui/x-charts/internals").ChartPlugin<UseChartPolarAxisSignature<any>>)[];
7
+ export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature, UseChartProExportSignature];
7
8
  export type DefaultPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<DefaultPluginSignatures<TSeries>>;
8
- export declare const DEFAULT_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>>)[];
9
+ export declare const DEFAULT_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartProExportSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>>)[];
@@ -1,6 +1,7 @@
1
1
  // This file should be removed after creating all plugins in favor of a file per chart type.
2
2
 
3
3
  import { useChartCartesianAxis, useChartInteraction, useChartZAxis, useChartHighlight, useChartPolarAxis } from '@mui/x-charts/internals';
4
+ import { useChartProExport } from "./useChartProExport/index.js";
4
5
  import { useChartProZoom } from "./useChartProZoom/index.js";
5
- export const ALL_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartPolarAxis, useChartInteraction, useChartHighlight, useChartProZoom];
6
- export const DEFAULT_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartProZoom];
6
+ export const ALL_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartPolarAxis, useChartInteraction, useChartHighlight, useChartProZoom, useChartProExport];
7
+ export const DEFAULT_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartProZoom, useChartProExport];
@@ -0,0 +1 @@
1
+ export declare function createExportIframe(title?: string): HTMLIFrameElement;
@@ -0,0 +1,8 @@
1
+ export function createExportIframe(title) {
2
+ const iframeEl = document.createElement('iframe');
3
+ iframeEl.style.position = 'absolute';
4
+ iframeEl.style.width = '0px';
5
+ iframeEl.style.height = '0px';
6
+ iframeEl.title = title || document.title;
7
+ return iframeEl;
8
+ }
@@ -0,0 +1,3 @@
1
+ import { ChartImageExportOptions } from "./useChartProExport.types.js";
2
+ export declare const getDrawDocument: () => Promise<typeof import("rasterizehtml").drawDocument>;
3
+ export declare function exportImage(element: HTMLElement | SVGElement, params?: ChartImageExportOptions): Promise<void>;
@@ -0,0 +1,85 @@
1
+ import ownerDocument from '@mui/utils/ownerDocument';
2
+ import { loadStyleSheets } from '@mui/x-internals/export';
3
+ import { createExportIframe } from "./common.js";
4
+ export const getDrawDocument = async () => {
5
+ try {
6
+ const module = await import('rasterizehtml');
7
+ return module.drawDocument;
8
+ } catch (error) {
9
+ throw new Error(`MUI X Charts: Failed to import 'rasterizehtml' module. This dependency is mandatory when exporting a chart as an image. Make sure you have it installed as a dependency.`, {
10
+ cause: error
11
+ });
12
+ }
13
+ };
14
+ export async function exportImage(element, params) {
15
+ const {
16
+ fileName,
17
+ type = 'image/png',
18
+ quality = 0.9
19
+ } = params ?? {};
20
+ const drawDocumentPromise = getDrawDocument();
21
+ const {
22
+ width,
23
+ height
24
+ } = element.getBoundingClientRect();
25
+ const doc = ownerDocument(element);
26
+ const canvas = document.createElement('canvas');
27
+ const ratio = window.devicePixelRatio || 1;
28
+ canvas.width = width * ratio;
29
+ canvas.height = height * ratio;
30
+ canvas.style.width = `${width}px`;
31
+ canvas.style.height = `${height}px`;
32
+ const iframe = createExportIframe(fileName);
33
+ let resolve;
34
+ const iframeLoadPromise = new Promise(res => {
35
+ resolve = res;
36
+ });
37
+ iframe.onload = async () => {
38
+ const exportDoc = iframe.contentDocument;
39
+ const elementClone = element.cloneNode(true);
40
+ const container = document.createElement('div');
41
+ container.appendChild(elementClone);
42
+ exportDoc.body.innerHTML = container.innerHTML;
43
+ exportDoc.body.style.margin = '0px';
44
+ const rootCandidate = element.getRootNode();
45
+ const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
46
+ await Promise.all(loadStyleSheets(exportDoc, root));
47
+ resolve();
48
+ };
49
+ doc.body.appendChild(iframe);
50
+ const [drawDocument] = await Promise.all([drawDocumentPromise, iframeLoadPromise]);
51
+ try {
52
+ await drawDocument(iframe.contentDocument, canvas, {
53
+ // Handle retina displays: https://github.com/cburgmer/rasterizeHTML.js/blob/262b3404d1c469ce4a7750a2976dec09b8ae2d6c/examples/retina.html#L71
54
+ zoom: ratio
55
+ });
56
+ } finally {
57
+ doc.body.removeChild(iframe);
58
+ }
59
+ let resolveBlobPromise;
60
+ const blobPromise = new Promise(res => {
61
+ resolveBlobPromise = res;
62
+ });
63
+ canvas.toBlob(blob => resolveBlobPromise(blob), type, quality);
64
+ let blob;
65
+ try {
66
+ blob = await blobPromise;
67
+ } catch (error) {
68
+ throw new Error('MUI X Charts: Failed to create blob from canvas.', {
69
+ cause: error
70
+ });
71
+ }
72
+ if (!blob) {
73
+ throw new Error('MUI X Charts: Failed to create blob from canvas.');
74
+ return;
75
+ }
76
+ const url = URL.createObjectURL(blob);
77
+ triggerDownload(url, fileName || document.title);
78
+ URL.revokeObjectURL(url);
79
+ }
80
+ function triggerDownload(url, name) {
81
+ const a = document.createElement('a');
82
+ a.href = url;
83
+ a.download = name;
84
+ a.click();
85
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./useChartProExport.js";
2
+ export * from "./useChartProExport.types.js";
@@ -0,0 +1,2 @@
1
+ export * from "./useChartProExport.js";
2
+ export * from "./useChartProExport.types.js";
@@ -0,0 +1,4 @@
1
+ import { ChartPrintExportOptions } from "./useChartProExport.types.js";
2
+ export declare function printChart(element: HTMLElement | SVGElement, {
3
+ fileName
4
+ }?: ChartPrintExportOptions): void;
@@ -0,0 +1,28 @@
1
+ import ownerDocument from '@mui/utils/ownerDocument';
2
+ import { loadStyleSheets } from '@mui/x-internals/export';
3
+ import { createExportIframe } from "./common.js";
4
+ export function printChart(element, {
5
+ fileName
6
+ } = {}) {
7
+ const printWindow = createExportIframe(fileName);
8
+ const doc = ownerDocument(element);
9
+ printWindow.onload = async () => {
10
+ const printDoc = printWindow.contentDocument;
11
+ const elementClone = element.cloneNode(true);
12
+ const container = document.createElement('div');
13
+ container.appendChild(elementClone);
14
+ printDoc.body.innerHTML = container.innerHTML;
15
+ const rootCandidate = element.getRootNode();
16
+ const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
17
+ await Promise.all(loadStyleSheets(printDoc, root));
18
+ printWindow.contentWindow.print();
19
+ const mediaQueryList = printWindow.contentWindow.matchMedia('print');
20
+ mediaQueryList.addEventListener('change', mql => {
21
+ const isAfterPrint = mql.matches === false;
22
+ if (isAfterPrint) {
23
+ doc.body.removeChild(printWindow);
24
+ }
25
+ });
26
+ };
27
+ doc.body.appendChild(printWindow);
28
+ }
@@ -0,0 +1,3 @@
1
+ import { ChartPlugin } from '@mui/x-charts/internals';
2
+ import { UseChartProExportSignature } from "./useChartProExport.types.js";
3
+ export declare const useChartProExport: ChartPlugin<UseChartProExportSignature>;
@@ -0,0 +1,65 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { printChart } from "./print.js";
3
+ import { exportImage } from "./exportImage.js";
4
+ function waitForAnimationFrame() {
5
+ let resolve;
6
+ const promise = new Promise(res => {
7
+ resolve = res;
8
+ });
9
+ window.requestAnimationFrame(() => {
10
+ resolve();
11
+ });
12
+ return promise;
13
+ }
14
+ export const useChartProExport = ({
15
+ chartRootRef,
16
+ instance
17
+ }) => {
18
+ const exportAsPrint = async options => {
19
+ const chartRoot = chartRootRef.current;
20
+ if (chartRoot) {
21
+ const enableAnimation = instance.disableAnimation();
22
+ try {
23
+ // Wait for animation frame to ensure the animation finished
24
+ await waitForAnimationFrame();
25
+ printChart(chartRoot, options);
26
+ } catch (error) {
27
+ console.error('MUI X Charts: Error exporting chart as print:', error);
28
+ } finally {
29
+ enableAnimation();
30
+ }
31
+ }
32
+ };
33
+ const exportAsImage = async options => {
34
+ const chartRoot = chartRootRef.current;
35
+ if (chartRoot) {
36
+ const enableAnimation = instance.disableAnimation();
37
+ try {
38
+ // Wait for animation frame to ensure the animation finished
39
+ await waitForAnimationFrame();
40
+ await exportImage(chartRoot, options);
41
+ } catch (error) {
42
+ console.error('MUI X Charts: Error exporting chart as image:', error);
43
+ } finally {
44
+ enableAnimation();
45
+ }
46
+ }
47
+ };
48
+ return {
49
+ publicAPI: {
50
+ exportAsPrint,
51
+ exportAsImage
52
+ },
53
+ instance: {
54
+ exportAsPrint,
55
+ exportAsImage
56
+ }
57
+ };
58
+ };
59
+ useChartProExport.params = {};
60
+ useChartProExport.getDefaultizedParams = ({
61
+ params
62
+ }) => _extends({}, params);
63
+ useChartProExport.getInitialState = () => ({
64
+ export: {}
65
+ });
@@ -0,0 +1,67 @@
1
+ import { UseChartSeriesSignature, ChartPluginSignature, UseChartCartesianAxisSignature } from '@mui/x-charts/internals';
2
+ export interface UseChartProExportParameters {}
3
+ export type UseChartProExportDefaultizedParameters = UseChartProExportParameters;
4
+ export interface UseChartProExportState {
5
+ export: {};
6
+ }
7
+ /**
8
+ * The options to apply on the Print export.
9
+ * @demos
10
+ * - [Print export](/x/react-charts/export/#print-export-as-pdf)
11
+ */
12
+ export interface ChartPrintExportOptions {
13
+ /**
14
+ * The value to be used as the print window title.
15
+ * @default The title of the page.
16
+ */
17
+ fileName?: string;
18
+ }
19
+ /**
20
+ * The options to apply on the image export.
21
+ * @demos
22
+ * - [Image export](/x/react-charts/export/#export-as-image)
23
+ */
24
+ export interface ChartImageExportOptions {
25
+ /**
26
+ * The value to be used as the print window title.
27
+ * @default The title of the page.
28
+ */
29
+ fileName?: string;
30
+ /**
31
+ * The format of the image to be exported.
32
+ * Browsers are required to support 'image/png'. Some browsers also support 'image/jpeg' and 'image/webp'.
33
+ * @default 'image/png'
34
+ */
35
+ type?: 'image/png' | string;
36
+ /**
37
+ * The quality of the image to be exported between 0 and 1. This is only applicable for lossy formats, such as
38
+ * 'image/jpeg' and 'image/webp'. 'image/png' does not support this option.
39
+ * @default 0.9
40
+ */
41
+ quality?: number;
42
+ }
43
+ export interface UseChartProExportPublicApi {
44
+ /**
45
+ * Opens the browser's print dialog, which can be used to print the chart or export it as PDF.
46
+ * @param {ChartPrintExportOptions} options Options to customize the print export.
47
+ * @returns {void}
48
+ */
49
+ exportAsPrint: (options?: ChartPrintExportOptions) => void;
50
+ /**
51
+ * Exports the chart as an image.
52
+ * If the provided `type` is not supported by the browser, it will default to `image/png`.
53
+ *
54
+ * @param {ChartPrintExportOptions} options Options to customize the print export.
55
+ * @returns {void}
56
+ */
57
+ exportAsImage: (options?: ChartImageExportOptions) => void;
58
+ }
59
+ export interface UseChartProExportInstance extends UseChartProExportPublicApi {}
60
+ export type UseChartProExportSignature = ChartPluginSignature<{
61
+ params: UseChartProExportParameters;
62
+ defaultizedParams: UseChartProExportDefaultizedParameters;
63
+ state: UseChartProExportState;
64
+ publicAPI: UseChartProExportPublicApi;
65
+ instance: UseChartProExportInstance;
66
+ dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
67
+ }>;
@@ -1,3 +1,4 @@
1
- import { ChartPlugin } from '@mui/x-charts/internals';
1
+ import { ChartPlugin, AxisId, DefaultizedZoomOptions, ZoomData } from '@mui/x-charts/internals';
2
2
  import { UseChartProZoomSignature } from "./useChartProZoom.types.js";
3
+ export declare function initializeZoomData(options: Record<AxisId, DefaultizedZoomOptions>, zoomData?: readonly ZoomData[]): ZoomData[];
3
4
  export declare const useChartProZoom: ChartPlugin<UseChartProZoomSignature>;
@@ -7,17 +7,30 @@ import { useEventCallback } from '@mui/material/utils';
7
7
  import { rafThrottle } from '@mui/x-internals/rafThrottle';
8
8
  import debounce from '@mui/utils/debounce';
9
9
  import { getDiff, getHorizontalCenterRatio, getPinchScaleRatio, getVerticalCenterRatio, getWheelScaleRatio, isSpanValid, preventDefault, zoomAtPoint } from "./useChartProZoom.utils.js";
10
+
10
11
  // It is helpful to avoid the need to provide the possibly auto-generated id for each axis.
11
- function initializeZoomData(options) {
12
+ export function initializeZoomData(options, zoomData) {
13
+ const zoomDataMap = new Map();
14
+ zoomData?.forEach(zoom => {
15
+ const option = options[zoom.axisId];
16
+ if (option) {
17
+ zoomDataMap.set(zoom.axisId, zoom);
18
+ }
19
+ });
12
20
  return Object.values(options).map(({
13
21
  axisId,
14
22
  minStart: start,
15
23
  maxEnd: end
16
- }) => ({
17
- axisId,
18
- start,
19
- end
20
- }));
24
+ }) => {
25
+ if (zoomDataMap.has(axisId)) {
26
+ return zoomDataMap.get(axisId);
27
+ }
28
+ return {
29
+ axisId,
30
+ start,
31
+ end
32
+ };
33
+ });
21
34
  }
22
35
  export const useChartProZoom = ({
23
36
  store,
@@ -41,7 +54,7 @@ export const useChartProZoom = ({
41
54
  }
42
55
  store.update(prevState => {
43
56
  if (process.env.NODE_ENV !== 'production' && !prevState.zoom.isControlled) {
44
- console.error([`MUI X: A chart component is changing the \`zoomData\` from uncontrolled to controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', 'Decide between using a controlled or uncontrolled for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
57
+ console.error([`MUI X Charts: A chart component is changing the \`zoomData\` from uncontrolled to controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', 'Decide between using a controlled or uncontrolled for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
45
58
  }
46
59
  return _extends({}, prevState, {
47
60
  zoom: _extends({}, prevState.zoom, {
@@ -72,10 +85,7 @@ export const useChartProZoom = ({
72
85
  })
73
86
  });
74
87
  }), 166), [store]);
75
-
76
- // This is throttled. We want to run it at most once per frame.
77
- // By joining the two, we ensure that interacting and zooming are in sync.
78
- const setZoomDataCallback = React.useMemo(() => rafThrottle(zoomData => {
88
+ const setZoomDataCallback = React.useCallback(zoomData => {
79
89
  store.update(prevState => {
80
90
  const newZoomData = typeof zoomData === 'function' ? zoomData([...prevState.zoom.zoomData]) : zoomData;
81
91
  onZoomChange?.(newZoomData);
@@ -90,10 +100,9 @@ export const useChartProZoom = ({
90
100
  })
91
101
  });
92
102
  });
93
- }), [onZoomChange, store, removeIsInteracting]);
103
+ }, [onZoomChange, store, removeIsInteracting]);
94
104
  React.useEffect(() => {
95
105
  return () => {
96
- setZoomDataCallback.clear();
97
106
  removeIsInteracting.clear();
98
107
  };
99
108
  }, [setZoomDataCallback, removeIsInteracting]);
@@ -112,17 +121,10 @@ export const useChartProZoom = ({
112
121
  if (element === null || !isPanEnabled) {
113
122
  return () => {};
114
123
  }
115
- const handlePan = event => {
116
- if (element === null || !isDraggingRef.current || panningEventCacheRef.current.length > 1) {
117
- return;
118
- }
119
- if (touchStartRef.current == null) {
120
- return;
121
- }
122
- const point = getSVGPoint(element, event);
123
- const movementX = point.x - touchStartRef.current.x;
124
- const movementY = (point.y - touchStartRef.current.y) * -1;
125
- const newZoomData = touchStartRef.current.zoomData.map(zoom => {
124
+ const throttledHandlePan = rafThrottle((touchStart, point) => {
125
+ const movementX = point.x - touchStart.x;
126
+ const movementY = (point.y - touchStart.y) * -1;
127
+ const newZoomData = touchStart.zoomData.map(zoom => {
126
128
  const options = optionsLookup[zoom.axisId];
127
129
  if (!options || !options.panning) {
128
130
  return zoom;
@@ -153,6 +155,17 @@ export const useChartProZoom = ({
153
155
  });
154
156
  });
155
157
  setZoomDataCallback(newZoomData);
158
+ });
159
+ const handlePan = event => {
160
+ if (element === null || !isDraggingRef.current || panningEventCacheRef.current.length > 1) {
161
+ return;
162
+ }
163
+ if (touchStartRef.current == null) {
164
+ return;
165
+ }
166
+ const touchStart = touchStartRef.current;
167
+ const point = getSVGPoint(element, event);
168
+ throttledHandlePan(touchStart, point);
156
169
  };
157
170
  const handleDown = event => {
158
171
  panningEventCacheRef.current.push(event);
@@ -187,6 +200,7 @@ export const useChartProZoom = ({
187
200
  document.removeEventListener('pointerup', handleUp);
188
201
  document.removeEventListener('pointercancel', handleUp);
189
202
  document.removeEventListener('pointerleave', handleUp);
203
+ throttledHandlePan.clear();
190
204
  };
191
205
  }, [instance, svgRef, isDraggingRef, isPanEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store]);
192
206
 
@@ -196,6 +210,7 @@ export const useChartProZoom = ({
196
210
  if (element === null || !isZoomEnabled) {
197
211
  return () => {};
198
212
  }
213
+ const rafThrottledSetZoomData = rafThrottle(setZoomDataCallback);
199
214
  const wheelHandler = event => {
200
215
  if (element === null) {
201
216
  return;
@@ -205,7 +220,13 @@ export const useChartProZoom = ({
205
220
  return;
206
221
  }
207
222
  event.preventDefault();
208
- setZoomDataCallback(prevZoomData => {
223
+
224
+ /*
225
+ * Need to throttle `setZoomDataCallback` instead of `wheelHandler` because we're calling `event.preventDefault()`.
226
+ * If we throttle the event, then some events' default behavior won't be prevented and the page will scroll while
227
+ * the user is trying to zoom in.
228
+ */
229
+ rafThrottledSetZoomData(prevZoomData => {
209
230
  return prevZoomData.map(zoom => {
210
231
  const option = optionsLookup[zoom.axisId];
211
232
  if (!option) {
@@ -231,7 +252,7 @@ export const useChartProZoom = ({
231
252
  function pointerDownHandler(event) {
232
253
  zoomEventCacheRef.current.push(event);
233
254
  }
234
- function pointerMoveHandler(event) {
255
+ const pointerMoveHandler = rafThrottle(function pointerMoveHandler(event) {
235
256
  if (element === null) {
236
257
  return;
237
258
  }
@@ -274,7 +295,7 @@ export const useChartProZoom = ({
274
295
  eventPrevDiff.current = curDiff;
275
296
  return newZoomData;
276
297
  });
277
- }
298
+ });
278
299
  function pointerUpHandler(event) {
279
300
  zoomEventCacheRef.current.splice(zoomEventCacheRef.current.findIndex(cachedEvent => cachedEvent.pointerId === event.pointerId), 1);
280
301
  if (zoomEventCacheRef.current.length < 2) {
@@ -302,6 +323,8 @@ export const useChartProZoom = ({
302
323
  element.removeEventListener('pointerleave', pointerUpHandler);
303
324
  element.removeEventListener('touchstart', preventDefault);
304
325
  element.removeEventListener('touchmove', preventDefault);
326
+ pointerMoveHandler.clear();
327
+ rafThrottledSetZoomData.clear();
305
328
  };
306
329
  }, [svgRef, drawingArea, isZoomEnabled, optionsLookup, instance, setZoomDataCallback]);
307
330
  return {
@@ -331,11 +354,12 @@ useChartProZoom.getInitialState = params => {
331
354
  defaultizedYAxis
332
355
  } = params;
333
356
  const optionsLookup = _extends({}, createZoomLookup('x')(defaultizedXAxis), createZoomLookup('y')(defaultizedYAxis));
357
+ const userZoomData =
358
+ // eslint-disable-next-line no-nested-ternary
359
+ zoomData !== undefined ? zoomData : initialZoom !== undefined ? initialZoom : undefined;
334
360
  return {
335
361
  zoom: {
336
- zoomData:
337
- // eslint-disable-next-line no-nested-ternary
338
- zoomData !== undefined ? zoomData : initialZoom !== undefined ? initialZoom : initializeZoomData(optionsLookup),
362
+ zoomData: initializeZoomData(optionsLookup, userZoomData),
339
363
  isInteracting: false,
340
364
  isControlled: zoomData !== undefined
341
365
  }