@mui/x-charts-pro 9.4.0 → 9.5.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 (74) hide show
  1. package/BarChartPro/BarChartPro.js +1 -1
  2. package/BarChartPro/BarChartPro.mjs +2 -2
  3. package/CHANGELOG.md +100 -0
  4. package/ChartsDataProviderPro/ChartsDataProviderPro.js +2 -2
  5. package/ChartsDataProviderPro/ChartsDataProviderPro.mjs +2 -2
  6. package/FunnelChart/funnel.types.d.mts +1 -1
  7. package/FunnelChart/funnel.types.d.ts +1 -1
  8. package/LineChartPro/LineChartPro.js +1 -1
  9. package/LineChartPro/LineChartPro.mjs +2 -2
  10. package/PieChartPro/PieChartPro.js +1 -1
  11. package/PieChartPro/PieChartPro.mjs +2 -2
  12. package/RadarChartPro/RadarChartPro.js +1 -1
  13. package/RadarChartPro/RadarChartPro.mjs +2 -2
  14. package/ScatterChartPro/ScatterChartPro.js +8 -4
  15. package/ScatterChartPro/ScatterChartPro.mjs +9 -5
  16. package/ScatterChartPro/ScatterChartPro.plugins.d.mts +2 -2
  17. package/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -2
  18. package/ScatterChartPro/ScatterChartPro.plugins.js +1 -1
  19. package/ScatterChartPro/ScatterChartPro.plugins.mjs +2 -2
  20. package/index.js +1 -1
  21. package/index.mjs +1 -1
  22. package/internals/plugins/allPlugins.d.mts +5 -5
  23. package/internals/plugins/allPlugins.d.ts +5 -5
  24. package/internals/plugins/allPlugins.js +2 -2
  25. package/internals/plugins/allPlugins.mjs +3 -3
  26. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.mts +36 -4
  27. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +36 -4
  28. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.js +2 -4
  29. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.mjs +1 -3
  30. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.mts +11 -11
  31. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +11 -11
  32. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.mts +0 -1
  33. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.ts +0 -1
  34. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +9 -65
  35. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.mjs +9 -64
  36. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.mts +0 -1
  37. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.ts +0 -1
  38. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.js +9 -69
  39. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.mjs +9 -68
  40. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.mts +0 -1
  41. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.ts +0 -1
  42. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +9 -39
  43. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.mjs +10 -39
  44. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.mts +0 -1
  45. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.ts +0 -1
  46. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +9 -58
  47. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.mjs +10 -58
  48. package/internals/plugins/zoomGestures/index.d.mts +5 -0
  49. package/internals/plugins/zoomGestures/index.d.ts +5 -0
  50. package/internals/plugins/zoomGestures/index.js +33 -0
  51. package/internals/plugins/zoomGestures/index.mjs +4 -0
  52. package/internals/plugins/zoomGestures/useDragGesture.d.mts +30 -0
  53. package/internals/plugins/zoomGestures/useDragGesture.d.ts +30 -0
  54. package/internals/plugins/zoomGestures/useDragGesture.js +105 -0
  55. package/internals/plugins/zoomGestures/useDragGesture.mjs +99 -0
  56. package/internals/plugins/zoomGestures/useDragOnPressGesture.d.mts +30 -0
  57. package/internals/plugins/zoomGestures/useDragOnPressGesture.d.ts +30 -0
  58. package/internals/plugins/zoomGestures/useDragOnPressGesture.js +105 -0
  59. package/internals/plugins/zoomGestures/useDragOnPressGesture.mjs +99 -0
  60. package/internals/plugins/zoomGestures/usePinchGesture.d.mts +22 -0
  61. package/internals/plugins/zoomGestures/usePinchGesture.d.ts +22 -0
  62. package/internals/plugins/zoomGestures/usePinchGesture.js +77 -0
  63. package/internals/plugins/zoomGestures/usePinchGesture.mjs +71 -0
  64. package/internals/plugins/zoomGestures/useWheelGesture.d.mts +21 -0
  65. package/internals/plugins/zoomGestures/useWheelGesture.d.ts +21 -0
  66. package/internals/plugins/zoomGestures/useWheelGesture.js +78 -0
  67. package/internals/plugins/zoomGestures/useWheelGesture.mjs +72 -0
  68. package/internals/plugins/zoomGestures/zoomGestures.types.d.mts +29 -0
  69. package/internals/plugins/zoomGestures/zoomGestures.types.d.ts +29 -0
  70. package/internals/plugins/zoomGestures/zoomGestures.types.js +5 -0
  71. package/internals/plugins/zoomGestures/zoomGestures.types.mjs +1 -0
  72. package/models/seriesType/heatmap.d.mts +1 -1
  73. package/models/seriesType/heatmap.d.ts +1 -1
  74. package/package.json +3 -3
@@ -1,6 +1,26 @@
1
1
  export declare const selectorZoomInteractionConfig: (args_0: import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeriesConfig/useChartSeriesConfig.types").UseChartSeriesConfigState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types").UseChartExperimentalFeaturesState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & import("./useChartProZoom.types.js").UseChartProZoomState & Partial<{}> & {
2
2
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
3
- }, interactionName: "wheel" | "pinch" | "tapAndDrag" | "doubleTapReset" | "brush") => (Omit<import("./ZoomInteractionConfig.types.js").ZoomInteraction, "pointerMode"> & {
3
+ }, interactionName: "wheel" | "pinch" | "tapAndDrag" | "doubleTapReset" | "brush") => (Omit<{
4
+ type: "wheel";
5
+ pointerMode?: any;
6
+ requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
7
+ } | {
8
+ type: "pinch";
9
+ pointerMode?: any;
10
+ requiredKeys?: any[] | undefined;
11
+ } | {
12
+ type: "tapAndDrag";
13
+ pointerMode?: ("mouse" | "touch") | undefined;
14
+ requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
15
+ } | {
16
+ type: "doubleTapReset";
17
+ pointerMode?: ("mouse" | "touch") | undefined;
18
+ requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
19
+ } | {
20
+ type: "brush";
21
+ pointerMode?: ("mouse" | "touch") | undefined;
22
+ requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
23
+ }, "pointerMode"> & {
4
24
  mouse: {
5
25
  requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
6
26
  };
@@ -12,7 +32,20 @@ export declare const selectorZoomInteractionConfig: (args_0: import("@mui/x-char
12
32
  }) | null;
13
33
  export declare const selectorPanInteractionConfig: (args_0: import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeriesConfig/useChartSeriesConfig.types").UseChartSeriesConfigState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types").UseChartExperimentalFeaturesState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & import("./useChartProZoom.types.js").UseChartProZoomState & Partial<{}> & {
14
34
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
15
- }, interactionName: "wheel" | "drag" | "pressAndDrag") => (Omit<import("./ZoomInteractionConfig.types.js").PanInteraction, "pointerMode"> & {
35
+ }, interactionName: "wheel" | "drag" | "pressAndDrag") => (Omit<{
36
+ type: "drag";
37
+ pointerMode?: ("mouse" | "touch") | undefined;
38
+ requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
39
+ } | {
40
+ type: "pressAndDrag";
41
+ pointerMode?: ("mouse" | "touch") | undefined;
42
+ requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
43
+ } | {
44
+ type: "wheel";
45
+ allowedDirection?: "x" | "y" | "xy" | undefined;
46
+ pointerMode?: any;
47
+ requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
48
+ }, "pointerMode"> & {
16
49
  mouse: {
17
50
  requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
18
51
  };
@@ -21,5 +54,4 @@ export declare const selectorPanInteractionConfig: (args_0: import("@mui/x-chart
21
54
  };
22
55
  pointerMode?: import("@mui/x-internal-gestures/core").PointerMode[];
23
56
  allowedDirection?: "x" | "y" | "xy";
24
- }) | null;
25
- export declare const selectorIsZoomBrushEnabled: (args_0: {}, zoomInteractionConfig: any) => any;
57
+ }) | null;
@@ -3,10 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.selectorZoomInteractionConfig = exports.selectorPanInteractionConfig = exports.selectorIsZoomBrushEnabled = void 0;
6
+ exports.selectorZoomInteractionConfig = exports.selectorPanInteractionConfig = void 0;
7
7
  var _store = require("@mui/x-internals/store");
8
- var _internals = require("@mui/x-charts/internals");
9
8
  var _useChartProZoom = require("./useChartProZoom.selectors");
10
9
  const selectorZoomInteractionConfig = exports.selectorZoomInteractionConfig = (0, _store.createSelector)(_useChartProZoom.selectorChartZoomState, (zoomState, interactionName) => zoomState.zoomInteractionConfig.zoom[interactionName] ?? null);
11
- const selectorPanInteractionConfig = exports.selectorPanInteractionConfig = (0, _store.createSelector)(_useChartProZoom.selectorChartZoomState, (zoomState, interactionName) => zoomState.zoomInteractionConfig.pan[interactionName] ?? null);
12
- const selectorIsZoomBrushEnabled = exports.selectorIsZoomBrushEnabled = (0, _store.createSelector)(_internals.selectorChartZoomOptionsLookup, state => selectorZoomInteractionConfig(state, 'brush'), (zoomOptions, zoomInteractionConfig) => Object.keys(zoomOptions).length > 0 && zoomInteractionConfig || false);
10
+ const selectorPanInteractionConfig = exports.selectorPanInteractionConfig = (0, _store.createSelector)(_useChartProZoom.selectorChartZoomState, (zoomState, interactionName) => zoomState.zoomInteractionConfig.pan[interactionName] ?? null);
@@ -1,6 +1,4 @@
1
1
  import { createSelector } from '@mui/x-internals/store';
2
- import { selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
3
2
  import { selectorChartZoomState } from "./useChartProZoom.selectors.mjs";
4
3
  export const selectorZoomInteractionConfig = createSelector(selectorChartZoomState, (zoomState, interactionName) => zoomState.zoomInteractionConfig.zoom[interactionName] ?? null);
5
- export const selectorPanInteractionConfig = createSelector(selectorChartZoomState, (zoomState, interactionName) => zoomState.zoomInteractionConfig.pan[interactionName] ?? null);
6
- export const selectorIsZoomBrushEnabled = createSelector(selectorChartZoomOptionsLookup, state => selectorZoomInteractionConfig(state, 'brush'), (zoomOptions, zoomInteractionConfig) => Object.keys(zoomOptions).length > 0 && zoomInteractionConfig || false);
4
+ export const selectorPanInteractionConfig = createSelector(selectorChartZoomState, (zoomState, interactionName) => zoomState.zoomInteractionConfig.pan[interactionName] ?? null);
@@ -35,11 +35,11 @@ export type DefaultizedZoomInteractionConfig = {
35
35
  zoom: Entry<ZoomInteraction>;
36
36
  pan: Entry<PanInteraction>;
37
37
  };
38
- export type ZoomInteraction = WheelInteraction | PinchInteraction | TapAndDragInteraction | DoubleTapResetInteraction | BrushInteraction;
39
- export type PanInteraction = DragInteraction | PressAndDragInteraction | WheelPanInteraction;
38
+ type ZoomInteraction = WheelInteraction | PinchInteraction | TapAndDragInteraction | DoubleTapResetInteraction | BrushInteraction;
39
+ type PanInteraction = DragInteraction | PressAndDragInteraction | WheelPanInteraction;
40
40
  export type ZoomInteractionName = ZoomInteraction['type'];
41
41
  export type PanInteractionName = PanInteraction['type'];
42
- export type InteractionMode = Exclude<PointerMode, 'pen'>;
42
+ type InteractionMode = Exclude<PointerMode, 'pen'>;
43
43
  type AllKeysProp = {
44
44
  /**
45
45
  * The keys that must be pressed to trigger the interaction.
@@ -68,22 +68,22 @@ type NoModeProp = {
68
68
  pointerMode?: any;
69
69
  };
70
70
  type Unpack<T> = { [K in keyof T]: T[K] extends object ? Unpack<T[K]> : T[K] };
71
- export type WheelInteraction = Unpack<{
71
+ type WheelInteraction = Unpack<{
72
72
  type: 'wheel';
73
73
  } & NoModeProp & AllKeysProp>;
74
- export type PinchInteraction = Unpack<{
74
+ type PinchInteraction = Unpack<{
75
75
  type: 'pinch';
76
76
  } & NoModeProp & NoKeysProp>;
77
- export type DragInteraction = Unpack<{
77
+ type DragInteraction = Unpack<{
78
78
  type: 'drag';
79
79
  } & AllModeProp & AllKeysProp>;
80
- export type TapAndDragInteraction = Unpack<{
80
+ type TapAndDragInteraction = Unpack<{
81
81
  type: 'tapAndDrag';
82
82
  } & AllModeProp & AllKeysProp>;
83
- export type PressAndDragInteraction = Unpack<{
83
+ type PressAndDragInteraction = Unpack<{
84
84
  type: 'pressAndDrag';
85
85
  } & AllModeProp & AllKeysProp>;
86
- export type WheelPanInteraction = Unpack<{
86
+ type WheelPanInteraction = Unpack<{
87
87
  type: 'wheel';
88
88
  /**
89
89
  * Defines which axes are affected by pan on wheel.
@@ -94,10 +94,10 @@ export type WheelPanInteraction = Unpack<{
94
94
  */
95
95
  allowedDirection?: 'x' | 'y' | 'xy';
96
96
  } & NoModeProp & AllKeysProp>;
97
- export type DoubleTapResetInteraction = Unpack<{
97
+ type DoubleTapResetInteraction = Unpack<{
98
98
  type: 'doubleTapReset';
99
99
  } & AllModeProp & AllKeysProp>;
100
- export type BrushInteraction = Unpack<{
100
+ type BrushInteraction = Unpack<{
101
101
  type: 'brush';
102
102
  } & AllModeProp & AllKeysProp>;
103
103
  export type AnyInteraction = {
@@ -35,11 +35,11 @@ export type DefaultizedZoomInteractionConfig = {
35
35
  zoom: Entry<ZoomInteraction>;
36
36
  pan: Entry<PanInteraction>;
37
37
  };
38
- export type ZoomInteraction = WheelInteraction | PinchInteraction | TapAndDragInteraction | DoubleTapResetInteraction | BrushInteraction;
39
- export type PanInteraction = DragInteraction | PressAndDragInteraction | WheelPanInteraction;
38
+ type ZoomInteraction = WheelInteraction | PinchInteraction | TapAndDragInteraction | DoubleTapResetInteraction | BrushInteraction;
39
+ type PanInteraction = DragInteraction | PressAndDragInteraction | WheelPanInteraction;
40
40
  export type ZoomInteractionName = ZoomInteraction['type'];
41
41
  export type PanInteractionName = PanInteraction['type'];
42
- export type InteractionMode = Exclude<PointerMode, 'pen'>;
42
+ type InteractionMode = Exclude<PointerMode, 'pen'>;
43
43
  type AllKeysProp = {
44
44
  /**
45
45
  * The keys that must be pressed to trigger the interaction.
@@ -68,22 +68,22 @@ type NoModeProp = {
68
68
  pointerMode?: any;
69
69
  };
70
70
  type Unpack<T> = { [K in keyof T]: T[K] extends object ? Unpack<T[K]> : T[K] };
71
- export type WheelInteraction = Unpack<{
71
+ type WheelInteraction = Unpack<{
72
72
  type: 'wheel';
73
73
  } & NoModeProp & AllKeysProp>;
74
- export type PinchInteraction = Unpack<{
74
+ type PinchInteraction = Unpack<{
75
75
  type: 'pinch';
76
76
  } & NoModeProp & NoKeysProp>;
77
- export type DragInteraction = Unpack<{
77
+ type DragInteraction = Unpack<{
78
78
  type: 'drag';
79
79
  } & AllModeProp & AllKeysProp>;
80
- export type TapAndDragInteraction = Unpack<{
80
+ type TapAndDragInteraction = Unpack<{
81
81
  type: 'tapAndDrag';
82
82
  } & AllModeProp & AllKeysProp>;
83
- export type PressAndDragInteraction = Unpack<{
83
+ type PressAndDragInteraction = Unpack<{
84
84
  type: 'pressAndDrag';
85
85
  } & AllModeProp & AllKeysProp>;
86
- export type WheelPanInteraction = Unpack<{
86
+ type WheelPanInteraction = Unpack<{
87
87
  type: 'wheel';
88
88
  /**
89
89
  * Defines which axes are affected by pan on wheel.
@@ -94,10 +94,10 @@ export type WheelPanInteraction = Unpack<{
94
94
  */
95
95
  allowedDirection?: 'x' | 'y' | 'xy';
96
96
  } & NoModeProp & AllKeysProp>;
97
- export type DoubleTapResetInteraction = Unpack<{
97
+ type DoubleTapResetInteraction = Unpack<{
98
98
  type: 'doubleTapReset';
99
99
  } & AllModeProp & AllKeysProp>;
100
- export type BrushInteraction = Unpack<{
100
+ type BrushInteraction = Unpack<{
101
101
  type: 'brush';
102
102
  } & AllModeProp & AllKeysProp>;
103
103
  export type AnyInteraction = {
@@ -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 usePanOnDrag: ({
@@ -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 usePanOnDrag: ({
@@ -1,90 +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.usePanOnDrag = 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 _useDragGesture = require("../../zoomGestures/useDragGesture");
14
12
  const usePanOnDrag = ({
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.selectorPanInteractionConfig, 'drag');
24
19
  const isPanOnDragEnabled = Object.values(optionsLookup).some(v => v.panning) && Boolean(config);
25
- React.useEffect(() => {
26
- if (!isPanOnDragEnabled) {
27
- return;
28
- }
29
- instance.updateZoomInteractionListeners('zoomPan', {
30
- requiredKeys: config.requiredKeys,
31
- pointerMode: config.pointerMode,
32
- pointerOptions: {
33
- mouse: config.mouse,
34
- touch: config.touch
35
- }
36
- });
37
- }, [isPanOnDragEnabled, config, instance]);
38
-
39
- // Add event for chart panning
40
- React.useEffect(() => {
41
- const element = chartsLayerContainerRef.current;
42
- let isInteracting = false;
43
- const accumulatedChange = {
44
- x: 0,
45
- y: 0
46
- };
47
- if (element === null || !isPanOnDragEnabled) {
48
- return () => {};
49
- }
50
- const handlePanStart = event => {
51
- if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
52
- isInteracting = true;
53
- }
54
- };
55
- const handlePanEnd = () => {
56
- isInteracting = false;
57
- };
58
- const throttledCallback = (0, _rafThrottle.rafThrottle)(() => {
59
- const x = accumulatedChange.x;
60
- const y = accumulatedChange.y;
61
- accumulatedChange.x = 0;
62
- accumulatedChange.y = 0;
20
+ (0, _useDragGesture.useDragGesture)(instance, {
21
+ config: config ?? undefined,
22
+ enabled: isPanOnDragEnabled,
23
+ onPan: delta => {
63
24
  setZoomDataCallback(prev => (0, _useZoom.translateZoom)(prev, {
64
- x,
65
- y: -y
25
+ x: delta.x,
26
+ y: -delta.y
66
27
  }, {
67
28
  width: drawingArea.width,
68
29
  height: drawingArea.height
69
30
  }, optionsLookup));
70
- });
71
- const handlePan = event => {
72
- if (!isInteracting) {
73
- return;
74
- }
75
- accumulatedChange.x += event.detail.deltaX;
76
- accumulatedChange.y += event.detail.deltaY;
77
- throttledCallback();
78
- };
79
- const panHandler = instance.addInteractionListener('zoomPan', handlePan);
80
- const panStartHandler = instance.addInteractionListener('zoomPanStart', handlePanStart);
81
- const panEndHandler = instance.addInteractionListener('zoomPanEnd', handlePanEnd);
82
- return () => {
83
- panStartHandler.cleanup();
84
- panHandler.cleanup();
85
- panEndHandler.cleanup();
86
- throttledCallback.clear();
87
- };
88
- }, [instance, chartsLayerContainerRef, isPanOnDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store]);
31
+ }
32
+ });
89
33
  };
90
34
  exports.usePanOnDrag = usePanOnDrag;
@@ -1,83 +1,28 @@
1
1
  'use client';
2
2
 
3
- import * as React from 'react';
4
3
  import { selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
5
- import { rafThrottle } from '@mui/x-internals/rafThrottle';
6
4
  import { translateZoom } from "./useZoom.utils.mjs";
7
5
  import { selectorPanInteractionConfig } from "../ZoomInteractionConfig.selectors.mjs";
6
+ import { useDragGesture } from "../../zoomGestures/useDragGesture.mjs";
8
7
  export const usePanOnDrag = ({
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(selectorPanInteractionConfig, 'drag');
18
14
  const isPanOnDragEnabled = Object.values(optionsLookup).some(v => v.panning) && Boolean(config);
19
- React.useEffect(() => {
20
- if (!isPanOnDragEnabled) {
21
- return;
22
- }
23
- instance.updateZoomInteractionListeners('zoomPan', {
24
- requiredKeys: config.requiredKeys,
25
- pointerMode: config.pointerMode,
26
- pointerOptions: {
27
- mouse: config.mouse,
28
- touch: config.touch
29
- }
30
- });
31
- }, [isPanOnDragEnabled, config, instance]);
32
-
33
- // Add event for chart panning
34
- React.useEffect(() => {
35
- const element = chartsLayerContainerRef.current;
36
- let isInteracting = false;
37
- const accumulatedChange = {
38
- x: 0,
39
- y: 0
40
- };
41
- if (element === null || !isPanOnDragEnabled) {
42
- return () => {};
43
- }
44
- const handlePanStart = event => {
45
- if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
46
- isInteracting = true;
47
- }
48
- };
49
- const handlePanEnd = () => {
50
- isInteracting = false;
51
- };
52
- const throttledCallback = rafThrottle(() => {
53
- const x = accumulatedChange.x;
54
- const y = accumulatedChange.y;
55
- accumulatedChange.x = 0;
56
- accumulatedChange.y = 0;
15
+ useDragGesture(instance, {
16
+ config: config ?? undefined,
17
+ enabled: isPanOnDragEnabled,
18
+ onPan: delta => {
57
19
  setZoomDataCallback(prev => translateZoom(prev, {
58
- x,
59
- y: -y
20
+ x: delta.x,
21
+ y: -delta.y
60
22
  }, {
61
23
  width: drawingArea.width,
62
24
  height: drawingArea.height
63
25
  }, optionsLookup));
64
- });
65
- const handlePan = event => {
66
- if (!isInteracting) {
67
- return;
68
- }
69
- accumulatedChange.x += event.detail.deltaX;
70
- accumulatedChange.y += event.detail.deltaY;
71
- throttledCallback();
72
- };
73
- const panHandler = instance.addInteractionListener('zoomPan', handlePan);
74
- const panStartHandler = instance.addInteractionListener('zoomPanStart', handlePanStart);
75
- const panEndHandler = instance.addInteractionListener('zoomPanEnd', handlePanEnd);
76
- return () => {
77
- panStartHandler.cleanup();
78
- panHandler.cleanup();
79
- panEndHandler.cleanup();
80
- throttledCallback.clear();
81
- };
82
- }, [instance, chartsLayerContainerRef, isPanOnDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store]);
26
+ }
27
+ });
83
28
  };
@@ -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 usePanOnPressAndDrag: ({
@@ -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 usePanOnPressAndDrag: ({
@@ -1,94 +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.usePanOnPressAndDrag = 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 _useDragOnPressGesture = require("../../zoomGestures/useDragOnPressGesture");
14
12
  const usePanOnPressAndDrag = ({
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 isInteracting = React.useRef(false);
24
- const accumulatedChange = React.useRef({
25
- x: 0,
26
- y: 0
27
- });
28
18
  const config = store.use(_ZoomInteractionConfig.selectorPanInteractionConfig, 'pressAndDrag');
29
19
  const isPanOnPressAndDragEnabled = Object.values(optionsLookup).some(v => v.panning) && Boolean(config);
30
- React.useEffect(() => {
31
- if (!isPanOnPressAndDragEnabled) {
32
- return;
33
- }
34
- instance.updateZoomInteractionListeners('zoomPressAndDrag', {
35
- requiredKeys: config.requiredKeys,
36
- pointerMode: config.pointerMode,
37
- pointerOptions: {
38
- mouse: config.mouse,
39
- touch: config.touch
40
- }
41
- });
42
- }, [isPanOnPressAndDragEnabled, config, instance]);
43
-
44
- // Add event for chart panning with press and drag
45
- React.useEffect(() => {
46
- const element = chartsLayerContainerRef.current;
47
- if (element === null || !isPanOnPressAndDragEnabled) {
48
- return () => {};
49
- }
50
- const handlePressAndDragStart = event => {
51
- if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
52
- isInteracting.current = true;
53
- accumulatedChange.current = {
54
- x: 0,
55
- y: 0
56
- };
57
- }
58
- };
59
- const handlePressAndDragEnd = () => {
60
- isInteracting.current = false;
61
- };
62
- const throttledCallback = (0, _rafThrottle.rafThrottle)(() => {
63
- const x = accumulatedChange.current.x;
64
- const y = accumulatedChange.current.y;
65
- accumulatedChange.current.x = 0;
66
- accumulatedChange.current.y = 0;
20
+ (0, _useDragOnPressGesture.useDragOnPressGesture)(instance, {
21
+ config: config ?? undefined,
22
+ enabled: isPanOnPressAndDragEnabled,
23
+ onPan: delta => {
67
24
  setZoomDataCallback(prev => (0, _useZoom.translateZoom)(prev, {
68
- x,
69
- y: -y
25
+ x: delta.x,
26
+ y: -delta.y
70
27
  }, {
71
28
  width: drawingArea.width,
72
29
  height: drawingArea.height
73
30
  }, optionsLookup));
74
- });
75
- const handlePressAndDrag = event => {
76
- if (!isInteracting.current) {
77
- return;
78
- }
79
- accumulatedChange.current.x += event.detail.deltaX;
80
- accumulatedChange.current.y += event.detail.deltaY;
81
- throttledCallback();
82
- };
83
- const pressAndDragHandler = instance.addInteractionListener('zoomPressAndDrag', handlePressAndDrag);
84
- const pressAndDragStartHandler = instance.addInteractionListener('zoomPressAndDragStart', handlePressAndDragStart);
85
- const pressAndDragEndHandler = instance.addInteractionListener('zoomPressAndDragEnd', handlePressAndDragEnd);
86
- return () => {
87
- pressAndDragStartHandler.cleanup();
88
- pressAndDragHandler.cleanup();
89
- pressAndDragEndHandler.cleanup();
90
- throttledCallback.clear();
91
- };
92
- }, [instance, chartsLayerContainerRef, isPanOnPressAndDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, isInteracting]);
31
+ }
32
+ });
93
33
  };
94
34
  exports.usePanOnPressAndDrag = usePanOnPressAndDrag;
@@ -1,87 +1,28 @@
1
1
  'use client';
2
2
 
3
- import * as React from 'react';
4
3
  import { selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
5
- import { rafThrottle } from '@mui/x-internals/rafThrottle';
6
4
  import { translateZoom } from "./useZoom.utils.mjs";
7
5
  import { selectorPanInteractionConfig } from "../ZoomInteractionConfig.selectors.mjs";
6
+ import { useDragOnPressGesture } from "../../zoomGestures/useDragOnPressGesture.mjs";
8
7
  export const usePanOnPressAndDrag = ({
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 isInteracting = React.useRef(false);
18
- const accumulatedChange = React.useRef({
19
- x: 0,
20
- y: 0
21
- });
22
13
  const config = store.use(selectorPanInteractionConfig, 'pressAndDrag');
23
14
  const isPanOnPressAndDragEnabled = Object.values(optionsLookup).some(v => v.panning) && Boolean(config);
24
- React.useEffect(() => {
25
- if (!isPanOnPressAndDragEnabled) {
26
- return;
27
- }
28
- instance.updateZoomInteractionListeners('zoomPressAndDrag', {
29
- requiredKeys: config.requiredKeys,
30
- pointerMode: config.pointerMode,
31
- pointerOptions: {
32
- mouse: config.mouse,
33
- touch: config.touch
34
- }
35
- });
36
- }, [isPanOnPressAndDragEnabled, config, instance]);
37
-
38
- // Add event for chart panning with press and drag
39
- React.useEffect(() => {
40
- const element = chartsLayerContainerRef.current;
41
- if (element === null || !isPanOnPressAndDragEnabled) {
42
- return () => {};
43
- }
44
- const handlePressAndDragStart = event => {
45
- if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
46
- isInteracting.current = true;
47
- accumulatedChange.current = {
48
- x: 0,
49
- y: 0
50
- };
51
- }
52
- };
53
- const handlePressAndDragEnd = () => {
54
- isInteracting.current = false;
55
- };
56
- const throttledCallback = rafThrottle(() => {
57
- const x = accumulatedChange.current.x;
58
- const y = accumulatedChange.current.y;
59
- accumulatedChange.current.x = 0;
60
- accumulatedChange.current.y = 0;
15
+ useDragOnPressGesture(instance, {
16
+ config: config ?? undefined,
17
+ enabled: isPanOnPressAndDragEnabled,
18
+ onPan: delta => {
61
19
  setZoomDataCallback(prev => translateZoom(prev, {
62
- x,
63
- y: -y
20
+ x: delta.x,
21
+ y: -delta.y
64
22
  }, {
65
23
  width: drawingArea.width,
66
24
  height: drawingArea.height
67
25
  }, optionsLookup));
68
- });
69
- const handlePressAndDrag = event => {
70
- if (!isInteracting.current) {
71
- return;
72
- }
73
- accumulatedChange.current.x += event.detail.deltaX;
74
- accumulatedChange.current.y += event.detail.deltaY;
75
- throttledCallback();
76
- };
77
- const pressAndDragHandler = instance.addInteractionListener('zoomPressAndDrag', handlePressAndDrag);
78
- const pressAndDragStartHandler = instance.addInteractionListener('zoomPressAndDragStart', handlePressAndDragStart);
79
- const pressAndDragEndHandler = instance.addInteractionListener('zoomPressAndDragEnd', handlePressAndDragEnd);
80
- return () => {
81
- pressAndDragStartHandler.cleanup();
82
- pressAndDragHandler.cleanup();
83
- pressAndDragEndHandler.cleanup();
84
- throttledCallback.clear();
85
- };
86
- }, [instance, chartsLayerContainerRef, isPanOnPressAndDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, isInteracting]);
26
+ }
27
+ });
87
28
  };
@@ -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 useZoomOnPinch: ({
@@ -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 useZoomOnPinch: ({