@mui/x-charts-pro 8.0.0-alpha.7 → 8.0.0-alpha.9

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 (169) hide show
  1. package/BarChartPro/BarChartPro.d.ts +2 -2
  2. package/BarChartPro/BarChartPro.js +55 -20
  3. package/CHANGELOG.md +551 -3
  4. package/ChartContainerPro/ChartContainerPro.d.ts +33 -4
  5. package/ChartContainerPro/ChartContainerPro.js +52 -27
  6. package/ChartContainerPro/useChartContainerProProps.d.ts +6 -5
  7. package/ChartContainerPro/useChartContainerProProps.js +11 -5
  8. package/ChartDataProviderPro/ChartDataProviderPro.d.ts +37 -0
  9. package/ChartDataProviderPro/ChartDataProviderPro.js +292 -0
  10. package/{context → ChartDataProviderPro}/package.json +1 -1
  11. package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +8 -0
  12. package/ChartDataProviderPro/useChartDataProviderProProps.js +17 -0
  13. package/Heatmap/Heatmap.js +28 -2
  14. package/Heatmap/HeatmapTooltip.js +6 -4
  15. package/Heatmap/extremums.d.ts +2 -2
  16. package/Heatmap/formatter.d.ts +2 -2
  17. package/Heatmap/formatter.js +2 -1
  18. package/Heatmap/plugin.d.ts +2 -2
  19. package/Heatmap/plugin.js +2 -2
  20. package/LineChartPro/LineChartPro.d.ts +2 -2
  21. package/LineChartPro/LineChartPro.js +58 -37
  22. package/ScatterChartPro/ScatterChartPro.d.ts +2 -2
  23. package/ScatterChartPro/ScatterChartPro.js +36 -28
  24. package/hooks/index.d.ts +1 -0
  25. package/hooks/index.js +2 -1
  26. package/hooks/zoom/index.d.ts +1 -0
  27. package/hooks/zoom/index.js +1 -0
  28. package/hooks/zoom/useIsZoomInteracting.d.ts +6 -0
  29. package/hooks/zoom/useIsZoomInteracting.js +14 -0
  30. package/index.d.ts +3 -1
  31. package/index.js +5 -5
  32. package/internals/plugins/allPlugins.d.ts +10 -0
  33. package/internals/plugins/allPlugins.js +5 -0
  34. package/internals/plugins/useChartProZoom/creatZoomLookup.d.ts +3 -0
  35. package/internals/plugins/useChartProZoom/creatZoomLookup.js +12 -0
  36. package/internals/plugins/useChartProZoom/defaultizeZoom.d.ts +2 -0
  37. package/internals/plugins/useChartProZoom/defaultizeZoom.js +25 -0
  38. package/internals/plugins/useChartProZoom/index.d.ts +3 -0
  39. package/internals/plugins/useChartProZoom/index.js +3 -0
  40. package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +3 -0
  41. package/internals/plugins/useChartProZoom/useChartProZoom.js +303 -0
  42. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +377 -0
  43. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +10 -0
  44. package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +50 -0
  45. package/internals/plugins/useChartProZoom/useChartProZoom.utils.d.ts +45 -0
  46. package/internals/plugins/useChartProZoom/useChartProZoom.utils.js +126 -0
  47. package/internals/plugins/useChartProZoom/zoom.types.d.ts +53 -0
  48. package/internals/utils/releaseInfo.js +1 -1
  49. package/models/index.d.ts +1 -0
  50. package/models/index.js +2 -1
  51. package/modern/BarChartPro/BarChartPro.js +55 -20
  52. package/modern/ChartContainerPro/ChartContainerPro.js +52 -27
  53. package/modern/ChartContainerPro/useChartContainerProProps.js +11 -5
  54. package/modern/ChartDataProviderPro/ChartDataProviderPro.js +292 -0
  55. package/modern/ChartDataProviderPro/useChartDataProviderProProps.js +17 -0
  56. package/modern/Heatmap/Heatmap.js +28 -2
  57. package/modern/Heatmap/HeatmapTooltip.js +6 -4
  58. package/modern/Heatmap/formatter.js +2 -1
  59. package/modern/Heatmap/plugin.js +2 -2
  60. package/modern/LineChartPro/LineChartPro.js +58 -37
  61. package/modern/ScatterChartPro/ScatterChartPro.js +36 -28
  62. package/modern/hooks/index.js +2 -1
  63. package/modern/hooks/zoom/index.js +1 -0
  64. package/modern/hooks/zoom/useIsZoomInteracting.js +14 -0
  65. package/modern/index.js +5 -5
  66. package/modern/internals/plugins/allPlugins.js +5 -0
  67. package/modern/internals/plugins/useChartProZoom/creatZoomLookup.js +12 -0
  68. package/modern/internals/plugins/useChartProZoom/defaultizeZoom.js +25 -0
  69. package/modern/internals/plugins/useChartProZoom/index.js +3 -0
  70. package/modern/internals/plugins/useChartProZoom/useChartProZoom.js +303 -0
  71. package/modern/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +10 -0
  72. package/modern/internals/plugins/useChartProZoom/useChartProZoom.types.js +1 -0
  73. package/modern/internals/plugins/useChartProZoom/useChartProZoom.utils.js +126 -0
  74. package/modern/internals/plugins/useChartProZoom/zoom.types.js +1 -0
  75. package/modern/internals/utils/releaseInfo.js +1 -1
  76. package/modern/models/index.js +2 -1
  77. package/node/BarChartPro/BarChartPro.js +55 -20
  78. package/node/ChartContainerPro/ChartContainerPro.js +51 -26
  79. package/node/ChartContainerPro/useChartContainerProProps.js +11 -5
  80. package/node/ChartDataProviderPro/ChartDataProviderPro.js +298 -0
  81. package/node/ChartDataProviderPro/useChartDataProviderProProps.js +23 -0
  82. package/node/Heatmap/Heatmap.js +28 -2
  83. package/node/Heatmap/HeatmapTooltip.js +4 -2
  84. package/node/Heatmap/formatter.js +2 -1
  85. package/node/Heatmap/plugin.js +2 -2
  86. package/node/LineChartPro/LineChartPro.js +58 -37
  87. package/node/ScatterChartPro/ScatterChartPro.js +36 -28
  88. package/node/hooks/index.js +16 -1
  89. package/node/{context/CartesianProviderPro → hooks/zoom}/index.js +4 -4
  90. package/node/hooks/zoom/useIsZoomInteracting.js +19 -0
  91. package/node/index.js +34 -12
  92. package/node/internals/plugins/allPlugins.js +11 -0
  93. package/node/internals/plugins/useChartProZoom/creatZoomLookup.js +19 -0
  94. package/node/internals/plugins/useChartProZoom/defaultizeZoom.js +33 -0
  95. package/node/internals/plugins/useChartProZoom/index.js +38 -0
  96. package/node/internals/plugins/useChartProZoom/useChartProZoom.js +310 -0
  97. package/node/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +18 -0
  98. package/node/internals/plugins/useChartProZoom/useChartProZoom.utils.js +140 -0
  99. package/node/internals/plugins/useChartProZoom/zoom.types.js +5 -0
  100. package/node/internals/utils/releaseInfo.js +1 -1
  101. package/package.json +5 -5
  102. package/typeOverloads/modules.d.ts +8 -1
  103. package/context/CartesianProviderPro/CartesianProviderPro.d.ts +0 -6
  104. package/context/CartesianProviderPro/CartesianProviderPro.js +0 -89
  105. package/context/CartesianProviderPro/createAxisFilterMapper.d.ts +0 -13
  106. package/context/CartesianProviderPro/createAxisFilterMapper.js +0 -60
  107. package/context/CartesianProviderPro/index.d.ts +0 -1
  108. package/context/CartesianProviderPro/index.js +0 -1
  109. package/context/ChartDataProviderPro/ChartDataProviderPro.d.ts +0 -7
  110. package/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -50
  111. package/context/ChartDataProviderPro/useChartDataProviderProProps.d.ts +0 -14
  112. package/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -43
  113. package/context/ZoomProvider/Zoom.types.d.ts +0 -144
  114. package/context/ZoomProvider/ZoomContext.d.ts +0 -4
  115. package/context/ZoomProvider/ZoomContext.js +0 -16
  116. package/context/ZoomProvider/ZoomProvider.d.ts +0 -3
  117. package/context/ZoomProvider/ZoomProvider.js +0 -56
  118. package/context/ZoomProvider/ZoomSetup.d.ts +0 -9
  119. package/context/ZoomProvider/ZoomSetup.js +0 -16
  120. package/context/ZoomProvider/defaultizeZoom.d.ts +0 -2
  121. package/context/ZoomProvider/defaultizeZoom.js +0 -32
  122. package/context/ZoomProvider/index.d.ts +0 -3
  123. package/context/ZoomProvider/index.js +0 -3
  124. package/context/ZoomProvider/initializeZoomData.d.ts +0 -6
  125. package/context/ZoomProvider/initializeZoomData.js +0 -13
  126. package/context/ZoomProvider/useSetupPan.d.ts +0 -1
  127. package/context/ZoomProvider/useSetupPan.js +0 -106
  128. package/context/ZoomProvider/useSetupZoom.d.ts +0 -1
  129. package/context/ZoomProvider/useSetupZoom.js +0 -274
  130. package/context/ZoomProvider/useZoom.d.ts +0 -7
  131. package/context/ZoomProvider/useZoom.js +0 -19
  132. package/context/index.d.ts +0 -3
  133. package/context/index.js +0 -5
  134. package/modern/context/CartesianProviderPro/CartesianProviderPro.js +0 -89
  135. package/modern/context/CartesianProviderPro/createAxisFilterMapper.js +0 -60
  136. package/modern/context/CartesianProviderPro/index.js +0 -1
  137. package/modern/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -50
  138. package/modern/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -43
  139. package/modern/context/ZoomProvider/ZoomContext.js +0 -16
  140. package/modern/context/ZoomProvider/ZoomProvider.js +0 -56
  141. package/modern/context/ZoomProvider/ZoomSetup.js +0 -16
  142. package/modern/context/ZoomProvider/defaultizeZoom.js +0 -32
  143. package/modern/context/ZoomProvider/index.js +0 -3
  144. package/modern/context/ZoomProvider/initializeZoomData.js +0 -13
  145. package/modern/context/ZoomProvider/useSetupPan.js +0 -106
  146. package/modern/context/ZoomProvider/useSetupZoom.js +0 -274
  147. package/modern/context/ZoomProvider/useZoom.js +0 -19
  148. package/modern/context/index.js +0 -5
  149. package/node/context/CartesianProviderPro/CartesianProviderPro.js +0 -95
  150. package/node/context/CartesianProviderPro/createAxisFilterMapper.js +0 -68
  151. package/node/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -56
  152. package/node/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -50
  153. package/node/context/ZoomProvider/ZoomContext.js +0 -23
  154. package/node/context/ZoomProvider/ZoomProvider.js +0 -63
  155. package/node/context/ZoomProvider/ZoomSetup.js +0 -20
  156. package/node/context/ZoomProvider/defaultizeZoom.js +0 -40
  157. package/node/context/ZoomProvider/index.js +0 -38
  158. package/node/context/ZoomProvider/initializeZoomData.js +0 -20
  159. package/node/context/ZoomProvider/useSetupPan.js +0 -114
  160. package/node/context/ZoomProvider/useSetupZoom.js +0 -281
  161. package/node/context/ZoomProvider/useZoom.js +0 -25
  162. package/node/context/index.js +0 -27
  163. /package/{context/ChartDataProviderPro → ChartDataProviderPro}/index.d.ts +0 -0
  164. /package/{context/ChartDataProviderPro → ChartDataProviderPro}/index.js +0 -0
  165. /package/{context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/useChartProZoom.types.js} +0 -0
  166. /package/{modern/context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/zoom.types.js} +0 -0
  167. /package/modern/{context/ChartDataProviderPro → ChartDataProviderPro}/index.js +0 -0
  168. /package/node/{context/ChartDataProviderPro → ChartDataProviderPro}/index.js +0 -0
  169. /package/node/{context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/useChartProZoom.types.js} +0 -0
@@ -2,13 +2,12 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["zoom", "onZoomChange"];
5
+ const _excluded = ["initialZoom", "onZoomChange", "apiRef"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { useThemeProps } from '@mui/material/styles';
9
9
  import { ChartsOverlay } from '@mui/x-charts/ChartsOverlay';
10
10
  import { ScatterPlot } from '@mui/x-charts/ScatterChart';
11
- import { ZAxisContextProvider } from '@mui/x-charts/context';
12
11
  import { ChartsVoronoiHandler } from '@mui/x-charts/ChartsVoronoiHandler';
13
12
  import { ChartsAxis } from '@mui/x-charts/ChartsAxis';
14
13
  import { ChartsGrid } from '@mui/x-charts/ChartsGrid';
@@ -17,9 +16,8 @@ import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
17
16
  import { ChartsAxisHighlight } from '@mui/x-charts/ChartsAxisHighlight';
18
17
  import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip';
19
18
  import { useScatterChartProps, ChartsWrapper } from '@mui/x-charts/internals';
20
- import { ZoomSetup } from "../context/ZoomProvider/ZoomSetup.js";
21
- import { ChartDataProviderPro } from "../context/ChartDataProviderPro/index.js";
22
19
  import { useChartContainerProProps } from "../ChartContainerPro/useChartContainerProProps.js";
20
+ import { ChartDataProviderPro } from "../ChartDataProviderPro/index.js";
23
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
22
  /**
25
23
  * Demos:
@@ -37,14 +35,14 @@ const ScatterChartPro = /*#__PURE__*/React.forwardRef(function ScatterChartPro(i
37
35
  name: 'MuiScatterChartPro'
38
36
  });
39
37
  const {
40
- zoom,
41
- onZoomChange
38
+ initialZoom,
39
+ onZoomChange,
40
+ apiRef
42
41
  } = props,
43
42
  other = _objectWithoutPropertiesLoose(props, _excluded);
44
43
  const {
45
44
  chartsWrapperProps,
46
45
  chartContainerProps,
47
- zAxisProps,
48
46
  voronoiHandlerProps,
49
47
  chartsAxisProps,
50
48
  gridProps,
@@ -57,21 +55,21 @@ const ScatterChartPro = /*#__PURE__*/React.forwardRef(function ScatterChartPro(i
57
55
  const {
58
56
  chartDataProviderProProps,
59
57
  chartsSurfaceProps
60
- } = useChartContainerProProps(chartContainerProps, ref);
58
+ } = useChartContainerProProps(_extends({}, chartContainerProps, {
59
+ initialZoom,
60
+ onZoomChange,
61
+ apiRef
62
+ }), ref);
61
63
  const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
62
64
  return /*#__PURE__*/_jsx(ChartDataProviderPro, _extends({}, chartDataProviderProProps, {
63
- zoom: zoom,
64
- onZoomChange: onZoomChange,
65
65
  children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
66
- children: [!props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsx(ChartsSurface, _extends({}, chartsSurfaceProps, {
67
- children: /*#__PURE__*/_jsxs(ZAxisContextProvider, _extends({}, zAxisProps, {
68
- children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx("g", {
69
- "data-drawing-container": true,
70
- children: /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps))
71
- }), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props?.slotProps?.tooltip, {
72
- trigger: "item"
73
- })), /*#__PURE__*/_jsx(ZoomSetup, {}), children]
74
- }))
66
+ children: [!props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
67
+ children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx("g", {
68
+ "data-drawing-container": true,
69
+ children: /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps))
70
+ }), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props?.slotProps?.tooltip, {
71
+ trigger: "item"
72
+ })), children]
75
73
  }))]
76
74
  }))
77
75
  }));
@@ -81,6 +79,11 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
81
79
  // | These PropTypes are generated from the TypeScript type definitions |
82
80
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
83
81
  // ----------------------------------------------------------------------
82
+ apiRef: PropTypes.shape({
83
+ current: PropTypes.shape({
84
+ setZoomData: PropTypes.func.isRequired
85
+ })
86
+ }),
84
87
  /**
85
88
  * The configuration of axes highlight.
86
89
  * @see See {@link https://mui.com/x/react-charts/highlighting/ highlighting docs} for more details.
@@ -141,6 +144,19 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
141
144
  dataIndex: PropTypes.number,
142
145
  seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
143
146
  }),
147
+ /**
148
+ * This prop is used to help implement the accessibility logic.
149
+ * If you don't provide this prop. It falls back to a randomly generated id.
150
+ */
151
+ id: PropTypes.string,
152
+ /**
153
+ * The list of zoom data related to each axis.
154
+ */
155
+ initialZoom: PropTypes.arrayOf(PropTypes.shape({
156
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
157
+ end: PropTypes.number.isRequired,
158
+ start: PropTypes.number.isRequired
159
+ })),
144
160
  /**
145
161
  * Indicate which axis to display the left of the charts.
146
162
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -156,7 +172,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
156
172
  * The margin between the SVG and the drawing area.
157
173
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
158
174
  * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
159
- * @default object Depends on the charts type.
160
175
  */
161
176
  margin: PropTypes.shape({
162
177
  bottom: PropTypes.number,
@@ -209,6 +224,7 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
209
224
  */
210
225
  slots: PropTypes.object,
211
226
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
227
+ theme: PropTypes.oneOf(['dark', 'light']),
212
228
  title: PropTypes.string,
213
229
  /**
214
230
  * Indicate which axis to display the top of the charts.
@@ -371,14 +387,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
371
387
  id: PropTypes.string,
372
388
  max: PropTypes.number,
373
389
  min: PropTypes.number
374
- })),
375
- /**
376
- * The list of zoom data related to each axis.
377
- */
378
- zoom: PropTypes.arrayOf(PropTypes.shape({
379
- axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
380
- end: PropTypes.number.isRequired,
381
- start: PropTypes.number.isRequired
382
390
  }))
383
391
  } : void 0;
384
392
  export { ScatterChartPro };
@@ -1 +1,2 @@
1
- export { useHeatmapSeries as unstable_useHeatmapSeries } from "./useSeries.js";
1
+ export { useHeatmapSeries as unstable_useHeatmapSeries } from "./useSeries.js";
2
+ export * from "./zoom/index.js";
@@ -0,0 +1 @@
1
+ export * from "./useIsZoomInteracting.js";
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+
3
+ import { useSelector, useStore } from '@mui/x-charts/internals';
4
+ import { selectorChartZoomIsInteracting } from "../../internals/plugins/useChartProZoom/index.js";
5
+ /**
6
+ * Get access to the zoom state.
7
+ *
8
+ * @returns {boolean} Inform the zoom is interacting.
9
+ */
10
+ export function useIsZoomInteracting() {
11
+ const store = useStore();
12
+ const isInteracting = useSelector(store, selectorChartZoomIsInteracting);
13
+ return isInteracting;
14
+ }
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts-pro v8.0.0-alpha.7
2
+ * @mui/x-charts-pro v8.0.0-alpha.9
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -32,13 +32,13 @@ export * from '@mui/x-charts/ScatterChart';
32
32
  export * from '@mui/x-charts/SparkLineChart';
33
33
  export * from '@mui/x-charts/Gauge';
34
34
  export * from '@mui/x-charts/ChartsSurface';
35
+ export * from '@mui/x-charts/ChartDataProvider';
36
+ export * from '@mui/x-charts/ChartsLabel';
35
37
 
36
38
  // Pro components
37
39
  export * from "./Heatmap/index.js";
38
40
  export * from "./ChartContainerPro/index.js";
41
+ export * from "./ChartDataProviderPro/index.js";
39
42
  export * from "./ScatterChartPro/index.js";
40
43
  export * from "./BarChartPro/index.js";
41
- export * from "./LineChartPro/index.js";
42
-
43
- // Pro context
44
- export * from "./context/index.js";
44
+ export * from "./LineChartPro/index.js";
@@ -0,0 +1,5 @@
1
+ // This file should be removed after creating all plugins in favor of a file per chart type.
2
+
3
+ import { useChartCartesianAxis, useChartInteraction, useChartZAxis } from '@mui/x-charts/internals';
4
+ import { useChartProZoom } from "./useChartProZoom/index.js";
5
+ export const ALL_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartProZoom];
@@ -0,0 +1,12 @@
1
+ import { defaultizeZoom } from "./defaultizeZoom.js";
2
+ export const creatZoomLookup = axes => axes.reduce((acc, v) => {
3
+ const {
4
+ zoom,
5
+ id: axisId
6
+ } = v;
7
+ const defaultizedZoom = defaultizeZoom(zoom, axisId, 'x');
8
+ if (defaultizedZoom) {
9
+ acc[axisId] = defaultizedZoom;
10
+ }
11
+ return acc;
12
+ }, {});
@@ -0,0 +1,25 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ const defaultZoomOptions = {
3
+ minStart: 0,
4
+ maxEnd: 100,
5
+ step: 5,
6
+ minSpan: 10,
7
+ maxSpan: 100,
8
+ panning: true,
9
+ filterMode: 'keep'
10
+ };
11
+ export const defaultizeZoom = (zoom, axisId, axisDirection) => {
12
+ if (!zoom) {
13
+ return undefined;
14
+ }
15
+ if (zoom === true) {
16
+ return _extends({
17
+ axisId,
18
+ axisDirection
19
+ }, defaultZoomOptions);
20
+ }
21
+ return _extends({
22
+ axisId,
23
+ axisDirection
24
+ }, defaultZoomOptions, zoom);
25
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./useChartProZoom.selectors.js";
2
+ export * from "./useChartProZoom.js";
3
+ export * from "./useChartProZoom.types.js";
@@ -0,0 +1,303 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import * as React from 'react';
5
+ import { useSelector, getSVGPoint, selectorChartDrawingArea } from '@mui/x-charts/internals';
6
+ import { creatZoomLookup } from "./creatZoomLookup.js";
7
+ import { getDiff, getHorizontalCenterRatio, getPinchScaleRatio, getVerticalCenterRatio, getWheelScaleRatio, isSpanValid, preventDefault, zoomAtPoint } from "./useChartProZoom.utils.js";
8
+ import { selectorChartZoomOptionsLookup } from "./useChartProZoom.selectors.js";
9
+
10
+ // It is helpful to avoid the need to provide the possibly auto-generated id for each axis.
11
+ function initializeZoomData(options) {
12
+ return Object.values(options).map(({
13
+ axisId,
14
+ minStart: start,
15
+ maxEnd: end
16
+ }) => ({
17
+ axisId,
18
+ start,
19
+ end
20
+ }));
21
+ }
22
+ export const useChartProZoom = ({
23
+ store,
24
+ instance,
25
+ svgRef,
26
+ params
27
+ }) => {
28
+ const drawingArea = useSelector(store, selectorChartDrawingArea);
29
+ const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
30
+ const isZoomEnabled = Object.keys(optionsLookup).length > 0;
31
+
32
+ // Add events
33
+ const panningEventCacheRef = React.useRef([]);
34
+ const zoomEventCacheRef = React.useRef([]);
35
+ const eventPrevDiff = React.useRef(0);
36
+ const interactionTimeoutRef = React.useRef(undefined);
37
+ const setIsInteracting = React.useCallback(isInteracting => {
38
+ store.update(prev => _extends({}, prev, {
39
+ zoom: _extends({}, prev.zoom, {
40
+ isInteracting
41
+ })
42
+ }));
43
+ }, [store]);
44
+ const setZoomDataCallback = React.useCallback(zoomData => {
45
+ store.update(prevState => {
46
+ const newZoomData = typeof zoomData === 'function' ? zoomData(prevState.zoom.zoomData) : zoomData;
47
+ params.onZoomChange?.(newZoomData);
48
+ return _extends({}, prevState, {
49
+ zoom: _extends({}, prevState.zoom, {
50
+ zoomData: newZoomData
51
+ })
52
+ });
53
+ });
54
+ }, [params, store]);
55
+
56
+ // Add event for chart panning
57
+ const isPanEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) || false, [optionsLookup]);
58
+ const isDraggingRef = React.useRef(false);
59
+ const touchStartRef = React.useRef(null);
60
+ React.useEffect(() => {
61
+ const element = svgRef.current;
62
+ if (element === null || !isPanEnabled) {
63
+ return () => {};
64
+ }
65
+ const handlePan = event => {
66
+ if (element === null || !isDraggingRef.current || panningEventCacheRef.current.length > 1) {
67
+ return;
68
+ }
69
+ if (touchStartRef.current == null) {
70
+ return;
71
+ }
72
+ const point = getSVGPoint(element, event);
73
+ const movementX = point.x - touchStartRef.current.x;
74
+ const movementY = (point.y - touchStartRef.current.y) * -1;
75
+ const newZoomData = touchStartRef.current.zoomData.map(zoom => {
76
+ const options = optionsLookup[zoom.axisId];
77
+ if (!options || !options.panning) {
78
+ return zoom;
79
+ }
80
+ const min = zoom.start;
81
+ const max = zoom.end;
82
+ const span = max - min;
83
+ const MIN_PERCENT = options.minStart;
84
+ const MAX_PERCENT = options.maxEnd;
85
+ const movement = options.axisDirection === 'x' ? movementX : movementY;
86
+ const dimension = options.axisDirection === 'x' ? drawingArea.width : drawingArea.height;
87
+ let newMinPercent = min - movement / dimension * span;
88
+ let newMaxPercent = max - movement / dimension * span;
89
+ if (newMinPercent < MIN_PERCENT) {
90
+ newMinPercent = MIN_PERCENT;
91
+ newMaxPercent = newMinPercent + span;
92
+ }
93
+ if (newMaxPercent > MAX_PERCENT) {
94
+ newMaxPercent = MAX_PERCENT;
95
+ newMinPercent = newMaxPercent - span;
96
+ }
97
+ if (newMinPercent < MIN_PERCENT || newMaxPercent > MAX_PERCENT || span < options.minSpan || span > options.maxSpan) {
98
+ return zoom;
99
+ }
100
+ return _extends({}, zoom, {
101
+ start: newMinPercent,
102
+ end: newMaxPercent
103
+ });
104
+ });
105
+ setZoomDataCallback(newZoomData);
106
+ };
107
+ const handleDown = event => {
108
+ panningEventCacheRef.current.push(event);
109
+ const point = getSVGPoint(element, event);
110
+ if (!instance.isPointInside(point)) {
111
+ return;
112
+ }
113
+ // If there is only one pointer, prevent selecting text
114
+ if (panningEventCacheRef.current.length === 1) {
115
+ event.preventDefault();
116
+ }
117
+ isDraggingRef.current = true;
118
+ setIsInteracting(true);
119
+ touchStartRef.current = {
120
+ x: point.x,
121
+ y: point.y,
122
+ zoomData: store.getSnapshot().zoom.zoomData
123
+ };
124
+ };
125
+ const handleUp = event => {
126
+ panningEventCacheRef.current.splice(panningEventCacheRef.current.findIndex(cachedEvent => cachedEvent.pointerId === event.pointerId), 1);
127
+ setIsInteracting(false);
128
+ isDraggingRef.current = false;
129
+ touchStartRef.current = null;
130
+ };
131
+ element.addEventListener('pointerdown', handleDown);
132
+ document.addEventListener('pointermove', handlePan);
133
+ document.addEventListener('pointerup', handleUp);
134
+ document.addEventListener('pointercancel', handleUp);
135
+ document.addEventListener('pointerleave', handleUp);
136
+ return () => {
137
+ element.removeEventListener('pointerdown', handleDown);
138
+ document.removeEventListener('pointermove', handlePan);
139
+ document.removeEventListener('pointerup', handleUp);
140
+ document.removeEventListener('pointercancel', handleUp);
141
+ document.removeEventListener('pointerleave', handleUp);
142
+ };
143
+ }, [instance, svgRef, isDraggingRef, setIsInteracting, isPanEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store]);
144
+
145
+ // Add event for chart zoom in/out
146
+ React.useEffect(() => {
147
+ const element = svgRef.current;
148
+ if (element === null || !isZoomEnabled) {
149
+ return () => {};
150
+ }
151
+ const wheelHandler = event => {
152
+ if (element === null) {
153
+ return;
154
+ }
155
+ const point = getSVGPoint(element, event);
156
+ if (!instance.isPointInside(point)) {
157
+ return;
158
+ }
159
+ event.preventDefault();
160
+ if (interactionTimeoutRef.current) {
161
+ clearTimeout(interactionTimeoutRef.current);
162
+ }
163
+ setIsInteracting(true);
164
+ // Debounce transition to `isInteractive=false`.
165
+ // Useful because wheel events don't have an "end" event.
166
+ interactionTimeoutRef.current = window.setTimeout(() => {
167
+ setIsInteracting(false);
168
+ }, 166);
169
+ setZoomDataCallback(prevZoomData => {
170
+ return prevZoomData.map(zoom => {
171
+ const option = optionsLookup[zoom.axisId];
172
+ if (!option) {
173
+ return zoom;
174
+ }
175
+ const centerRatio = option.axisDirection === 'x' ? getHorizontalCenterRatio(point, drawingArea) : getVerticalCenterRatio(point, drawingArea);
176
+ const {
177
+ scaleRatio,
178
+ isZoomIn
179
+ } = getWheelScaleRatio(event, option.step);
180
+ const [newMinRange, newMaxRange] = zoomAtPoint(centerRatio, scaleRatio, zoom, option);
181
+ if (!isSpanValid(newMinRange, newMaxRange, isZoomIn, option)) {
182
+ return zoom;
183
+ }
184
+ return {
185
+ axisId: zoom.axisId,
186
+ start: newMinRange,
187
+ end: newMaxRange
188
+ };
189
+ });
190
+ });
191
+ };
192
+ function pointerDownHandler(event) {
193
+ zoomEventCacheRef.current.push(event);
194
+ setIsInteracting(true);
195
+ }
196
+ function pointerMoveHandler(event) {
197
+ if (element === null) {
198
+ return;
199
+ }
200
+ const index = zoomEventCacheRef.current.findIndex(cachedEv => cachedEv.pointerId === event.pointerId);
201
+ zoomEventCacheRef.current[index] = event;
202
+
203
+ // Not a pinch gesture
204
+ if (zoomEventCacheRef.current.length !== 2) {
205
+ return;
206
+ }
207
+ const firstEvent = zoomEventCacheRef.current[0];
208
+ const curDiff = getDiff(zoomEventCacheRef.current);
209
+ setZoomDataCallback(prevZoomData => {
210
+ const newZoomData = prevZoomData.map(zoom => {
211
+ const option = optionsLookup[zoom.axisId];
212
+ if (!option) {
213
+ return zoom;
214
+ }
215
+ const {
216
+ scaleRatio,
217
+ isZoomIn
218
+ } = getPinchScaleRatio(curDiff, eventPrevDiff.current, option.step);
219
+
220
+ // If the scale ratio is 0, it means the pinch gesture is not valid.
221
+ if (scaleRatio === 0) {
222
+ return zoom;
223
+ }
224
+ const point = getSVGPoint(element, firstEvent);
225
+ const centerRatio = option.axisDirection === 'x' ? getHorizontalCenterRatio(point, drawingArea) : getVerticalCenterRatio(point, drawingArea);
226
+ const [newMinRange, newMaxRange] = zoomAtPoint(centerRatio, scaleRatio, zoom, option);
227
+ if (!isSpanValid(newMinRange, newMaxRange, isZoomIn, option)) {
228
+ return zoom;
229
+ }
230
+ return {
231
+ axisId: zoom.axisId,
232
+ start: newMinRange,
233
+ end: newMaxRange
234
+ };
235
+ });
236
+ eventPrevDiff.current = curDiff;
237
+ return newZoomData;
238
+ });
239
+ }
240
+ function pointerUpHandler(event) {
241
+ zoomEventCacheRef.current.splice(zoomEventCacheRef.current.findIndex(cachedEvent => cachedEvent.pointerId === event.pointerId), 1);
242
+ if (zoomEventCacheRef.current.length < 2) {
243
+ eventPrevDiff.current = 0;
244
+ }
245
+ if (event.type === 'pointerup' || event.type === 'pointercancel') {
246
+ setIsInteracting(false);
247
+ }
248
+ }
249
+ element.addEventListener('wheel', wheelHandler);
250
+ element.addEventListener('pointerdown', pointerDownHandler);
251
+ element.addEventListener('pointermove', pointerMoveHandler);
252
+ element.addEventListener('pointerup', pointerUpHandler);
253
+ element.addEventListener('pointercancel', pointerUpHandler);
254
+ element.addEventListener('pointerout', pointerUpHandler);
255
+ element.addEventListener('pointerleave', pointerUpHandler);
256
+
257
+ // Prevent zooming the entire page on touch devices
258
+ element.addEventListener('touchstart', preventDefault);
259
+ element.addEventListener('touchmove', preventDefault);
260
+ return () => {
261
+ element.removeEventListener('wheel', wheelHandler);
262
+ element.removeEventListener('pointerdown', pointerDownHandler);
263
+ element.removeEventListener('pointermove', pointerMoveHandler);
264
+ element.removeEventListener('pointerup', pointerUpHandler);
265
+ element.removeEventListener('pointercancel', pointerUpHandler);
266
+ element.removeEventListener('pointerout', pointerUpHandler);
267
+ element.removeEventListener('pointerleave', pointerUpHandler);
268
+ element.removeEventListener('touchstart', preventDefault);
269
+ element.removeEventListener('touchmove', preventDefault);
270
+ if (interactionTimeoutRef.current) {
271
+ clearTimeout(interactionTimeoutRef.current);
272
+ }
273
+ };
274
+ }, [svgRef, drawingArea, isZoomEnabled, optionsLookup, setIsInteracting, instance, setZoomDataCallback]);
275
+ return {
276
+ publicAPI: {
277
+ setZoomData: setZoomDataCallback
278
+ },
279
+ instance: {
280
+ setZoomData: setZoomDataCallback
281
+ }
282
+ };
283
+ };
284
+ useChartProZoom.params = {
285
+ initialZoom: true,
286
+ onZoomChange: true
287
+ };
288
+ useChartProZoom.getDefaultizedParams = ({
289
+ params
290
+ }) => {
291
+ const optionsLookup = _extends({}, creatZoomLookup(params.defaultizedXAxis), creatZoomLookup(params.defaultizedYAxis));
292
+ return _extends({}, params, {
293
+ optionsLookup
294
+ });
295
+ };
296
+ useChartProZoom.getInitialState = params => {
297
+ return {
298
+ zoom: {
299
+ zoomData: params.initialZoom === undefined ? initializeZoomData(params.optionsLookup) : params.initialZoom,
300
+ isInteracting: false
301
+ }
302
+ };
303
+ };
@@ -0,0 +1,10 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { createSelector, selectorChartRawXAxis, selectorChartRawYAxis } from '@mui/x-charts/internals';
3
+ import { creatZoomLookup } from "./creatZoomLookup.js";
4
+ export const selectorChartZoomState = state => state.zoom;
5
+ const selectorChartXZoomOptionsLookup = createSelector(selectorChartRawXAxis, creatZoomLookup);
6
+ const selectorChartYZoomOptionsLookup = createSelector(selectorChartRawYAxis, creatZoomLookup);
7
+ export const selectorChartZoomOptionsLookup = createSelector([selectorChartXZoomOptionsLookup, selectorChartYZoomOptionsLookup], (xLookup, yLookup) => _extends({}, xLookup, yLookup));
8
+ export const selectorChartZoomData = createSelector(selectorChartZoomState, zoom => zoom.zoomData);
9
+ export const selectorChartZoomIsInteracting = createSelector(selectorChartZoomState, zoom => zoom.isInteracting);
10
+ export const selectorChartZoomIsEnabled = createSelector(selectorChartZoomOptionsLookup, optionsLookup => Object.keys(optionsLookup).length > 0);
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Helper to get the range (in percents of a reference range) corresponding to a given scale.
3
+ * @param centerRatio {number} The ratio of the point that should not move between the previous and next range.
4
+ * @param scaleRatio {number} The target scale ratio.
5
+ * @returns The range to display.
6
+ */
7
+ export const zoomAtPoint = (centerRatio, scaleRatio, currentZoomData, options) => {
8
+ const MIN_RANGE = options.minStart;
9
+ const MAX_RANGE = options.maxEnd;
10
+ const MIN_ALLOWED_SPAN = options.minSpan;
11
+ const minRange = currentZoomData.start;
12
+ const maxRange = currentZoomData.end;
13
+ const point = minRange + centerRatio * (maxRange - minRange);
14
+ let newMinRange = (minRange + point * (scaleRatio - 1)) / scaleRatio;
15
+ let newMaxRange = (maxRange + point * (scaleRatio - 1)) / scaleRatio;
16
+ let minSpillover = 0;
17
+ let maxSpillover = 0;
18
+ if (newMinRange < MIN_RANGE) {
19
+ minSpillover = Math.abs(newMinRange);
20
+ newMinRange = MIN_RANGE;
21
+ }
22
+ if (newMaxRange > MAX_RANGE) {
23
+ maxSpillover = Math.abs(newMaxRange - MAX_RANGE);
24
+ newMaxRange = MAX_RANGE;
25
+ }
26
+ if (minSpillover > 0 && maxSpillover > 0) {
27
+ return [MIN_RANGE, MAX_RANGE];
28
+ }
29
+ newMaxRange += minSpillover;
30
+ newMinRange -= maxSpillover;
31
+ newMinRange = Math.min(MAX_RANGE - MIN_ALLOWED_SPAN, Math.max(MIN_RANGE, newMinRange));
32
+ newMaxRange = Math.max(MIN_ALLOWED_SPAN, Math.min(MAX_RANGE, newMaxRange));
33
+ return [newMinRange, newMaxRange];
34
+ };
35
+
36
+ /**
37
+ * Checks if the new span is valid.
38
+ */
39
+ export function isSpanValid(minRange, maxRange, isZoomIn, option) {
40
+ const newSpanPercent = maxRange - minRange;
41
+ if (isZoomIn && newSpanPercent < option.minSpan || !isZoomIn && newSpanPercent > option.maxSpan) {
42
+ return false;
43
+ }
44
+ if (minRange < option.minStart || maxRange > option.maxEnd) {
45
+ return false;
46
+ }
47
+ return true;
48
+ }
49
+ function getMultiplier(event) {
50
+ const ctrlMultiplier = event.ctrlKey ? 3 : 1;
51
+
52
+ // DeltaMode: 0 is pixel, 1 is line, 2 is page
53
+ // This is defined by the browser.
54
+ if (event.deltaMode === 1) {
55
+ return 1 * ctrlMultiplier;
56
+ }
57
+ if (event.deltaMode) {
58
+ return 10 * ctrlMultiplier;
59
+ }
60
+ return 0.2 * ctrlMultiplier;
61
+ }
62
+
63
+ /**
64
+ * Get the scale ratio and if it's a zoom in or out from a wheel event.
65
+ */
66
+ export function getWheelScaleRatio(event, step) {
67
+ const deltaY = -event.deltaY;
68
+ const multiplier = getMultiplier(event);
69
+ const scaledStep = step * multiplier * deltaY / 1000;
70
+ // Clamp the scale ratio between 0.1 and 1.9 so that the zoom is not too big or too small.
71
+ const scaleRatio = Math.min(Math.max(1 + scaledStep, 0.1), 1.9);
72
+ const isZoomIn = deltaY > 0;
73
+ return {
74
+ scaleRatio,
75
+ isZoomIn
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Get the scale ratio and if it's a zoom in or out from a pinch gesture.
81
+ */
82
+ export function getPinchScaleRatio(curDiff, prevDiff, step) {
83
+ const scaledStep = step / 1000;
84
+ let scaleRatio = 0;
85
+ let isZoomIn = false;
86
+ const hasMoved = prevDiff > 0;
87
+ if (hasMoved && curDiff > prevDiff) {
88
+ // The distance between the two pointers has increased
89
+ scaleRatio = 1 + scaledStep;
90
+ isZoomIn = true;
91
+ }
92
+ if (hasMoved && curDiff < prevDiff) {
93
+ // The distance between the two pointers has decreased
94
+ scaleRatio = 1 - scaledStep;
95
+ isZoomIn = false;
96
+ }
97
+ return {
98
+ scaleRatio,
99
+ isZoomIn
100
+ };
101
+ }
102
+ export function getDiff(eventCache) {
103
+ const [firstEvent, secondEvent] = eventCache;
104
+ return Math.hypot(firstEvent.pageX - secondEvent.pageX, firstEvent.pageY - secondEvent.pageY);
105
+ }
106
+
107
+ /**
108
+ * Get the ratio of the point in the horizontal center of the area.
109
+ */
110
+ export function getHorizontalCenterRatio(point, area) {
111
+ const {
112
+ left,
113
+ width
114
+ } = area;
115
+ return (point.x - left) / width;
116
+ }
117
+ export function preventDefault(event) {
118
+ event.preventDefault();
119
+ }
120
+ export function getVerticalCenterRatio(point, area) {
121
+ const {
122
+ top,
123
+ height
124
+ } = area;
125
+ return (point.y - top) / height * -1 + 1;
126
+ }