@mui/x-charts-pro 9.4.0 → 9.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/BarChartPro/BarChartPro.js +6 -4
  2. package/BarChartPro/BarChartPro.mjs +7 -5
  3. package/CHANGELOG.md +251 -0
  4. package/ChartsDataProviderPro/ChartsDataProviderPro.js +7 -3
  5. package/ChartsDataProviderPro/ChartsDataProviderPro.mjs +7 -3
  6. package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +1 -1
  7. package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.mjs +1 -1
  8. package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.js +1 -1
  9. package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.mjs +1 -1
  10. package/ChartsToolbarPro/ChartsToolbarPro.js +3 -2
  11. package/ChartsToolbarPro/ChartsToolbarPro.mjs +3 -2
  12. package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.js +1 -1
  13. package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.mjs +1 -1
  14. package/ChartsToolbarPro/ChartsToolbarZoomInTrigger.js +1 -1
  15. package/ChartsToolbarPro/ChartsToolbarZoomInTrigger.mjs +1 -1
  16. package/ChartsToolbarPro/ChartsToolbarZoomOutTrigger.js +1 -1
  17. package/ChartsToolbarPro/ChartsToolbarZoomOutTrigger.mjs +1 -1
  18. package/FunnelChart/FunnelChart.js +1 -1
  19. package/FunnelChart/FunnelChart.mjs +1 -1
  20. package/FunnelChart/FunnelPlot.js +5 -1
  21. package/FunnelChart/FunnelPlot.mjs +5 -1
  22. package/FunnelChart/funnel.types.d.mts +1 -1
  23. package/FunnelChart/funnel.types.d.ts +1 -1
  24. package/Heatmap/Heatmap.js +5 -3
  25. package/Heatmap/Heatmap.mjs +5 -3
  26. package/Heatmap/HeatmapCell.js +1 -1
  27. package/Heatmap/HeatmapCell.mjs +1 -1
  28. package/Heatmap/HeatmapPlot.js +1 -1
  29. package/Heatmap/HeatmapPlot.mjs +1 -1
  30. package/Heatmap/HeatmapTooltip/HeatmapTooltip.js +5 -25
  31. package/Heatmap/HeatmapTooltip/HeatmapTooltip.mjs +5 -25
  32. package/Heatmap/HeatmapTooltip/HeatmapTooltipContent.js +1 -1
  33. package/Heatmap/HeatmapTooltip/HeatmapTooltipContent.mjs +1 -1
  34. package/LineChartPro/LineChartPro.js +6 -4
  35. package/LineChartPro/LineChartPro.mjs +7 -5
  36. package/PieChartPro/PieChartPro.js +2 -2
  37. package/PieChartPro/PieChartPro.mjs +3 -3
  38. package/RadarChartPro/RadarChartPro.js +2 -2
  39. package/RadarChartPro/RadarChartPro.mjs +3 -3
  40. package/SankeyChart/SankeyChart.js +1 -1
  41. package/SankeyChart/SankeyChart.mjs +1 -1
  42. package/SankeyChart/SankeyDataProvider.d.mts +3 -0
  43. package/SankeyChart/SankeyDataProvider.d.ts +3 -0
  44. package/SankeyChart/SankeyDataProvider.js +170 -1
  45. package/SankeyChart/SankeyDataProvider.mjs +169 -0
  46. package/SankeyChart/SankeyLinkLabelPlot.d.mts +3 -0
  47. package/SankeyChart/SankeyLinkLabelPlot.d.ts +3 -0
  48. package/SankeyChart/SankeyLinkLabelPlot.js +12 -1
  49. package/SankeyChart/SankeyLinkLabelPlot.mjs +11 -0
  50. package/SankeyChart/SankeyLinkPlot.d.mts +3 -0
  51. package/SankeyChart/SankeyLinkPlot.d.ts +3 -0
  52. package/SankeyChart/SankeyLinkPlot.js +18 -1
  53. package/SankeyChart/SankeyLinkPlot.mjs +17 -0
  54. package/SankeyChart/SankeyNodeLabelPlot.d.mts +3 -0
  55. package/SankeyChart/SankeyNodeLabelPlot.d.ts +3 -0
  56. package/SankeyChart/SankeyNodeLabelPlot.js +12 -1
  57. package/SankeyChart/SankeyNodeLabelPlot.mjs +11 -0
  58. package/SankeyChart/SankeyNodePlot.d.mts +3 -0
  59. package/SankeyChart/SankeyNodePlot.d.ts +3 -0
  60. package/SankeyChart/SankeyNodePlot.js +18 -1
  61. package/SankeyChart/SankeyNodePlot.mjs +17 -0
  62. package/SankeyChart/SankeyPlot.js +5 -1
  63. package/SankeyChart/SankeyPlot.mjs +5 -1
  64. package/SankeyChart/SankeyTooltip/SankeyTooltip.js +8 -28
  65. package/SankeyChart/SankeyTooltip/SankeyTooltip.mjs +8 -28
  66. package/SankeyChart/SankeyTooltip/SankeyTooltipContent.js +1 -1
  67. package/SankeyChart/SankeyTooltip/SankeyTooltipContent.mjs +1 -1
  68. package/ScatterChartPro/ScatterChartPro.js +13 -7
  69. package/ScatterChartPro/ScatterChartPro.mjs +14 -8
  70. package/ScatterChartPro/ScatterChartPro.plugins.d.mts +2 -2
  71. package/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -2
  72. package/ScatterChartPro/ScatterChartPro.plugins.js +1 -1
  73. package/ScatterChartPro/ScatterChartPro.plugins.mjs +2 -2
  74. package/index.js +1 -1
  75. package/index.mjs +1 -1
  76. package/internals/plugins/allPlugins.d.mts +5 -5
  77. package/internals/plugins/allPlugins.d.ts +5 -5
  78. package/internals/plugins/allPlugins.js +2 -2
  79. package/internals/plugins/allPlugins.mjs +3 -3
  80. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.mts +36 -4
  81. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +36 -4
  82. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.js +2 -4
  83. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.mjs +1 -3
  84. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.mts +11 -11
  85. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +11 -11
  86. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.mts +0 -1
  87. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.ts +0 -1
  88. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +9 -65
  89. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.mjs +9 -64
  90. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.mts +0 -1
  91. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.ts +0 -1
  92. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.js +9 -69
  93. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.mjs +9 -68
  94. package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.d.mts +10 -0
  95. package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.d.ts +10 -0
  96. package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.js +49 -0
  97. package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.mjs +42 -0
  98. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.mts +0 -1
  99. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.ts +0 -1
  100. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +9 -39
  101. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.mjs +10 -39
  102. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.mts +0 -1
  103. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.ts +0 -1
  104. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +9 -58
  105. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.mjs +10 -58
  106. package/internals/plugins/useChartProZoom/useChartProZoom.js +2 -0
  107. package/internals/plugins/useChartProZoom/useChartProZoom.mjs +2 -0
  108. package/internals/plugins/zoomGestures/index.d.mts +5 -0
  109. package/internals/plugins/zoomGestures/index.d.ts +5 -0
  110. package/internals/plugins/zoomGestures/index.js +33 -0
  111. package/internals/plugins/zoomGestures/index.mjs +4 -0
  112. package/internals/plugins/zoomGestures/useDragGesture.d.mts +30 -0
  113. package/internals/plugins/zoomGestures/useDragGesture.d.ts +30 -0
  114. package/internals/plugins/zoomGestures/useDragGesture.js +105 -0
  115. package/internals/plugins/zoomGestures/useDragGesture.mjs +99 -0
  116. package/internals/plugins/zoomGestures/useDragOnPressGesture.d.mts +30 -0
  117. package/internals/plugins/zoomGestures/useDragOnPressGesture.d.ts +30 -0
  118. package/internals/plugins/zoomGestures/useDragOnPressGesture.js +105 -0
  119. package/internals/plugins/zoomGestures/useDragOnPressGesture.mjs +99 -0
  120. package/internals/plugins/zoomGestures/usePinchGesture.d.mts +22 -0
  121. package/internals/plugins/zoomGestures/usePinchGesture.d.ts +22 -0
  122. package/internals/plugins/zoomGestures/usePinchGesture.js +77 -0
  123. package/internals/plugins/zoomGestures/usePinchGesture.mjs +71 -0
  124. package/internals/plugins/zoomGestures/useWheelGesture.d.mts +21 -0
  125. package/internals/plugins/zoomGestures/useWheelGesture.d.ts +21 -0
  126. package/internals/plugins/zoomGestures/useWheelGesture.js +78 -0
  127. package/internals/plugins/zoomGestures/useWheelGesture.mjs +72 -0
  128. package/internals/plugins/zoomGestures/zoomGestures.types.d.mts +29 -0
  129. package/internals/plugins/zoomGestures/zoomGestures.types.d.ts +29 -0
  130. package/internals/plugins/zoomGestures/zoomGestures.types.js +5 -0
  131. package/internals/plugins/zoomGestures/zoomGestures.types.mjs +1 -0
  132. package/models/seriesType/heatmap.d.mts +1 -1
  133. package/models/seriesType/heatmap.d.ts +1 -1
  134. package/package.json +10 -7
@@ -1,59 +1,34 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.useZoomOnPinch = void 0;
9
- var React = _interopRequireWildcard(require("react"));
10
8
  var _internals = require("@mui/x-charts/internals");
11
- var _rafThrottle = require("@mui/x-internals/rafThrottle");
12
9
  var _useZoom = require("./useZoom.utils");
13
10
  var _ZoomInteractionConfig = require("../ZoomInteractionConfig.selectors");
11
+ var _usePinchGesture = require("../../zoomGestures/usePinchGesture");
14
12
  const useZoomOnPinch = ({
15
13
  store,
16
14
  instance
17
15
  }, setZoomDataCallback) => {
18
- const {
19
- chartsLayerContainerRef
20
- } = instance;
21
16
  const drawingArea = store.use(_internals.selectorChartDrawingArea);
22
17
  const optionsLookup = store.use(_internals.selectorChartZoomOptionsLookup);
23
18
  const config = store.use(_ZoomInteractionConfig.selectorZoomInteractionConfig, 'pinch');
24
19
  const isZoomOnPinchEnabled = Object.keys(optionsLookup).length > 0 && Boolean(config);
25
- React.useEffect(() => {
26
- if (!isZoomOnPinchEnabled) {
27
- return;
28
- }
29
- instance.updateZoomInteractionListeners('zoomPinch', {
30
- requiredKeys: config.requiredKeys
31
- });
32
- }, [config, isZoomOnPinchEnabled, instance]);
33
-
34
- // Zoom on pinch
35
- React.useEffect(() => {
36
- const element = chartsLayerContainerRef.current;
37
- if (element === null || !isZoomOnPinchEnabled) {
38
- return () => {};
39
- }
40
- const rafThrottledCallback = (0, _rafThrottle.rafThrottle)(event => {
41
- // If the delta is 0, it means the pinch gesture is not valid.
42
- if (event.detail.direction === 0) {
43
- return;
44
- }
20
+ (0, _usePinchGesture.usePinchGesture)(instance, {
21
+ enabled: isZoomOnPinchEnabled,
22
+ requiredKeys: config?.requiredKeys,
23
+ onPinch: (point, deltaScale, direction) => {
45
24
  setZoomDataCallback(prev => {
46
25
  return prev.map(zoom => {
47
26
  const option = optionsLookup[zoom.axisId];
48
27
  if (!option) {
49
28
  return zoom;
50
29
  }
51
- const isZoomIn = event.detail.direction > 0;
52
- const scaleRatio = 1 + event.detail.deltaScale;
53
- const point = (0, _internals.getChartPoint)(element, {
54
- clientX: event.detail.centroid.x,
55
- clientY: event.detail.centroid.y
56
- });
30
+ const isZoomIn = direction > 0;
31
+ const scaleRatio = 1 + deltaScale;
57
32
  const centerRatio = option.axisDirection === 'x' ? (0, _useZoom.getHorizontalCenterRatio)(point, drawingArea, option.reverse) : (0, _useZoom.getVerticalCenterRatio)(point, drawingArea, option.reverse);
58
33
  const [newMinRange, newMaxRange] = (0, _useZoom.zoomAtPoint)(centerRatio, scaleRatio, zoom, option);
59
34
  if (!(0, _useZoom.isSpanValid)(newMinRange, newMaxRange, isZoomIn, option)) {
@@ -66,12 +41,7 @@ const useZoomOnPinch = ({
66
41
  };
67
42
  });
68
43
  });
69
- });
70
- const zoomHandler = instance.addInteractionListener('zoomPinch', rafThrottledCallback);
71
- return () => {
72
- zoomHandler.cleanup();
73
- rafThrottledCallback.clear();
74
- };
75
- }, [chartsLayerContainerRef, drawingArea, isZoomOnPinchEnabled, optionsLookup, store, instance, setZoomDataCallback]);
44
+ }
45
+ });
76
46
  };
77
47
  exports.useZoomOnPinch = useZoomOnPinch;
@@ -1,53 +1,29 @@
1
1
  'use client';
2
2
 
3
- import * as React from 'react';
4
- import { getChartPoint, selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
5
- import { rafThrottle } from '@mui/x-internals/rafThrottle';
3
+ import { selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
6
4
  import { getHorizontalCenterRatio, getVerticalCenterRatio, isSpanValid, zoomAtPoint } from "./useZoom.utils.mjs";
7
5
  import { selectorZoomInteractionConfig } from "../ZoomInteractionConfig.selectors.mjs";
6
+ import { usePinchGesture } from "../../zoomGestures/usePinchGesture.mjs";
8
7
  export const useZoomOnPinch = ({
9
8
  store,
10
9
  instance
11
10
  }, setZoomDataCallback) => {
12
- const {
13
- chartsLayerContainerRef
14
- } = instance;
15
11
  const drawingArea = store.use(selectorChartDrawingArea);
16
12
  const optionsLookup = store.use(selectorChartZoomOptionsLookup);
17
13
  const config = store.use(selectorZoomInteractionConfig, 'pinch');
18
14
  const isZoomOnPinchEnabled = Object.keys(optionsLookup).length > 0 && Boolean(config);
19
- React.useEffect(() => {
20
- if (!isZoomOnPinchEnabled) {
21
- return;
22
- }
23
- instance.updateZoomInteractionListeners('zoomPinch', {
24
- requiredKeys: config.requiredKeys
25
- });
26
- }, [config, isZoomOnPinchEnabled, instance]);
27
-
28
- // Zoom on pinch
29
- React.useEffect(() => {
30
- const element = chartsLayerContainerRef.current;
31
- if (element === null || !isZoomOnPinchEnabled) {
32
- return () => {};
33
- }
34
- const rafThrottledCallback = rafThrottle(event => {
35
- // If the delta is 0, it means the pinch gesture is not valid.
36
- if (event.detail.direction === 0) {
37
- return;
38
- }
15
+ usePinchGesture(instance, {
16
+ enabled: isZoomOnPinchEnabled,
17
+ requiredKeys: config?.requiredKeys,
18
+ onPinch: (point, deltaScale, direction) => {
39
19
  setZoomDataCallback(prev => {
40
20
  return prev.map(zoom => {
41
21
  const option = optionsLookup[zoom.axisId];
42
22
  if (!option) {
43
23
  return zoom;
44
24
  }
45
- const isZoomIn = event.detail.direction > 0;
46
- const scaleRatio = 1 + event.detail.deltaScale;
47
- const point = getChartPoint(element, {
48
- clientX: event.detail.centroid.x,
49
- clientY: event.detail.centroid.y
50
- });
25
+ const isZoomIn = direction > 0;
26
+ const scaleRatio = 1 + deltaScale;
51
27
  const centerRatio = option.axisDirection === 'x' ? getHorizontalCenterRatio(point, drawingArea, option.reverse) : getVerticalCenterRatio(point, drawingArea, option.reverse);
52
28
  const [newMinRange, newMaxRange] = zoomAtPoint(centerRatio, scaleRatio, zoom, option);
53
29
  if (!isSpanValid(newMinRange, newMaxRange, isZoomIn, option)) {
@@ -60,11 +36,6 @@ export const useZoomOnPinch = ({
60
36
  };
61
37
  });
62
38
  });
63
- });
64
- const zoomHandler = instance.addInteractionListener('zoomPinch', rafThrottledCallback);
65
- return () => {
66
- zoomHandler.cleanup();
67
- rafThrottledCallback.clear();
68
- };
69
- }, [chartsLayerContainerRef, drawingArea, isZoomOnPinchEnabled, optionsLookup, store, instance, setZoomDataCallback]);
39
+ }
40
+ });
70
41
  };
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { type ChartPlugin, type ZoomData } from '@mui/x-charts/internals';
3
2
  import { type UseChartProZoomSignature } from "../useChartProZoom.types.mjs";
4
3
  export declare const useZoomOnWheel: ({
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { type ChartPlugin, type ZoomData } from '@mui/x-charts/internals';
3
2
  import { type UseChartProZoomSignature } from "../useChartProZoom.types.js";
4
3
  export declare const useZoomOnWheel: ({
@@ -1,67 +1,27 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.useZoomOnWheel = void 0;
9
- var React = _interopRequireWildcard(require("react"));
10
8
  var _internals = require("@mui/x-charts/internals");
11
- var _rafThrottle = require("@mui/x-internals/rafThrottle");
12
9
  var _useZoom = require("./useZoom.utils");
13
10
  var _ZoomInteractionConfig = require("../ZoomInteractionConfig.selectors");
11
+ var _useWheelGesture = require("../../zoomGestures/useWheelGesture");
14
12
  const useZoomOnWheel = ({
15
13
  store,
16
14
  instance
17
15
  }, setZoomDataCallback) => {
18
- const {
19
- chartsLayerContainerRef
20
- } = instance;
21
16
  const drawingArea = store.use(_internals.selectorChartDrawingArea);
22
17
  const optionsLookup = store.use(_internals.selectorChartZoomOptionsLookup);
23
- const startedOutsideRef = React.useRef(false);
24
- const startedOutsideTimeoutRef = React.useRef(null);
25
18
  const config = store.use(_ZoomInteractionConfig.selectorZoomInteractionConfig, 'wheel');
26
19
  const isZoomOnWheelEnabled = Object.keys(optionsLookup).length > 0 && Boolean(config);
27
- React.useEffect(() => {
28
- if (!isZoomOnWheelEnabled) {
29
- return;
30
- }
31
- instance.updateZoomInteractionListeners('zoomTurnWheel', {
32
- requiredKeys: config.requiredKeys
33
- });
34
- }, [config, isZoomOnWheelEnabled, instance]);
35
-
36
- // Add event for chart zoom in/out
37
- React.useEffect(() => {
38
- const element = chartsLayerContainerRef.current;
39
- if (element === null || !isZoomOnWheelEnabled) {
40
- return () => {};
41
- }
42
- const rafThrottledSetZoomData = (0, _rafThrottle.rafThrottle)(setZoomDataCallback);
43
- const zoomOnWheelHandler = instance.addInteractionListener('zoomTurnWheel', event => {
44
- const point = (0, _internals.getChartPoint)(element, {
45
- clientX: event.detail.centroid.x,
46
- clientY: event.detail.centroid.y
47
- });
48
-
49
- // This prevents a zoom event from being triggered when the mouse is outside the chart area.
50
- // The timeout is used to prevent a weird behavior where if the mouse is outside but enters due to
51
- // scrolling, then the zoom event is triggered.
52
- if (startedOutsideRef.current || !instance.isPointInside(point.x, point.y)) {
53
- startedOutsideRef.current = true;
54
- if (startedOutsideTimeoutRef.current) {
55
- clearTimeout(startedOutsideTimeoutRef.current);
56
- }
57
- startedOutsideTimeoutRef.current = setTimeout(() => {
58
- startedOutsideRef.current = false;
59
- startedOutsideTimeoutRef.current = null;
60
- }, 100);
61
- return;
62
- }
63
- event.detail.srcEvent.preventDefault();
64
- rafThrottledSetZoomData(prev => {
20
+ (0, _useWheelGesture.useWheelGesture)(instance, {
21
+ enabled: isZoomOnWheelEnabled,
22
+ requiredKeys: config?.requiredKeys,
23
+ onWheel: (point, wheelEvent) => {
24
+ setZoomDataCallback(prev => {
65
25
  return prev.map(zoom => {
66
26
  const option = optionsLookup[zoom.axisId];
67
27
  if (!option) {
@@ -71,7 +31,7 @@ const useZoomOnWheel = ({
71
31
  const {
72
32
  scaleRatio,
73
33
  isZoomIn
74
- } = (0, _useZoom.getWheelScaleRatio)(event.detail.srcEvent, option.step);
34
+ } = (0, _useZoom.getWheelScaleRatio)(wheelEvent, option.step);
75
35
  const [newMinRange, newMaxRange] = (0, _useZoom.zoomAtPoint)(centerRatio, scaleRatio, zoom, option);
76
36
  if (!(0, _useZoom.isSpanValid)(newMinRange, newMaxRange, isZoomIn, option)) {
77
37
  return zoom;
@@ -83,16 +43,7 @@ const useZoomOnWheel = ({
83
43
  };
84
44
  });
85
45
  });
86
- });
87
- return () => {
88
- zoomOnWheelHandler.cleanup();
89
- if (startedOutsideTimeoutRef.current) {
90
- clearTimeout(startedOutsideTimeoutRef.current);
91
- startedOutsideTimeoutRef.current = null;
92
- }
93
- startedOutsideRef.current = false;
94
- rafThrottledSetZoomData.clear();
95
- };
96
- }, [chartsLayerContainerRef, drawingArea, isZoomOnWheelEnabled, optionsLookup, instance, setZoomDataCallback, store]);
46
+ }
47
+ });
97
48
  };
98
49
  exports.useZoomOnWheel = useZoomOnWheel;
@@ -1,61 +1,22 @@
1
1
  'use client';
2
2
 
3
- import * as React from 'react';
4
- import { getChartPoint, selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
5
- import { rafThrottle } from '@mui/x-internals/rafThrottle';
3
+ import { selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
6
4
  import { getHorizontalCenterRatio, getVerticalCenterRatio, getWheelScaleRatio, isSpanValid, zoomAtPoint } from "./useZoom.utils.mjs";
7
5
  import { selectorZoomInteractionConfig } from "../ZoomInteractionConfig.selectors.mjs";
6
+ import { useWheelGesture } from "../../zoomGestures/useWheelGesture.mjs";
8
7
  export const useZoomOnWheel = ({
9
8
  store,
10
9
  instance
11
10
  }, setZoomDataCallback) => {
12
- const {
13
- chartsLayerContainerRef
14
- } = instance;
15
11
  const drawingArea = store.use(selectorChartDrawingArea);
16
12
  const optionsLookup = store.use(selectorChartZoomOptionsLookup);
17
- const startedOutsideRef = React.useRef(false);
18
- const startedOutsideTimeoutRef = React.useRef(null);
19
13
  const config = store.use(selectorZoomInteractionConfig, 'wheel');
20
14
  const isZoomOnWheelEnabled = Object.keys(optionsLookup).length > 0 && Boolean(config);
21
- React.useEffect(() => {
22
- if (!isZoomOnWheelEnabled) {
23
- return;
24
- }
25
- instance.updateZoomInteractionListeners('zoomTurnWheel', {
26
- requiredKeys: config.requiredKeys
27
- });
28
- }, [config, isZoomOnWheelEnabled, instance]);
29
-
30
- // Add event for chart zoom in/out
31
- React.useEffect(() => {
32
- const element = chartsLayerContainerRef.current;
33
- if (element === null || !isZoomOnWheelEnabled) {
34
- return () => {};
35
- }
36
- const rafThrottledSetZoomData = rafThrottle(setZoomDataCallback);
37
- const zoomOnWheelHandler = instance.addInteractionListener('zoomTurnWheel', event => {
38
- const point = getChartPoint(element, {
39
- clientX: event.detail.centroid.x,
40
- clientY: event.detail.centroid.y
41
- });
42
-
43
- // This prevents a zoom event from being triggered when the mouse is outside the chart area.
44
- // The timeout is used to prevent a weird behavior where if the mouse is outside but enters due to
45
- // scrolling, then the zoom event is triggered.
46
- if (startedOutsideRef.current || !instance.isPointInside(point.x, point.y)) {
47
- startedOutsideRef.current = true;
48
- if (startedOutsideTimeoutRef.current) {
49
- clearTimeout(startedOutsideTimeoutRef.current);
50
- }
51
- startedOutsideTimeoutRef.current = setTimeout(() => {
52
- startedOutsideRef.current = false;
53
- startedOutsideTimeoutRef.current = null;
54
- }, 100);
55
- return;
56
- }
57
- event.detail.srcEvent.preventDefault();
58
- rafThrottledSetZoomData(prev => {
15
+ useWheelGesture(instance, {
16
+ enabled: isZoomOnWheelEnabled,
17
+ requiredKeys: config?.requiredKeys,
18
+ onWheel: (point, wheelEvent) => {
19
+ setZoomDataCallback(prev => {
59
20
  return prev.map(zoom => {
60
21
  const option = optionsLookup[zoom.axisId];
61
22
  if (!option) {
@@ -65,7 +26,7 @@ export const useZoomOnWheel = ({
65
26
  const {
66
27
  scaleRatio,
67
28
  isZoomIn
68
- } = getWheelScaleRatio(event.detail.srcEvent, option.step);
29
+ } = getWheelScaleRatio(wheelEvent, option.step);
69
30
  const [newMinRange, newMaxRange] = zoomAtPoint(centerRatio, scaleRatio, zoom, option);
70
31
  if (!isSpanValid(newMinRange, newMaxRange, isZoomIn, option)) {
71
32
  return zoom;
@@ -77,15 +38,6 @@ export const useZoomOnWheel = ({
77
38
  };
78
39
  });
79
40
  });
80
- });
81
- return () => {
82
- zoomOnWheelHandler.cleanup();
83
- if (startedOutsideTimeoutRef.current) {
84
- clearTimeout(startedOutsideTimeoutRef.current);
85
- startedOutsideTimeoutRef.current = null;
86
- }
87
- startedOutsideRef.current = false;
88
- rafThrottledSetZoomData.clear();
89
- };
90
- }, [chartsLayerContainerRef, drawingArea, isZoomOnWheelEnabled, optionsLookup, instance, setZoomDataCallback, store]);
41
+ }
42
+ });
91
43
  };
@@ -27,6 +27,7 @@ var _useZoomOnBrush = require("./gestureHooks/useZoomOnBrush");
27
27
  var _useZoomOnDoubleTapReset = require("./gestureHooks/useZoomOnDoubleTapReset");
28
28
  var _initializeZoomInteractionConfig = require("./initializeZoomInteractionConfig");
29
29
  var _initializeZoomData = require("./initializeZoomData");
30
+ var _useRegisterZoomGestures = require("./gestureHooks/useRegisterZoomGestures");
30
31
  /**
31
32
  * Type guard for `initialZoom` entries provided as a range value.
32
33
  */
@@ -193,6 +194,7 @@ const useChartProZoom = pluginData => {
193
194
  }, [removeIsInteracting]);
194
195
 
195
196
  // Add events
197
+ (0, _useRegisterZoomGestures.useRegisterZoomGestures)(pluginData);
196
198
  (0, _usePanOnDrag.usePanOnDrag)(pluginData, setZoomDataCallback);
197
199
  (0, _usePanOnPressAndDrag.usePanOnPressAndDrag)(pluginData, setZoomDataCallback);
198
200
  (0, _usePanOnWheel.usePanOnWheel)(pluginData, setZoomDataCallback);
@@ -20,6 +20,7 @@ import { useZoomOnBrush } from "./gestureHooks/useZoomOnBrush.mjs";
20
20
  import { useZoomOnDoubleTapReset } from "./gestureHooks/useZoomOnDoubleTapReset.mjs";
21
21
  import { initializeZoomInteractionConfig } from "./initializeZoomInteractionConfig.mjs";
22
22
  import { initializeZoomData } from "./initializeZoomData.mjs";
23
+ import { useRegisterZoomGestures } from "./gestureHooks/useRegisterZoomGestures.mjs";
23
24
 
24
25
  /**
25
26
  * Type guard for `initialZoom` entries provided as a range value.
@@ -187,6 +188,7 @@ export const useChartProZoom = pluginData => {
187
188
  }, [removeIsInteracting]);
188
189
 
189
190
  // Add events
191
+ useRegisterZoomGestures(pluginData);
190
192
  usePanOnDrag(pluginData, setZoomDataCallback);
191
193
  usePanOnPressAndDrag(pluginData, setZoomDataCallback);
192
194
  usePanOnWheel(pluginData, setZoomDataCallback);
@@ -0,0 +1,5 @@
1
+ export { useDragGesture, type UseDragGestureOptions } from "./useDragGesture.mjs";
2
+ export { useDragOnPressGesture, type UseDragOnPressGestureOptions } from "./useDragOnPressGesture.mjs";
3
+ export { useWheelGesture, type UseWheelGestureOptions } from "./useWheelGesture.mjs";
4
+ export { usePinchGesture, type UsePinchGestureOptions } from "./usePinchGesture.mjs";
5
+ export type { GestureInstance, PanGestureConfig, ChartPoint } from "./zoomGestures.types.mjs";
@@ -0,0 +1,5 @@
1
+ export { useDragGesture, type UseDragGestureOptions } from "./useDragGesture.js";
2
+ export { useDragOnPressGesture, type UseDragOnPressGestureOptions } from "./useDragOnPressGesture.js";
3
+ export { useWheelGesture, type UseWheelGestureOptions } from "./useWheelGesture.js";
4
+ export { usePinchGesture, type UsePinchGestureOptions } from "./usePinchGesture.js";
5
+ export type { GestureInstance, PanGestureConfig, ChartPoint } from "./zoomGestures.types.js";
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useDragGesture", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _useDragGesture.useDragGesture;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "useDragOnPressGesture", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _useDragOnPressGesture.useDragOnPressGesture;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "usePinchGesture", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _usePinchGesture.usePinchGesture;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useWheelGesture", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _useWheelGesture.useWheelGesture;
28
+ }
29
+ });
30
+ var _useDragGesture = require("./useDragGesture");
31
+ var _useDragOnPressGesture = require("./useDragOnPressGesture");
32
+ var _useWheelGesture = require("./useWheelGesture");
33
+ var _usePinchGesture = require("./usePinchGesture");
@@ -0,0 +1,4 @@
1
+ export { useDragGesture } from "./useDragGesture.mjs";
2
+ export { useDragOnPressGesture } from "./useDragOnPressGesture.mjs";
3
+ export { useWheelGesture } from "./useWheelGesture.mjs";
4
+ export { usePinchGesture } from "./usePinchGesture.mjs";
@@ -0,0 +1,30 @@
1
+ import { type PanEvent } from '@mui/x-internal-gestures/core';
2
+ import { type ChartPoint, type GestureInstance, type PanGestureConfig } from "./zoomGestures.types.mjs";
3
+ export interface UseDragGestureOptions {
4
+ /** Whether the gesture is active. */
5
+ enabled: boolean;
6
+ /** Pointer and keyboard gating for the gesture. */
7
+ config?: PanGestureConfig;
8
+ /**
9
+ * Called when the drag starts.
10
+ * @param {PanEvent} event The pan start event.
11
+ */
12
+ onPanStart?: (event: PanEvent) => void;
13
+ /**
14
+ * Called (rAF-throttled) on each drag update.
15
+ * @param {ChartPoint} delta The pixel delta since the last call.
16
+ * @param {PanEvent} event The pan event.
17
+ */
18
+ onPan: (delta: ChartPoint, event: PanEvent) => void;
19
+ /**
20
+ * Called when the drag ends.
21
+ * @param {PanEvent} event The pan end event.
22
+ */
23
+ onPanEnd?: (event: PanEvent) => void;
24
+ }
25
+ /**
26
+ * Generic drag-to-pan gesture binding.
27
+ *
28
+ * It owns the listener lifecycle, and lets you create your own interactions by providing the delta change of the interaction.
29
+ */
30
+ export declare function useDragGesture(instance: GestureInstance, options: UseDragGestureOptions): void;
@@ -0,0 +1,30 @@
1
+ import { type PanEvent } from '@mui/x-internal-gestures/core';
2
+ import { type ChartPoint, type GestureInstance, type PanGestureConfig } from "./zoomGestures.types.js";
3
+ export interface UseDragGestureOptions {
4
+ /** Whether the gesture is active. */
5
+ enabled: boolean;
6
+ /** Pointer and keyboard gating for the gesture. */
7
+ config?: PanGestureConfig;
8
+ /**
9
+ * Called when the drag starts.
10
+ * @param {PanEvent} event The pan start event.
11
+ */
12
+ onPanStart?: (event: PanEvent) => void;
13
+ /**
14
+ * Called (rAF-throttled) on each drag update.
15
+ * @param {ChartPoint} delta The pixel delta since the last call.
16
+ * @param {PanEvent} event The pan event.
17
+ */
18
+ onPan: (delta: ChartPoint, event: PanEvent) => void;
19
+ /**
20
+ * Called when the drag ends.
21
+ * @param {PanEvent} event The pan end event.
22
+ */
23
+ onPanEnd?: (event: PanEvent) => void;
24
+ }
25
+ /**
26
+ * Generic drag-to-pan gesture binding.
27
+ *
28
+ * It owns the listener lifecycle, and lets you create your own interactions by providing the delta change of the interaction.
29
+ */
30
+ export declare function useDragGesture(instance: GestureInstance, options: UseDragGestureOptions): void;
@@ -0,0 +1,105 @@
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.useDragGesture = useDragGesture;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _rafThrottle = require("@mui/x-internals/rafThrottle");
11
+ /**
12
+ * Generic drag-to-pan gesture binding.
13
+ *
14
+ * It owns the listener lifecycle, and lets you create your own interactions by providing the delta change of the interaction.
15
+ */
16
+ function useDragGesture(instance, options) {
17
+ const {
18
+ enabled,
19
+ config,
20
+ onPanStart,
21
+ onPan,
22
+ onPanEnd
23
+ } = options;
24
+ const {
25
+ chartsLayerContainerRef
26
+ } = instance;
27
+
28
+ // Keep the latest handlers in a ref so changing them doesn't rebind listeners.
29
+ const handlersRef = React.useRef({
30
+ onPanStart,
31
+ onPan,
32
+ onPanEnd
33
+ });
34
+ React.useEffect(() => {
35
+ handlersRef.current = {
36
+ onPanStart,
37
+ onPan,
38
+ onPanEnd
39
+ };
40
+ });
41
+ React.useEffect(() => {
42
+ if (!enabled) {
43
+ return;
44
+ }
45
+ instance.updateZoomInteractionListeners('zoomPan', {
46
+ requiredKeys: config?.requiredKeys,
47
+ pointerMode: config?.pointerMode,
48
+ pointerOptions: {
49
+ mouse: config?.mouse,
50
+ touch: config?.touch
51
+ }
52
+ });
53
+ }, [enabled, config, instance]);
54
+ React.useEffect(() => {
55
+ const element = chartsLayerContainerRef.current;
56
+ if (element === null || !enabled) {
57
+ return () => {};
58
+ }
59
+ let isInteracting = false;
60
+ let lastEvent = null;
61
+ const accumulated = {
62
+ x: 0,
63
+ y: 0
64
+ };
65
+ const handlePanStart = event => {
66
+ if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
67
+ isInteracting = true;
68
+ handlersRef.current.onPanStart?.(event);
69
+ }
70
+ };
71
+ const handlePanEnd = event => {
72
+ isInteracting = false;
73
+ handlersRef.current.onPanEnd?.(event);
74
+ };
75
+ const throttled = (0, _rafThrottle.rafThrottle)(() => {
76
+ const delta = {
77
+ x: accumulated.x,
78
+ y: accumulated.y
79
+ };
80
+ accumulated.x = 0;
81
+ accumulated.y = 0;
82
+ if (lastEvent) {
83
+ handlersRef.current.onPan(delta, lastEvent);
84
+ }
85
+ });
86
+ const handlePan = event => {
87
+ if (!isInteracting) {
88
+ return;
89
+ }
90
+ lastEvent = event;
91
+ accumulated.x += event.detail.deltaX;
92
+ accumulated.y += event.detail.deltaY;
93
+ throttled();
94
+ };
95
+ const panHandler = instance.addInteractionListener('zoomPan', handlePan);
96
+ const panStartHandler = instance.addInteractionListener('zoomPanStart', handlePanStart);
97
+ const panEndHandler = instance.addInteractionListener('zoomPanEnd', handlePanEnd);
98
+ return () => {
99
+ panHandler.cleanup();
100
+ panStartHandler.cleanup();
101
+ panEndHandler.cleanup();
102
+ throttled.clear();
103
+ };
104
+ }, [instance, chartsLayerContainerRef, enabled]);
105
+ }