@mui/x-charts-pro 8.0.0 → 8.1.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 (66) hide show
  1. package/BarChartPro/BarChartPro.js +5 -0
  2. package/BarChartPro/BarChartPro.plugins.d.ts +2 -1
  3. package/BarChartPro/BarChartPro.plugins.js +2 -1
  4. package/CHANGELOG.md +106 -0
  5. package/ChartContainerPro/ChartContainerPro.d.ts +1 -0
  6. package/ChartDataProviderPro/ChartDataProviderPro.js +11 -2
  7. package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +1 -0
  8. package/ChartDataProviderPro/useChartDataProviderProProps.js +2 -0
  9. package/FunnelChart/FunnelChart.js +5 -0
  10. package/Heatmap/Heatmap.js +4 -0
  11. package/Heatmap/HeatmapItem.js +1 -1
  12. package/LineChartPro/LineChartPro.js +5 -0
  13. package/LineChartPro/LineChartPro.plugins.d.ts +2 -1
  14. package/LineChartPro/LineChartPro.plugins.js +2 -1
  15. package/ScatterChartPro/ScatterChartPro.js +5 -0
  16. package/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -1
  17. package/ScatterChartPro/ScatterChartPro.plugins.js +2 -1
  18. package/esm/BarChartPro/BarChartPro.js +5 -0
  19. package/esm/BarChartPro/BarChartPro.plugins.d.ts +2 -1
  20. package/esm/BarChartPro/BarChartPro.plugins.js +2 -1
  21. package/esm/ChartContainerPro/ChartContainerPro.d.ts +1 -0
  22. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +11 -2
  23. package/esm/ChartDataProviderPro/useChartDataProviderProProps.d.ts +1 -0
  24. package/esm/ChartDataProviderPro/useChartDataProviderProProps.js +2 -0
  25. package/esm/FunnelChart/FunnelChart.js +5 -0
  26. package/esm/Heatmap/Heatmap.js +4 -0
  27. package/esm/Heatmap/HeatmapItem.js +1 -1
  28. package/esm/LineChartPro/LineChartPro.js +5 -0
  29. package/esm/LineChartPro/LineChartPro.plugins.d.ts +2 -1
  30. package/esm/LineChartPro/LineChartPro.plugins.js +2 -1
  31. package/esm/ScatterChartPro/ScatterChartPro.js +5 -0
  32. package/esm/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -1
  33. package/esm/ScatterChartPro/ScatterChartPro.plugins.js +2 -1
  34. package/esm/index.d.ts +1 -0
  35. package/esm/index.js +2 -1
  36. package/esm/internals/plugins/allPlugins.d.ts +5 -4
  37. package/esm/internals/plugins/allPlugins.js +3 -2
  38. package/esm/internals/plugins/useChartProExport/index.d.ts +2 -0
  39. package/esm/internals/plugins/useChartProExport/index.js +2 -0
  40. package/esm/internals/plugins/useChartProExport/print.d.ts +4 -0
  41. package/esm/internals/plugins/useChartProExport/print.js +72 -0
  42. package/esm/internals/plugins/useChartProExport/useChartProExport.d.ts +3 -0
  43. package/esm/internals/plugins/useChartProExport/useChartProExport.js +45 -0
  44. package/esm/internals/plugins/useChartProExport/useChartProExport.types.d.ts +35 -0
  45. package/esm/internals/plugins/useChartProExport/useChartProExport.types.js +1 -0
  46. package/esm/internals/plugins/useChartProZoom/useChartProZoom.d.ts +2 -1
  47. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +53 -29
  48. package/esm/locales/index.d.ts +1 -0
  49. package/esm/locales/index.js +1 -0
  50. package/index.d.ts +1 -0
  51. package/index.js +12 -1
  52. package/internals/plugins/allPlugins.d.ts +5 -4
  53. package/internals/plugins/allPlugins.js +3 -2
  54. package/internals/plugins/useChartProExport/index.d.ts +2 -0
  55. package/internals/plugins/useChartProExport/index.js +27 -0
  56. package/internals/plugins/useChartProExport/print.d.ts +4 -0
  57. package/internals/plugins/useChartProExport/print.js +79 -0
  58. package/internals/plugins/useChartProExport/useChartProExport.d.ts +3 -0
  59. package/internals/plugins/useChartProExport/useChartProExport.js +53 -0
  60. package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +35 -0
  61. package/internals/plugins/useChartProExport/useChartProExport.types.js +5 -0
  62. package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +2 -1
  63. package/internals/plugins/useChartProZoom/useChartProZoom.js +53 -29
  64. package/locales/index.d.ts +1 -0
  65. package/locales/index.js +16 -0
  66. package/package.json +3 -3
@@ -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,72 @@
1
+ import ownerDocument from '@mui/utils/ownerDocument';
2
+ export function printChart(element, {
3
+ fileName
4
+ } = {}) {
5
+ const printWindow = buildPrintWindow(fileName);
6
+ const doc = ownerDocument(element);
7
+ printWindow.onload = async () => {
8
+ const printDoc = printWindow.contentDocument;
9
+ const elementClone = element.cloneNode(true);
10
+ const container = document.createElement('div');
11
+ container.appendChild(elementClone);
12
+ printDoc.body.innerHTML = container.innerHTML;
13
+ await loadStyleSheets(printDoc, element);
14
+ printWindow.contentWindow.print();
15
+ const mediaQueryList = printWindow.contentWindow.matchMedia('print');
16
+ mediaQueryList.addEventListener('change', mql => {
17
+ const isAfterPrint = mql.matches === false;
18
+ if (isAfterPrint) {
19
+ doc.body.removeChild(printWindow);
20
+ }
21
+ });
22
+ };
23
+ doc.body.appendChild(printWindow);
24
+ }
25
+ function buildPrintWindow(title) {
26
+ const iframeEl = document.createElement('iframe');
27
+ iframeEl.style.position = 'absolute';
28
+ iframeEl.style.width = '0px';
29
+ iframeEl.style.height = '0px';
30
+ iframeEl.title = title || document.title;
31
+ return iframeEl;
32
+ }
33
+ function loadStyleSheets(printDoc, element) {
34
+ const stylesheetLoadPromises = [];
35
+ const doc = ownerDocument(element);
36
+ const rootCandidate = element.getRootNode();
37
+ const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
38
+ const headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
39
+ for (let i = 0; i < headStyleElements.length; i += 1) {
40
+ const node = headStyleElements[i];
41
+ if (node.tagName === 'STYLE') {
42
+ const newHeadStyleElements = printDoc.createElement(node.tagName);
43
+ const sheet = node.sheet;
44
+ if (sheet) {
45
+ let styleCSS = '';
46
+ // NOTE: for-of is not supported by IE
47
+ for (let j = 0; j < sheet.cssRules.length; j += 1) {
48
+ if (typeof sheet.cssRules[j].cssText === 'string') {
49
+ styleCSS += `${sheet.cssRules[j].cssText}\r\n`;
50
+ }
51
+ }
52
+ newHeadStyleElements.appendChild(printDoc.createTextNode(styleCSS));
53
+ printDoc.head.appendChild(newHeadStyleElements);
54
+ }
55
+ } else if (node.getAttribute('href')) {
56
+ // If `href` tag is empty, avoid loading these links
57
+
58
+ const newHeadStyleElements = printDoc.createElement(node.tagName);
59
+ for (let j = 0; j < node.attributes.length; j += 1) {
60
+ const attr = node.attributes[j];
61
+ if (attr) {
62
+ newHeadStyleElements.setAttribute(attr.nodeName, attr.nodeValue || '');
63
+ }
64
+ }
65
+ stylesheetLoadPromises.push(new Promise(resolve => {
66
+ newHeadStyleElements.addEventListener('load', () => resolve());
67
+ }));
68
+ printDoc.head.appendChild(newHeadStyleElements);
69
+ }
70
+ }
71
+ return Promise.all(stylesheetLoadPromises);
72
+ }
@@ -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,45 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { printChart } from "./print.js";
3
+ function waitForAnimationFrame() {
4
+ let resolve;
5
+ const promise = new Promise(res => {
6
+ resolve = res;
7
+ });
8
+ window.requestAnimationFrame(() => {
9
+ resolve();
10
+ });
11
+ return promise;
12
+ }
13
+ export const useChartProExport = ({
14
+ chartRootRef,
15
+ instance
16
+ }) => {
17
+ const exportAsPrint = async options => {
18
+ const chartRoot = chartRootRef.current;
19
+ if (chartRoot) {
20
+ const enableAnimation = instance.disableAnimation();
21
+ try {
22
+ // Wait for animation frame to ensure the animation finished
23
+ await waitForAnimationFrame();
24
+ printChart(chartRoot, options);
25
+ } finally {
26
+ enableAnimation();
27
+ }
28
+ }
29
+ };
30
+ return {
31
+ publicAPI: {
32
+ exportAsPrint
33
+ },
34
+ instance: {
35
+ exportAsPrint
36
+ }
37
+ };
38
+ };
39
+ useChartProExport.params = {};
40
+ useChartProExport.getDefaultizedParams = ({
41
+ params
42
+ }) => _extends({}, params);
43
+ useChartProExport.getInitialState = () => ({
44
+ export: {}
45
+ });
@@ -0,0 +1,35 @@
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
+ export interface UseChartProExportPublicApi {
20
+ /**
21
+ * Opens the browser's print dialog, which can be used to print the chart or export it as PDF.
22
+ * @param {ChartPrintExportOptions} options Options to customize the print export.
23
+ * @returns {void}
24
+ */
25
+ exportAsPrint: (options?: ChartPrintExportOptions) => void;
26
+ }
27
+ export interface UseChartProExportInstance extends UseChartProExportPublicApi {}
28
+ export type UseChartProExportSignature = ChartPluginSignature<{
29
+ params: UseChartProExportParameters;
30
+ defaultizedParams: UseChartProExportDefaultizedParameters;
31
+ state: UseChartProExportState;
32
+ publicAPI: UseChartProExportPublicApi;
33
+ instance: UseChartProExportInstance;
34
+ dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
35
+ }>;
@@ -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,
@@ -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
  }
@@ -0,0 +1 @@
1
+ export * from '@mui/x-charts/locales';
@@ -0,0 +1 @@
1
+ export * from '@mui/x-charts/locales';
package/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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts-pro v8.0.0
2
+ * @mui/x-charts-pro v8.1.0
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -165,6 +165,17 @@ Object.keys(_ChartsLegend).forEach(function (key) {
165
165
  }
166
166
  });
167
167
  });
168
+ var _ChartsLocalizationProvider = require("@mui/x-charts/ChartsLocalizationProvider");
169
+ Object.keys(_ChartsLocalizationProvider).forEach(function (key) {
170
+ if (key === "default" || key === "__esModule") return;
171
+ if (key in exports && exports[key] === _ChartsLocalizationProvider[key]) return;
172
+ Object.defineProperty(exports, key, {
173
+ enumerable: true,
174
+ get: function () {
175
+ return _ChartsLocalizationProvider[key];
176
+ }
177
+ });
178
+ });
168
179
  var _ChartsAxisHighlight = require("@mui/x-charts/ChartsAxisHighlight");
169
180
  Object.keys(_ChartsAxisHighlight).forEach(function (key) {
170
181
  if (key === "default" || key === "__esModule") return;
@@ -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>>)[];
@@ -5,8 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.DEFAULT_PLUGINS = exports.ALL_PLUGINS = void 0;
7
7
  var _internals = require("@mui/x-charts/internals");
8
+ var _useChartProExport = require("./useChartProExport");
8
9
  var _useChartProZoom = require("./useChartProZoom");
9
10
  // This file should be removed after creating all plugins in favor of a file per chart type.
10
11
 
11
- const ALL_PLUGINS = exports.ALL_PLUGINS = [_internals.useChartZAxis, _internals.useChartCartesianAxis, _internals.useChartPolarAxis, _internals.useChartInteraction, _internals.useChartHighlight, _useChartProZoom.useChartProZoom];
12
- const DEFAULT_PLUGINS = exports.DEFAULT_PLUGINS = [_internals.useChartZAxis, _internals.useChartCartesianAxis, _internals.useChartInteraction, _internals.useChartHighlight, _useChartProZoom.useChartProZoom];
12
+ const ALL_PLUGINS = exports.ALL_PLUGINS = [_internals.useChartZAxis, _internals.useChartCartesianAxis, _internals.useChartPolarAxis, _internals.useChartInteraction, _internals.useChartHighlight, _useChartProZoom.useChartProZoom, _useChartProExport.useChartProExport];
13
+ const DEFAULT_PLUGINS = exports.DEFAULT_PLUGINS = [_internals.useChartZAxis, _internals.useChartCartesianAxis, _internals.useChartInteraction, _internals.useChartHighlight, _useChartProZoom.useChartProZoom, _useChartProExport.useChartProExport];
@@ -0,0 +1,2 @@
1
+ export * from "./useChartProExport.js";
2
+ export * from "./useChartProExport.types.js";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _useChartProExport = require("./useChartProExport");
7
+ Object.keys(_useChartProExport).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _useChartProExport[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _useChartProExport[key];
14
+ }
15
+ });
16
+ });
17
+ var _useChartProExport2 = require("./useChartProExport.types");
18
+ Object.keys(_useChartProExport2).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _useChartProExport2[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _useChartProExport2[key];
25
+ }
26
+ });
27
+ });
@@ -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,79 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.printChart = printChart;
8
+ var _ownerDocument = _interopRequireDefault(require("@mui/utils/ownerDocument"));
9
+ function printChart(element, {
10
+ fileName
11
+ } = {}) {
12
+ const printWindow = buildPrintWindow(fileName);
13
+ const doc = (0, _ownerDocument.default)(element);
14
+ printWindow.onload = async () => {
15
+ const printDoc = printWindow.contentDocument;
16
+ const elementClone = element.cloneNode(true);
17
+ const container = document.createElement('div');
18
+ container.appendChild(elementClone);
19
+ printDoc.body.innerHTML = container.innerHTML;
20
+ await loadStyleSheets(printDoc, element);
21
+ printWindow.contentWindow.print();
22
+ const mediaQueryList = printWindow.contentWindow.matchMedia('print');
23
+ mediaQueryList.addEventListener('change', mql => {
24
+ const isAfterPrint = mql.matches === false;
25
+ if (isAfterPrint) {
26
+ doc.body.removeChild(printWindow);
27
+ }
28
+ });
29
+ };
30
+ doc.body.appendChild(printWindow);
31
+ }
32
+ function buildPrintWindow(title) {
33
+ const iframeEl = document.createElement('iframe');
34
+ iframeEl.style.position = 'absolute';
35
+ iframeEl.style.width = '0px';
36
+ iframeEl.style.height = '0px';
37
+ iframeEl.title = title || document.title;
38
+ return iframeEl;
39
+ }
40
+ function loadStyleSheets(printDoc, element) {
41
+ const stylesheetLoadPromises = [];
42
+ const doc = (0, _ownerDocument.default)(element);
43
+ const rootCandidate = element.getRootNode();
44
+ const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
45
+ const headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
46
+ for (let i = 0; i < headStyleElements.length; i += 1) {
47
+ const node = headStyleElements[i];
48
+ if (node.tagName === 'STYLE') {
49
+ const newHeadStyleElements = printDoc.createElement(node.tagName);
50
+ const sheet = node.sheet;
51
+ if (sheet) {
52
+ let styleCSS = '';
53
+ // NOTE: for-of is not supported by IE
54
+ for (let j = 0; j < sheet.cssRules.length; j += 1) {
55
+ if (typeof sheet.cssRules[j].cssText === 'string') {
56
+ styleCSS += `${sheet.cssRules[j].cssText}\r\n`;
57
+ }
58
+ }
59
+ newHeadStyleElements.appendChild(printDoc.createTextNode(styleCSS));
60
+ printDoc.head.appendChild(newHeadStyleElements);
61
+ }
62
+ } else if (node.getAttribute('href')) {
63
+ // If `href` tag is empty, avoid loading these links
64
+
65
+ const newHeadStyleElements = printDoc.createElement(node.tagName);
66
+ for (let j = 0; j < node.attributes.length; j += 1) {
67
+ const attr = node.attributes[j];
68
+ if (attr) {
69
+ newHeadStyleElements.setAttribute(attr.nodeName, attr.nodeValue || '');
70
+ }
71
+ }
72
+ stylesheetLoadPromises.push(new Promise(resolve => {
73
+ newHeadStyleElements.addEventListener('load', () => resolve());
74
+ }));
75
+ printDoc.head.appendChild(newHeadStyleElements);
76
+ }
77
+ }
78
+ return Promise.all(stylesheetLoadPromises);
79
+ }
@@ -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,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useChartProExport = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _print = require("./print");
10
+ function waitForAnimationFrame() {
11
+ let resolve;
12
+ const promise = new Promise(res => {
13
+ resolve = res;
14
+ });
15
+ window.requestAnimationFrame(() => {
16
+ resolve();
17
+ });
18
+ return promise;
19
+ }
20
+ const useChartProExport = ({
21
+ chartRootRef,
22
+ instance
23
+ }) => {
24
+ const exportAsPrint = async options => {
25
+ const chartRoot = chartRootRef.current;
26
+ if (chartRoot) {
27
+ const enableAnimation = instance.disableAnimation();
28
+ try {
29
+ // Wait for animation frame to ensure the animation finished
30
+ await waitForAnimationFrame();
31
+ (0, _print.printChart)(chartRoot, options);
32
+ } finally {
33
+ enableAnimation();
34
+ }
35
+ }
36
+ };
37
+ return {
38
+ publicAPI: {
39
+ exportAsPrint
40
+ },
41
+ instance: {
42
+ exportAsPrint
43
+ }
44
+ };
45
+ };
46
+ exports.useChartProExport = useChartProExport;
47
+ useChartProExport.params = {};
48
+ useChartProExport.getDefaultizedParams = ({
49
+ params
50
+ }) => (0, _extends2.default)({}, params);
51
+ useChartProExport.getInitialState = () => ({
52
+ export: {}
53
+ });
@@ -0,0 +1,35 @@
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
+ export interface UseChartProExportPublicApi {
20
+ /**
21
+ * Opens the browser's print dialog, which can be used to print the chart or export it as PDF.
22
+ * @param {ChartPrintExportOptions} options Options to customize the print export.
23
+ * @returns {void}
24
+ */
25
+ exportAsPrint: (options?: ChartPrintExportOptions) => void;
26
+ }
27
+ export interface UseChartProExportInstance extends UseChartProExportPublicApi {}
28
+ export type UseChartProExportSignature = ChartPluginSignature<{
29
+ params: UseChartProExportParameters;
30
+ defaultizedParams: UseChartProExportDefaultizedParameters;
31
+ state: UseChartProExportState;
32
+ publicAPI: UseChartProExportPublicApi;
33
+ instance: UseChartProExportInstance;
34
+ dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
35
+ }>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -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>;