@mui/x-charts-pro 8.5.3 → 8.7.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 (124) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/ChartContainerPro/index.d.ts +7 -1
  3. package/ChartContainerPro/index.js +0 -11
  4. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  5. package/ChartZoomSlider/index.d.ts +2 -1
  6. package/ChartZoomSlider/index.js +10 -2
  7. package/ChartZoomSlider/internals/ChartAxisZoomSlider.js +4 -0
  8. package/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +7 -1
  9. package/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +9 -1
  10. package/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.d.ts +15 -0
  11. package/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.js +31 -0
  12. package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.d.ts +27 -0
  13. package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +77 -0
  14. package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.d.ts +33 -0
  15. package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.js +75 -0
  16. package/ChartsToolbarPro/ChartsToolbarPro.d.ts +16 -3
  17. package/ChartsToolbarPro/ChartsToolbarPro.js +118 -8
  18. package/ChartsToolbarPro/index.d.ts +3 -1
  19. package/ChartsToolbarPro/index.js +22 -0
  20. package/ChartsToolbarPro/internals/ChartsMenu.d.ts +14 -0
  21. package/ChartsToolbarPro/internals/ChartsMenu.js +73 -0
  22. package/ChartsToolbarPro/internals/ChartsToolbarDivider.d.ts +5 -0
  23. package/ChartsToolbarPro/internals/ChartsToolbarDivider.js +47 -0
  24. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.js +43 -33
  25. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +3 -3
  26. package/{ChartContainerPro → context}/ChartProApi.d.ts +2 -3
  27. package/context/index.d.ts +2 -1
  28. package/context/index.js +4 -4
  29. package/context/useChartProApiContext.d.ts +9 -0
  30. package/context/{useChartApiContext.js → useChartProApiContext.js} +4 -4
  31. package/esm/ChartContainerPro/index.d.ts +7 -1
  32. package/esm/ChartContainerPro/index.js +4 -1
  33. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  34. package/esm/ChartZoomSlider/index.d.ts +2 -1
  35. package/esm/ChartZoomSlider/index.js +2 -1
  36. package/esm/ChartZoomSlider/internals/ChartAxisZoomSlider.js +4 -0
  37. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +8 -1
  38. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +10 -1
  39. package/esm/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.d.ts +15 -0
  40. package/esm/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.js +21 -0
  41. package/esm/ChartsToolbarPro/ChartsToolbarImageExportTrigger.d.ts +27 -0
  42. package/esm/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +70 -0
  43. package/esm/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.d.ts +33 -0
  44. package/esm/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.js +68 -0
  45. package/esm/ChartsToolbarPro/ChartsToolbarPro.d.ts +16 -3
  46. package/esm/ChartsToolbarPro/ChartsToolbarPro.js +120 -8
  47. package/esm/ChartsToolbarPro/index.d.ts +3 -1
  48. package/esm/ChartsToolbarPro/index.js +3 -1
  49. package/esm/ChartsToolbarPro/internals/ChartsMenu.d.ts +14 -0
  50. package/esm/ChartsToolbarPro/internals/ChartsMenu.js +67 -0
  51. package/esm/ChartsToolbarPro/internals/ChartsToolbarDivider.d.ts +5 -0
  52. package/esm/ChartsToolbarPro/internals/ChartsToolbarDivider.js +40 -0
  53. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.js +43 -33
  54. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +3 -3
  55. package/esm/{ChartContainerPro → context}/ChartProApi.d.ts +2 -3
  56. package/esm/context/index.d.ts +2 -1
  57. package/esm/context/index.js +2 -1
  58. package/esm/context/useChartProApiContext.d.ts +9 -0
  59. package/esm/context/{useChartApiContext.js → useChartProApiContext.js} +3 -3
  60. package/esm/hooks/index.d.ts +2 -1
  61. package/esm/hooks/index.js +2 -1
  62. package/esm/hooks/useChartProApiRef.d.ts +23 -0
  63. package/esm/hooks/useChartProApiRef.js +20 -0
  64. package/esm/index.d.ts +6 -3
  65. package/esm/index.js +3 -3
  66. package/esm/internals/material/components/BaseMenuItem.d.ts +3 -0
  67. package/esm/internals/material/components/BaseMenuItem.js +27 -0
  68. package/esm/internals/material/components/BasePopper.d.ts +3 -0
  69. package/esm/internals/material/components/BasePopper.js +122 -0
  70. package/esm/internals/material/icons.d.ts +2 -1
  71. package/esm/internals/material/icons.js +4 -1
  72. package/esm/internals/material/index.d.ts +1 -0
  73. package/esm/internals/material/index.js +12 -3
  74. package/esm/internals/plugins/allPlugins.d.ts +2 -2
  75. package/esm/internals/plugins/useChartProExport/print.js +1 -1
  76. package/esm/internals/plugins/useChartProExport/useChartProExport.types.d.ts +7 -6
  77. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.ts +8 -0
  78. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +58 -0
  79. package/esm/internals/plugins/useChartProZoom/{useChartProZoom.utils.d.ts → gestureHooks/useZoom.utils.d.ts} +14 -10
  80. package/esm/internals/plugins/useChartProZoom/{useChartProZoom.utils.js → gestureHooks/useZoom.utils.js} +41 -31
  81. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.ts +8 -0
  82. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +59 -0
  83. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.ts +8 -0
  84. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +79 -0
  85. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +15 -227
  86. package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +4 -4
  87. package/esm/internals/slots/chartBaseSlotProps.d.ts +50 -3
  88. package/esm/internals/slots/chartsBaseSlots.d.ts +5 -1
  89. package/esm/internals/slots/chartsIconSlots.d.ts +5 -0
  90. package/hooks/index.d.ts +2 -1
  91. package/hooks/index.js +11 -0
  92. package/hooks/useChartProApiRef.d.ts +23 -0
  93. package/hooks/useChartProApiRef.js +28 -0
  94. package/index.d.ts +6 -3
  95. package/index.js +58 -22
  96. package/internals/material/components/BaseMenuItem.d.ts +3 -0
  97. package/internals/material/components/BaseMenuItem.js +35 -0
  98. package/internals/material/components/BasePopper.d.ts +3 -0
  99. package/internals/material/components/BasePopper.js +130 -0
  100. package/internals/material/icons.d.ts +2 -1
  101. package/internals/material/icons.js +5 -2
  102. package/internals/material/index.d.ts +1 -0
  103. package/internals/material/index.js +11 -2
  104. package/internals/plugins/allPlugins.d.ts +2 -2
  105. package/internals/plugins/useChartProExport/print.js +1 -1
  106. package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +7 -6
  107. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.ts +8 -0
  108. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +65 -0
  109. package/internals/plugins/useChartProZoom/{useChartProZoom.utils.d.ts → gestureHooks/useZoom.utils.d.ts} +14 -10
  110. package/internals/plugins/useChartProZoom/{useChartProZoom.utils.js → gestureHooks/useZoom.utils.js} +43 -34
  111. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.ts +8 -0
  112. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +66 -0
  113. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.ts +8 -0
  114. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +86 -0
  115. package/internals/plugins/useChartProZoom/useChartProZoom.js +14 -226
  116. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +4 -4
  117. package/internals/slots/chartBaseSlotProps.d.ts +50 -3
  118. package/internals/slots/chartsBaseSlots.d.ts +5 -1
  119. package/internals/slots/chartsIconSlots.d.ts +5 -0
  120. package/package.json +5 -4
  121. package/context/useChartApiContext.d.ts +0 -9
  122. package/esm/context/useChartApiContext.d.ts +0 -9
  123. /package/{ChartContainerPro → context}/ChartProApi.js +0 -0
  124. /package/esm/{ChartContainerPro → context}/ChartProApi.js +0 -0
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.BasePopper = BasePopper;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
+ var React = _interopRequireWildcard(require("react"));
12
+ var _Popper = _interopRequireDefault(require("@mui/material/Popper"));
13
+ var _Unstable_TrapFocus = _interopRequireDefault(require("@mui/material/Unstable_TrapFocus"));
14
+ var _ClickAwayListener = _interopRequireDefault(require("@mui/material/ClickAwayListener"));
15
+ var _Grow = _interopRequireDefault(require("@mui/material/Grow"));
16
+ var _Paper = _interopRequireDefault(require("@mui/material/Paper"));
17
+ var _jsxRuntime = require("react/jsx-runtime");
18
+ const _excluded = ["ref", "open", "children", "className", "clickAwayTouchEvent", "clickAwayMouseEvent", "flip", "focusTrap", "onExited", "onClickAway", "onDidShow", "onDidHide", "id", "target", "transition", "placement"];
19
+ function clickAwayWrapper(props, content) {
20
+ if (props.onClickAway === undefined) {
21
+ return content;
22
+ }
23
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ClickAwayListener.default, {
24
+ onClickAway: props.onClickAway,
25
+ touchEvent: props.clickAwayTouchEvent,
26
+ mouseEvent: props.clickAwayMouseEvent,
27
+ children: content
28
+ });
29
+ }
30
+ function focusTrapWrapper(props, content) {
31
+ if (props.focusTrap === undefined) {
32
+ return content;
33
+ }
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_TrapFocus.default, {
35
+ open: true,
36
+ disableEnforceFocus: true,
37
+ disableAutoFocus: true,
38
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
39
+ tabIndex: -1,
40
+ children: content
41
+ })
42
+ });
43
+ }
44
+ function wrappers(props, content) {
45
+ return focusTrapWrapper(props, clickAwayWrapper(props, content));
46
+ }
47
+ const transformOrigin = {
48
+ 'bottom-start': 'top left',
49
+ 'bottom-end': 'top right'
50
+ };
51
+ function BasePopper(props) {
52
+ const {
53
+ open,
54
+ children,
55
+ className,
56
+ flip,
57
+ onExited,
58
+ onDidShow,
59
+ onDidHide,
60
+ id,
61
+ target,
62
+ transition,
63
+ placement
64
+ } = props,
65
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
66
+ const modifiers = React.useMemo(() => {
67
+ const result = [{
68
+ name: 'preventOverflow',
69
+ options: {
70
+ padding: 8
71
+ }
72
+ }];
73
+ if (flip) {
74
+ result.push({
75
+ name: 'flip',
76
+ enabled: true,
77
+ options: {
78
+ rootBoundary: 'document'
79
+ }
80
+ });
81
+ }
82
+ if (onDidShow || onDidHide) {
83
+ result.push({
84
+ name: 'isPlaced',
85
+ enabled: true,
86
+ phase: 'main',
87
+ fn: () => {
88
+ onDidShow?.();
89
+ },
90
+ effect: () => () => {
91
+ onDidHide?.();
92
+ }
93
+ });
94
+ }
95
+ return result;
96
+ }, [flip, onDidShow, onDidHide]);
97
+ let content;
98
+ if (!transition) {
99
+ content = wrappers(props, children);
100
+ } else {
101
+ const handleExited = popperOnExited => node => {
102
+ if (popperOnExited) {
103
+ popperOnExited();
104
+ }
105
+ if (onExited) {
106
+ onExited(node);
107
+ }
108
+ };
109
+ content = p => wrappers(props, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grow.default, (0, _extends2.default)({}, p.TransitionProps, {
110
+ style: {
111
+ transformOrigin: transformOrigin[p.placement]
112
+ },
113
+ onExited: handleExited(p.TransitionProps?.onExited),
114
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Paper.default, {
115
+ children: children
116
+ })
117
+ })));
118
+ }
119
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popper.default, (0, _extends2.default)({
120
+ id: id,
121
+ className: className,
122
+ open: open,
123
+ anchorEl: target,
124
+ transition: transition,
125
+ placement: placement,
126
+ modifiers: modifiers
127
+ }, rest, {
128
+ children: content
129
+ }));
130
+ }
@@ -1,3 +1,4 @@
1
1
  import * as React from 'react';
2
2
  export declare const ChartsZoomInIcon: (props: import("@mui/x-charts").ChartBaseIconProps) => React.ReactNode;
3
- export declare const ChartsZoomOutIcon: (props: import("@mui/x-charts").ChartBaseIconProps) => React.ReactNode;
3
+ export declare const ChartsZoomOutIcon: (props: import("@mui/x-charts").ChartBaseIconProps) => React.ReactNode;
4
+ export declare const ChartsExportIcon: (props: import("@mui/x-charts").ChartBaseIconProps) => React.ReactNode;
@@ -4,7 +4,7 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.ChartsZoomOutIcon = exports.ChartsZoomInIcon = void 0;
7
+ exports.ChartsZoomOutIcon = exports.ChartsZoomInIcon = exports.ChartsExportIcon = void 0;
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
  var _internals = require("@mui/x-charts/internals");
10
10
  var _jsxRuntime = require("react/jsx-runtime");
@@ -17,4 +17,7 @@ const ChartsZoomInIcon = exports.ChartsZoomInIcon = (0, _internals.createSvgIcon
17
17
  }), 'ZoomIn');
18
18
  const ChartsZoomOutIcon = exports.ChartsZoomOutIcon = (0, _internals.createSvgIcon)(/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
19
19
  d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14M7 9h5v1H7z"
20
- }), 'ZoomOut');
20
+ }), 'ZoomOut');
21
+ const ChartsExportIcon = exports.ChartsExportIcon = (0, _internals.createSvgIcon)(/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
22
+ d: "M19 9h-4V3H9v6H5l7 7zM5 18v2h14v-2z"
23
+ }), 'Export');
@@ -1,3 +1,4 @@
1
+ import * as React from 'react';
1
2
  import { ChartsBaseSlotsPro } from "../slots/chartsBaseSlots.js";
2
3
  import { ChartsIconSlotsPro } from "../slots/chartsIconSlots.js";
3
4
  export type ChartsSlotsPro = ChartsBaseSlotsPro & ChartsIconSlotsPro;
@@ -7,13 +7,22 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.defaultSlotsMaterial = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
10
+ var _MenuList = _interopRequireDefault(require("@mui/material/MenuList"));
11
+ var _Divider = _interopRequireDefault(require("@mui/material/Divider"));
10
12
  var _internals = require("@mui/x-charts/internals");
13
+ var _BaseMenuItem = require("./components/BaseMenuItem");
14
+ var _BasePopper = require("./components/BasePopper");
11
15
  var _icons = require("./icons");
12
16
  const baseSlots = {
13
- baseTooltip: _Tooltip.default
17
+ baseTooltip: _Tooltip.default,
18
+ basePopper: _BasePopper.BasePopper,
19
+ baseMenuList: _MenuList.default,
20
+ baseMenuItem: _BaseMenuItem.BaseMenuItem,
21
+ baseDivider: _Divider.default
14
22
  };
15
23
  const iconSlots = {
16
24
  zoomInIcon: _icons.ChartsZoomInIcon,
17
- zoomOutIcon: _icons.ChartsZoomOutIcon
25
+ zoomOutIcon: _icons.ChartsZoomOutIcon,
26
+ exportIcon: _icons.ChartsExportIcon
18
27
  };
19
28
  const defaultSlotsMaterial = exports.defaultSlotsMaterial = (0, _extends2.default)({}, _internals.defaultSlotsMaterial, baseSlots, iconSlots);
@@ -3,7 +3,7 @@ import { UseChartProExportSignature } from "./useChartProExport/index.js";
3
3
  import { UseChartProZoomSignature } from "./useChartProZoom/index.js";
4
4
  export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature, UseChartProExportSignature];
5
5
  export type AllPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<AllPluginSignatures<TSeries>>;
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>>)[];
6
+ export declare const ALL_PLUGINS: (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<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartPolarAxisSignature<any>>)[];
7
7
  export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature, UseChartProExportSignature];
8
8
  export type DefaultPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<DefaultPluginSignatures<TSeries>>;
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>>)[];
9
+ export declare const DEFAULT_PLUGINS: (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<UseChartProZoomSignature>)[];
@@ -22,7 +22,6 @@ function printChart(element, {
22
22
  const rootCandidate = element.getRootNode();
23
23
  const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
24
24
  await Promise.all((0, _export.loadStyleSheets)(printDoc, root));
25
- printWindow.contentWindow.print();
26
25
  const mediaQueryList = printWindow.contentWindow.matchMedia('print');
27
26
  mediaQueryList.addEventListener('change', mql => {
28
27
  const isAfterPrint = mql.matches === false;
@@ -30,6 +29,7 @@ function printChart(element, {
30
29
  doc.body.removeChild(printWindow);
31
30
  }
32
31
  });
32
+ printWindow.contentWindow.print();
33
33
  };
34
34
  doc.body.appendChild(printWindow);
35
35
  }
@@ -7,29 +7,30 @@ export interface UseChartProExportState {
7
7
  /**
8
8
  * The options to apply on the Print export.
9
9
  * @demos
10
- * - [Print export](/x/react-charts/export/#print-export-as-pdf)
10
+ * - [Print export](https://mui.com/x/react-charts/export/#print-export-as-pdf)
11
11
  */
12
12
  export interface ChartPrintExportOptions {
13
13
  /**
14
- * The value to be used as the print window title.
15
- * @default The title of the page.
14
+ * The name of the file without the extension.
15
+ * @default The title of the document the chart belongs to
16
16
  */
17
17
  fileName?: string;
18
18
  }
19
19
  /**
20
20
  * The options to apply on the image export.
21
21
  * @demos
22
- * - [Image export](/x/react-charts/export/#export-as-image)
22
+ * - [Image export](https://mui.com/x/react-charts/export/#export-as-image)
23
23
  */
24
24
  export interface ChartImageExportOptions {
25
25
  /**
26
- * The value to be used as the print window title.
27
- * @default The title of the page.
26
+ * The name of the file without the extension.
27
+ * @default The title of the document the chart belongs to
28
28
  */
29
29
  fileName?: string;
30
30
  /**
31
31
  * The format of the image to be exported.
32
32
  * Browsers are required to support 'image/png'. Some browsers also support 'image/jpeg' and 'image/webp'.
33
+ * If the provided `type` is not supported by the browser, it will default to 'image/png'.
33
34
  * @default 'image/png'
34
35
  */
35
36
  type?: 'image/png' | string;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ChartPlugin, ZoomData } from '@mui/x-charts/internals';
3
+ import { UseChartProZoomSignature } from "../useChartProZoom.types.js";
4
+ export declare const usePanOnDrag: ({
5
+ store,
6
+ instance,
7
+ svgRef
8
+ }: Pick<Parameters<ChartPlugin<UseChartProZoomSignature>>[0], "store" | "instance" | "svgRef">, setZoomDataCallback: React.Dispatch<ZoomData[] | ((prev: ZoomData[]) => ZoomData[])>) => void;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.usePanOnDrag = void 0;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _internals = require("@mui/x-charts/internals");
11
+ var _rafThrottle = require("@mui/x-internals/rafThrottle");
12
+ var _useZoom = require("./useZoom.utils");
13
+ const usePanOnDrag = ({
14
+ store,
15
+ instance,
16
+ svgRef
17
+ }, setZoomDataCallback) => {
18
+ const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
19
+ const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
20
+ const startRef = React.useRef(null);
21
+
22
+ // Add event for chart panning
23
+ const isPanEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) || false, [optionsLookup]);
24
+ React.useEffect(() => {
25
+ const element = svgRef.current;
26
+ if (element === null || !isPanEnabled) {
27
+ return () => {};
28
+ }
29
+ const handlePanStart = event => {
30
+ if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
31
+ startRef.current = store.value.zoom.zoomData;
32
+ }
33
+ };
34
+ const handlePanEnd = () => {
35
+ startRef.current = null;
36
+ };
37
+ const throttledCallback = (0, _rafThrottle.rafThrottle)((event, zoomData) => {
38
+ const newZoomData = (0, _useZoom.translateZoom)(zoomData, {
39
+ x: event.detail.activeDeltaX,
40
+ y: -event.detail.activeDeltaY
41
+ }, {
42
+ width: drawingArea.width,
43
+ height: drawingArea.height
44
+ }, optionsLookup);
45
+ setZoomDataCallback(newZoomData);
46
+ });
47
+ const handlePan = event => {
48
+ const zoomData = startRef.current;
49
+ if (!zoomData) {
50
+ return;
51
+ }
52
+ throttledCallback(event, zoomData);
53
+ };
54
+ const panHandler = instance.addInteractionListener('pan', handlePan);
55
+ const panStartHandler = instance.addInteractionListener('panStart', handlePanStart);
56
+ const panEndHandler = instance.addInteractionListener('panEnd', handlePanEnd);
57
+ return () => {
58
+ panStartHandler.cleanup();
59
+ panHandler.cleanup();
60
+ panEndHandler.cleanup();
61
+ throttledCallback.clear();
62
+ };
63
+ }, [instance, svgRef, isPanEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, startRef]);
64
+ };
65
+ exports.usePanOnDrag = usePanOnDrag;
@@ -17,14 +17,6 @@ export declare function getWheelScaleRatio(event: WheelEvent, step: number): {
17
17
  scaleRatio: number;
18
18
  isZoomIn: boolean;
19
19
  };
20
- /**
21
- * Get the scale ratio and if it's a zoom in or out from a pinch gesture.
22
- */
23
- export declare function getPinchScaleRatio(curDiff: number, prevDiff: number, step: number): {
24
- scaleRatio: number;
25
- isZoomIn: boolean;
26
- };
27
- export declare function getDiff(eventCache: PointerEvent[]): number;
28
20
  /**
29
21
  * Get the ratio of the point in the horizontal center of the area.
30
22
  */
@@ -35,11 +27,23 @@ export declare function getHorizontalCenterRatio(point: {
35
27
  left: number;
36
28
  width: number;
37
29
  }): number;
38
- export declare function preventDefault(event: TouchEvent): void;
30
+ /**
31
+ * Get the ratio of the point in the vertical center of the area.
32
+ */
39
33
  export declare function getVerticalCenterRatio(point: {
40
34
  x: number;
41
35
  y: number;
42
36
  }, area: {
43
37
  top: number;
44
38
  height: number;
45
- }): number;
39
+ }): number;
40
+ /**
41
+ * Translate the zoom data by a given movement.
42
+ */
43
+ export declare function translateZoom(initialZoomData: readonly ZoomData[], movement: {
44
+ x: number;
45
+ y: number;
46
+ }, drawingArea: {
47
+ width: number;
48
+ height: number;
49
+ }, optionsLookup: Record<string | number, DefaultizedZoomOptions>): ZoomData[];
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.getDiff = getDiff;
7
7
  exports.getHorizontalCenterRatio = getHorizontalCenterRatio;
8
- exports.getPinchScaleRatio = getPinchScaleRatio;
9
8
  exports.getVerticalCenterRatio = getVerticalCenterRatio;
10
9
  exports.getWheelScaleRatio = getWheelScaleRatio;
11
10
  exports.isSpanValid = isSpanValid;
12
- exports.preventDefault = preventDefault;
11
+ exports.translateZoom = translateZoom;
13
12
  exports.zoomAtPoint = void 0;
13
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
14
14
  /**
15
15
  * Helper to get the range (in percents of a reference range) corresponding to a given scale.
16
16
  * @param centerRatio {number} The ratio of the point that should not move between the previous and next range.
@@ -90,34 +90,6 @@ function getWheelScaleRatio(event, step) {
90
90
  };
91
91
  }
92
92
 
93
- /**
94
- * Get the scale ratio and if it's a zoom in or out from a pinch gesture.
95
- */
96
- function getPinchScaleRatio(curDiff, prevDiff, step) {
97
- const scaledStep = step / 1000;
98
- let scaleRatio = 0;
99
- let isZoomIn = false;
100
- const hasMoved = prevDiff > 0;
101
- if (hasMoved && curDiff > prevDiff) {
102
- // The distance between the two pointers has increased
103
- scaleRatio = 1 + scaledStep;
104
- isZoomIn = true;
105
- }
106
- if (hasMoved && curDiff < prevDiff) {
107
- // The distance between the two pointers has decreased
108
- scaleRatio = 1 - scaledStep;
109
- isZoomIn = false;
110
- }
111
- return {
112
- scaleRatio,
113
- isZoomIn
114
- };
115
- }
116
- function getDiff(eventCache) {
117
- const [firstEvent, secondEvent] = eventCache;
118
- return Math.hypot(firstEvent.pageX - secondEvent.pageX, firstEvent.pageY - secondEvent.pageY);
119
- }
120
-
121
93
  /**
122
94
  * Get the ratio of the point in the horizontal center of the area.
123
95
  */
@@ -128,13 +100,50 @@ function getHorizontalCenterRatio(point, area) {
128
100
  } = area;
129
101
  return (point.x - left) / width;
130
102
  }
131
- function preventDefault(event) {
132
- event.preventDefault();
133
- }
103
+
104
+ /**
105
+ * Get the ratio of the point in the vertical center of the area.
106
+ */
134
107
  function getVerticalCenterRatio(point, area) {
135
108
  const {
136
109
  top,
137
110
  height
138
111
  } = area;
139
112
  return (point.y - top) / height * -1 + 1;
113
+ }
114
+
115
+ /**
116
+ * Translate the zoom data by a given movement.
117
+ */
118
+ function translateZoom(initialZoomData, movement, drawingArea, optionsLookup) {
119
+ return initialZoomData.map(zoom => {
120
+ const options = optionsLookup[zoom.axisId];
121
+ if (!options || !options.panning) {
122
+ return zoom;
123
+ }
124
+ const min = zoom.start;
125
+ const max = zoom.end;
126
+ const span = max - min;
127
+ const MIN_PERCENT = options.minStart;
128
+ const MAX_PERCENT = options.maxEnd;
129
+ const displacement = options.axisDirection === 'x' ? movement.x : movement.y;
130
+ const dimension = options.axisDirection === 'x' ? drawingArea.width : drawingArea.height;
131
+ let newMinPercent = min - displacement / dimension * span;
132
+ let newMaxPercent = max - displacement / dimension * span;
133
+ if (newMinPercent < MIN_PERCENT) {
134
+ newMinPercent = MIN_PERCENT;
135
+ newMaxPercent = newMinPercent + span;
136
+ }
137
+ if (newMaxPercent > MAX_PERCENT) {
138
+ newMaxPercent = MAX_PERCENT;
139
+ newMinPercent = newMaxPercent - span;
140
+ }
141
+ if (newMinPercent < MIN_PERCENT || newMaxPercent > MAX_PERCENT || span < options.minSpan || span > options.maxSpan) {
142
+ return zoom;
143
+ }
144
+ return (0, _extends2.default)({}, zoom, {
145
+ start: newMinPercent,
146
+ end: newMaxPercent
147
+ });
148
+ });
140
149
  }
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ChartPlugin, ZoomData } from '@mui/x-charts/internals';
3
+ import { UseChartProZoomSignature } from "../useChartProZoom.types.js";
4
+ export declare const useZoomOnPinch: ({
5
+ store,
6
+ instance,
7
+ svgRef
8
+ }: Pick<Parameters<ChartPlugin<UseChartProZoomSignature>>[0], "store" | "instance" | "svgRef">, setZoomDataCallback: React.Dispatch<ZoomData[] | ((prev: ZoomData[]) => ZoomData[])>) => void;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useZoomOnPinch = void 0;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _internals = require("@mui/x-charts/internals");
11
+ var _rafThrottle = require("@mui/x-internals/rafThrottle");
12
+ var _useZoom = require("./useZoom.utils");
13
+ const useZoomOnPinch = ({
14
+ store,
15
+ instance,
16
+ svgRef
17
+ }, setZoomDataCallback) => {
18
+ const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
19
+ const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
20
+ const isZoomEnabled = Object.keys(optionsLookup).length > 0;
21
+
22
+ // Zoom on pinch
23
+ React.useEffect(() => {
24
+ const element = svgRef.current;
25
+ if (element === null || !isZoomEnabled) {
26
+ return () => {};
27
+ }
28
+ const rafThrottledCallback = (0, _rafThrottle.rafThrottle)(event => {
29
+ setZoomDataCallback(prev => {
30
+ return prev.map(zoom => {
31
+ const option = optionsLookup[zoom.axisId];
32
+ if (!option) {
33
+ return zoom;
34
+ }
35
+ const isZoomIn = event.detail.direction > 0;
36
+ const scaleRatio = 1 + event.detail.deltaScale;
37
+
38
+ // If the delta is 0, it means the pinch gesture is not valid.
39
+ if (event.detail.direction === 0) {
40
+ return zoom;
41
+ }
42
+ const point = (0, _internals.getSVGPoint)(element, {
43
+ clientX: event.detail.centroid.x,
44
+ clientY: event.detail.centroid.y
45
+ });
46
+ const centerRatio = option.axisDirection === 'x' ? (0, _useZoom.getHorizontalCenterRatio)(point, drawingArea) : (0, _useZoom.getVerticalCenterRatio)(point, drawingArea);
47
+ const [newMinRange, newMaxRange] = (0, _useZoom.zoomAtPoint)(centerRatio, scaleRatio, zoom, option);
48
+ if (!(0, _useZoom.isSpanValid)(newMinRange, newMaxRange, isZoomIn, option)) {
49
+ return zoom;
50
+ }
51
+ return {
52
+ axisId: zoom.axisId,
53
+ start: newMinRange,
54
+ end: newMaxRange
55
+ };
56
+ });
57
+ });
58
+ });
59
+ const zoomHandler = instance.addInteractionListener('pinch', rafThrottledCallback);
60
+ return () => {
61
+ zoomHandler.cleanup();
62
+ rafThrottledCallback.clear();
63
+ };
64
+ }, [svgRef, drawingArea, isZoomEnabled, optionsLookup, store, instance, setZoomDataCallback]);
65
+ };
66
+ exports.useZoomOnPinch = useZoomOnPinch;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ChartPlugin, ZoomData } from '@mui/x-charts/internals';
3
+ import { UseChartProZoomSignature } from "../useChartProZoom.types.js";
4
+ export declare const useZoomOnWheel: ({
5
+ store,
6
+ instance,
7
+ svgRef
8
+ }: Pick<Parameters<ChartPlugin<UseChartProZoomSignature>>[0], "store" | "instance" | "svgRef">, setZoomDataCallback: React.Dispatch<ZoomData[] | ((prev: ZoomData[]) => ZoomData[])>) => void;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useZoomOnWheel = void 0;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _internals = require("@mui/x-charts/internals");
11
+ var _rafThrottle = require("@mui/x-internals/rafThrottle");
12
+ var _useZoom = require("./useZoom.utils");
13
+ const useZoomOnWheel = ({
14
+ store,
15
+ instance,
16
+ svgRef
17
+ }, setZoomDataCallback) => {
18
+ const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
19
+ const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
20
+ const isZoomEnabled = Object.keys(optionsLookup).length > 0;
21
+ const startedOutsideRef = React.useRef(false);
22
+ const startedOutsideTimeoutRef = React.useRef(null);
23
+
24
+ // Add event for chart zoom in/out
25
+ React.useEffect(() => {
26
+ const element = svgRef.current;
27
+ if (element === null || !isZoomEnabled) {
28
+ return () => {};
29
+ }
30
+ const rafThrottledSetZoomData = (0, _rafThrottle.rafThrottle)(setZoomDataCallback);
31
+ const zoomOnWheelHandler = instance.addInteractionListener('turnWheel', event => {
32
+ const point = (0, _internals.getSVGPoint)(element, {
33
+ clientX: event.detail.centroid.x,
34
+ clientY: event.detail.centroid.y
35
+ });
36
+
37
+ // This prevents a zoom event from being triggered when the mouse is outside the chart area.
38
+ // The timeout is used to prevent an weird behavior where if the mouse is outside but enters due to
39
+ // scrolling, then the zoom event is triggered.
40
+ if (startedOutsideRef.current || !instance.isPointInside(point.x, point.y)) {
41
+ startedOutsideRef.current = true;
42
+ if (startedOutsideTimeoutRef.current) {
43
+ clearTimeout(startedOutsideTimeoutRef.current);
44
+ }
45
+ startedOutsideTimeoutRef.current = setTimeout(() => {
46
+ startedOutsideRef.current = false;
47
+ startedOutsideTimeoutRef.current = null;
48
+ }, 100);
49
+ return;
50
+ }
51
+ event.detail.srcEvent.preventDefault();
52
+ rafThrottledSetZoomData(prev => {
53
+ return prev.map(zoom => {
54
+ const option = optionsLookup[zoom.axisId];
55
+ if (!option) {
56
+ return zoom;
57
+ }
58
+ const centerRatio = option.axisDirection === 'x' ? (0, _useZoom.getHorizontalCenterRatio)(point, drawingArea) : (0, _useZoom.getVerticalCenterRatio)(point, drawingArea);
59
+ const {
60
+ scaleRatio,
61
+ isZoomIn
62
+ } = (0, _useZoom.getWheelScaleRatio)(event.detail.srcEvent, option.step);
63
+ const [newMinRange, newMaxRange] = (0, _useZoom.zoomAtPoint)(centerRatio, scaleRatio, zoom, option);
64
+ if (!(0, _useZoom.isSpanValid)(newMinRange, newMaxRange, isZoomIn, option)) {
65
+ return zoom;
66
+ }
67
+ return {
68
+ axisId: zoom.axisId,
69
+ start: newMinRange,
70
+ end: newMaxRange
71
+ };
72
+ });
73
+ });
74
+ });
75
+ return () => {
76
+ zoomOnWheelHandler.cleanup();
77
+ if (startedOutsideTimeoutRef.current) {
78
+ clearTimeout(startedOutsideTimeoutRef.current);
79
+ startedOutsideTimeoutRef.current = null;
80
+ }
81
+ startedOutsideRef.current = false;
82
+ rafThrottledSetZoomData.clear();
83
+ };
84
+ }, [svgRef, drawingArea, isZoomEnabled, optionsLookup, instance, setZoomDataCallback, store]);
85
+ };
86
+ exports.useZoomOnWheel = useZoomOnWheel;