@mui/x-charts-pro 8.12.0 → 8.13.1
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.
- package/BarChartPro/BarChartPro.js +24 -1
- package/CHANGELOG.md +207 -0
- package/ChartContainerPro/useChartContainerProProps.js +3 -1
- package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/FunnelChart/funnelAxisPlugin/computeAxisValue.js +1 -4
- package/LineChartPro/LineChartPro.js +24 -1
- package/ScatterChartPro/ScatterChartPro.js +24 -1
- package/esm/BarChartPro/BarChartPro.js +24 -1
- package/esm/ChartContainerPro/useChartContainerProProps.js +3 -1
- package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/esm/FunnelChart/funnelAxisPlugin/computeAxisValue.js +2 -5
- package/esm/LineChartPro/LineChartPro.js +24 -1
- package/esm/ScatterChartPro/ScatterChartPro.js +24 -1
- package/esm/index.js +1 -1
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +22 -0
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.js +4 -0
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +92 -0
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.js +1 -0
- package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +21 -6
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoom.utils.js +1 -1
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +18 -9
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.d.ts +8 -0
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.js +73 -0
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +14 -4
- package/esm/internals/plugins/useChartProZoom/initializeZoomData.d.ts +2 -0
- package/esm/internals/plugins/useChartProZoom/initializeZoomData.js +26 -0
- package/esm/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.d.ts +2 -0
- package/esm/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.js +86 -0
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -2
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +25 -44
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +9 -0
- package/index.js +1 -1
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +22 -0
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.js +10 -0
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +92 -0
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.js +5 -0
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +21 -6
- package/internals/plugins/useChartProZoom/gestureHooks/useZoom.utils.js +1 -1
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +18 -9
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.d.ts +8 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.js +80 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +14 -4
- package/internals/plugins/useChartProZoom/initializeZoomData.d.ts +2 -0
- package/internals/plugins/useChartProZoom/initializeZoomData.js +31 -0
- package/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.d.ts +2 -0
- package/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.js +92 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -2
- package/internals/plugins/useChartProZoom/useChartProZoom.js +26 -45
- package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +9 -0
- package/package.json +6 -6
|
@@ -10,6 +10,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _internals = require("@mui/x-charts/internals");
|
|
11
11
|
var _rafThrottle = require("@mui/x-internals/rafThrottle");
|
|
12
12
|
var _useZoom = require("./useZoom.utils");
|
|
13
|
+
var _ZoomInteractionConfig = require("../ZoomInteractionConfig.selectors");
|
|
13
14
|
const usePanOnDrag = ({
|
|
14
15
|
store,
|
|
15
16
|
instance,
|
|
@@ -18,12 +19,26 @@ const usePanOnDrag = ({
|
|
|
18
19
|
const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
|
|
19
20
|
const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
|
|
20
21
|
const startRef = React.useRef(null);
|
|
22
|
+
const config = (0, _internals.useSelector)(store, _ZoomInteractionConfig.selectorPanInteractionConfig, ['drag']);
|
|
23
|
+
const isPanOnDragEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) && config || false, [optionsLookup, config]);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
if (!isPanOnDragEnabled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
instance.updateZoomInteractionListeners('zoomPan', {
|
|
29
|
+
requiredKeys: config.requiredKeys,
|
|
30
|
+
pointerMode: config.pointerMode,
|
|
31
|
+
pointerOptions: {
|
|
32
|
+
mouse: config.mouse,
|
|
33
|
+
touch: config.touch
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}, [isPanOnDragEnabled, config, instance]);
|
|
21
37
|
|
|
22
38
|
// Add event for chart panning
|
|
23
|
-
const isPanEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) || false, [optionsLookup]);
|
|
24
39
|
React.useEffect(() => {
|
|
25
40
|
const element = svgRef.current;
|
|
26
|
-
if (element === null || !
|
|
41
|
+
if (element === null || !isPanOnDragEnabled) {
|
|
27
42
|
return () => {};
|
|
28
43
|
}
|
|
29
44
|
const handlePanStart = event => {
|
|
@@ -51,15 +66,15 @@ const usePanOnDrag = ({
|
|
|
51
66
|
}
|
|
52
67
|
throttledCallback(event, zoomData);
|
|
53
68
|
};
|
|
54
|
-
const panHandler = instance.addInteractionListener('
|
|
55
|
-
const panStartHandler = instance.addInteractionListener('
|
|
56
|
-
const panEndHandler = instance.addInteractionListener('
|
|
69
|
+
const panHandler = instance.addInteractionListener('zoomPan', handlePan);
|
|
70
|
+
const panStartHandler = instance.addInteractionListener('zoomPanStart', handlePanStart);
|
|
71
|
+
const panEndHandler = instance.addInteractionListener('zoomPanEnd', handlePanEnd);
|
|
57
72
|
return () => {
|
|
58
73
|
panStartHandler.cleanup();
|
|
59
74
|
panHandler.cleanup();
|
|
60
75
|
panEndHandler.cleanup();
|
|
61
76
|
throttledCallback.clear();
|
|
62
77
|
};
|
|
63
|
-
}, [instance, svgRef,
|
|
78
|
+
}, [instance, svgRef, isPanOnDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, startRef]);
|
|
64
79
|
};
|
|
65
80
|
exports.usePanOnDrag = usePanOnDrag;
|
|
@@ -52,7 +52,7 @@ const zoomAtPoint = (centerRatio, scaleRatio, currentZoomData, options) => {
|
|
|
52
52
|
exports.zoomAtPoint = zoomAtPoint;
|
|
53
53
|
function isSpanValid(minRange, maxRange, isZoomIn, option) {
|
|
54
54
|
const newSpanPercent = maxRange - minRange;
|
|
55
|
-
if (isZoomIn && newSpanPercent < option.minSpan || !isZoomIn && newSpanPercent > option.maxSpan) {
|
|
55
|
+
if (newSpanPercent < 0 || isZoomIn && newSpanPercent < option.minSpan || !isZoomIn && newSpanPercent > option.maxSpan) {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
if (minRange < option.minStart || maxRange > option.maxEnd) {
|
|
@@ -10,6 +10,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _internals = require("@mui/x-charts/internals");
|
|
11
11
|
var _rafThrottle = require("@mui/x-internals/rafThrottle");
|
|
12
12
|
var _useZoom = require("./useZoom.utils");
|
|
13
|
+
var _ZoomInteractionConfig = require("../ZoomInteractionConfig.selectors");
|
|
13
14
|
const useZoomOnPinch = ({
|
|
14
15
|
store,
|
|
15
16
|
instance,
|
|
@@ -17,15 +18,28 @@ const useZoomOnPinch = ({
|
|
|
17
18
|
}, setZoomDataCallback) => {
|
|
18
19
|
const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
|
|
19
20
|
const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
|
|
20
|
-
const
|
|
21
|
+
const config = (0, _internals.useSelector)(store, _ZoomInteractionConfig.selectorZoomInteractionConfig, ['pinch']);
|
|
22
|
+
const isZoomOnPinchEnabled = React.useMemo(() => Object.keys(optionsLookup).length > 0 && config || false, [optionsLookup, config]);
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
if (!isZoomOnPinchEnabled) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
instance.updateZoomInteractionListeners('zoomPinch', {
|
|
28
|
+
requiredKeys: config.requiredKeys
|
|
29
|
+
});
|
|
30
|
+
}, [config, isZoomOnPinchEnabled, instance]);
|
|
21
31
|
|
|
22
32
|
// Zoom on pinch
|
|
23
33
|
React.useEffect(() => {
|
|
24
34
|
const element = svgRef.current;
|
|
25
|
-
if (element === null || !
|
|
35
|
+
if (element === null || !isZoomOnPinchEnabled) {
|
|
26
36
|
return () => {};
|
|
27
37
|
}
|
|
28
38
|
const rafThrottledCallback = (0, _rafThrottle.rafThrottle)(event => {
|
|
39
|
+
// If the delta is 0, it means the pinch gesture is not valid.
|
|
40
|
+
if (event.detail.direction === 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
29
43
|
setZoomDataCallback(prev => {
|
|
30
44
|
return prev.map(zoom => {
|
|
31
45
|
const option = optionsLookup[zoom.axisId];
|
|
@@ -34,11 +48,6 @@ const useZoomOnPinch = ({
|
|
|
34
48
|
}
|
|
35
49
|
const isZoomIn = event.detail.direction > 0;
|
|
36
50
|
const scaleRatio = 1 + event.detail.deltaScale;
|
|
37
|
-
|
|
38
|
-
// If the delta is 0, it means the pinch gesture is not valid.
|
|
39
|
-
if (event.detail.direction === 0) {
|
|
40
|
-
return zoom;
|
|
41
|
-
}
|
|
42
51
|
const point = (0, _internals.getSVGPoint)(element, {
|
|
43
52
|
clientX: event.detail.centroid.x,
|
|
44
53
|
clientY: event.detail.centroid.y
|
|
@@ -56,11 +65,11 @@ const useZoomOnPinch = ({
|
|
|
56
65
|
});
|
|
57
66
|
});
|
|
58
67
|
});
|
|
59
|
-
const zoomHandler = instance.addInteractionListener('
|
|
68
|
+
const zoomHandler = instance.addInteractionListener('zoomPinch', rafThrottledCallback);
|
|
60
69
|
return () => {
|
|
61
70
|
zoomHandler.cleanup();
|
|
62
71
|
rafThrottledCallback.clear();
|
|
63
72
|
};
|
|
64
|
-
}, [svgRef, drawingArea,
|
|
73
|
+
}, [svgRef, drawingArea, isZoomOnPinchEnabled, optionsLookup, store, instance, setZoomDataCallback]);
|
|
65
74
|
};
|
|
66
75
|
exports.useZoomOnPinch = useZoomOnPinch;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChartPlugin, ZoomData } from '@mui/x-charts/internals';
|
|
3
|
+
import { UseChartProZoomSignature } from "../useChartProZoom.types.js";
|
|
4
|
+
export declare const useZoomOnTapAndDrag: ({
|
|
5
|
+
store,
|
|
6
|
+
instance,
|
|
7
|
+
svgRef
|
|
8
|
+
}: Pick<Parameters<ChartPlugin<UseChartProZoomSignature>>[0], "store" | "instance" | "svgRef">, setZoomDataCallback: React.Dispatch<ZoomData[] | ((prev: ZoomData[]) => ZoomData[])>) => void;
|
|
@@ -0,0 +1,80 @@
|
|
|
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.useZoomOnTapAndDrag = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _internals = require("@mui/x-charts/internals");
|
|
11
|
+
var _rafThrottle = require("@mui/x-internals/rafThrottle");
|
|
12
|
+
var _useZoom = require("./useZoom.utils");
|
|
13
|
+
var _ZoomInteractionConfig = require("../ZoomInteractionConfig.selectors");
|
|
14
|
+
const useZoomOnTapAndDrag = ({
|
|
15
|
+
store,
|
|
16
|
+
instance,
|
|
17
|
+
svgRef
|
|
18
|
+
}, setZoomDataCallback) => {
|
|
19
|
+
const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
|
|
20
|
+
const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
|
|
21
|
+
const config = (0, _internals.useSelector)(store, _ZoomInteractionConfig.selectorZoomInteractionConfig, ['tapAndDrag']);
|
|
22
|
+
const isZoomOnTapAndDragEnabled = React.useMemo(() => Object.keys(optionsLookup).length > 0 && config || false, [optionsLookup, config]);
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
if (!isZoomOnTapAndDragEnabled) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
instance.updateZoomInteractionListeners('zoomTapAndDrag', {
|
|
28
|
+
requiredKeys: config.requiredKeys,
|
|
29
|
+
pointerMode: config.pointerMode,
|
|
30
|
+
pointerOptions: {
|
|
31
|
+
mouse: config.mouse,
|
|
32
|
+
touch: config.touch
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}, [config, isZoomOnTapAndDragEnabled, instance]);
|
|
36
|
+
|
|
37
|
+
// Zoom on tap and drag
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
const element = svgRef.current;
|
|
40
|
+
if (element === null || !isZoomOnTapAndDragEnabled) {
|
|
41
|
+
return () => {};
|
|
42
|
+
}
|
|
43
|
+
const rafThrottledCallback = (0, _rafThrottle.rafThrottle)(event => {
|
|
44
|
+
// If the delta is 0, we didn't move
|
|
45
|
+
if (event.detail.deltaY === 0) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
setZoomDataCallback(prev => {
|
|
49
|
+
return prev.map(zoom => {
|
|
50
|
+
const option = optionsLookup[zoom.axisId];
|
|
51
|
+
if (!option) {
|
|
52
|
+
return zoom;
|
|
53
|
+
}
|
|
54
|
+
const isZoomIn = event.detail.deltaY > 0;
|
|
55
|
+
const scaleRatio = 1 + event.detail.deltaY / 100;
|
|
56
|
+
const point = (0, _internals.getSVGPoint)(element, {
|
|
57
|
+
clientX: event.detail.initialCentroid.x,
|
|
58
|
+
clientY: event.detail.initialCentroid.y
|
|
59
|
+
});
|
|
60
|
+
const centerRatio = option.axisDirection === 'x' ? (0, _useZoom.getHorizontalCenterRatio)(point, drawingArea) : (0, _useZoom.getVerticalCenterRatio)(point, drawingArea);
|
|
61
|
+
const [newMinRange, newMaxRange] = (0, _useZoom.zoomAtPoint)(centerRatio, scaleRatio, zoom, option);
|
|
62
|
+
if (!(0, _useZoom.isSpanValid)(newMinRange, newMaxRange, isZoomIn, option)) {
|
|
63
|
+
return zoom;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
axisId: zoom.axisId,
|
|
67
|
+
start: newMinRange,
|
|
68
|
+
end: newMaxRange
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
const zoomHandler = instance.addInteractionListener('zoomTapAndDrag', rafThrottledCallback);
|
|
74
|
+
return () => {
|
|
75
|
+
zoomHandler.cleanup();
|
|
76
|
+
rafThrottledCallback.clear();
|
|
77
|
+
};
|
|
78
|
+
}, [svgRef, drawingArea, isZoomOnTapAndDragEnabled, optionsLookup, store, instance, setZoomDataCallback]);
|
|
79
|
+
};
|
|
80
|
+
exports.useZoomOnTapAndDrag = useZoomOnTapAndDrag;
|
|
@@ -10,6 +10,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _internals = require("@mui/x-charts/internals");
|
|
11
11
|
var _rafThrottle = require("@mui/x-internals/rafThrottle");
|
|
12
12
|
var _useZoom = require("./useZoom.utils");
|
|
13
|
+
var _ZoomInteractionConfig = require("../ZoomInteractionConfig.selectors");
|
|
13
14
|
const useZoomOnWheel = ({
|
|
14
15
|
store,
|
|
15
16
|
instance,
|
|
@@ -17,18 +18,27 @@ const useZoomOnWheel = ({
|
|
|
17
18
|
}, setZoomDataCallback) => {
|
|
18
19
|
const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
|
|
19
20
|
const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
|
|
20
|
-
const isZoomEnabled = Object.keys(optionsLookup).length > 0;
|
|
21
21
|
const startedOutsideRef = React.useRef(false);
|
|
22
22
|
const startedOutsideTimeoutRef = React.useRef(null);
|
|
23
|
+
const config = (0, _internals.useSelector)(store, _ZoomInteractionConfig.selectorZoomInteractionConfig, ['wheel']);
|
|
24
|
+
const isZoomOnWheelEnabled = React.useMemo(() => Object.keys(optionsLookup).length > 0 && config || false, [optionsLookup, config]);
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
if (!isZoomOnWheelEnabled) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
instance.updateZoomInteractionListeners('zoomTurnWheel', {
|
|
30
|
+
requiredKeys: config.requiredKeys
|
|
31
|
+
});
|
|
32
|
+
}, [config, isZoomOnWheelEnabled, instance]);
|
|
23
33
|
|
|
24
34
|
// Add event for chart zoom in/out
|
|
25
35
|
React.useEffect(() => {
|
|
26
36
|
const element = svgRef.current;
|
|
27
|
-
if (element === null || !
|
|
37
|
+
if (element === null || !isZoomOnWheelEnabled) {
|
|
28
38
|
return () => {};
|
|
29
39
|
}
|
|
30
40
|
const rafThrottledSetZoomData = (0, _rafThrottle.rafThrottle)(setZoomDataCallback);
|
|
31
|
-
const zoomOnWheelHandler = instance.addInteractionListener('
|
|
41
|
+
const zoomOnWheelHandler = instance.addInteractionListener('zoomTurnWheel', event => {
|
|
32
42
|
const point = (0, _internals.getSVGPoint)(element, {
|
|
33
43
|
clientX: event.detail.centroid.x,
|
|
34
44
|
clientY: event.detail.centroid.y
|
|
@@ -81,6 +91,6 @@ const useZoomOnWheel = ({
|
|
|
81
91
|
startedOutsideRef.current = false;
|
|
82
92
|
rafThrottledSetZoomData.clear();
|
|
83
93
|
};
|
|
84
|
-
}, [svgRef, drawingArea,
|
|
94
|
+
}, [svgRef, drawingArea, isZoomOnWheelEnabled, optionsLookup, instance, setZoomDataCallback, store]);
|
|
85
95
|
};
|
|
86
96
|
exports.useZoomOnWheel = useZoomOnWheel;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.initializeZoomData = initializeZoomData;
|
|
8
|
+
// This is helpful to avoid the need to provide the possibly auto-generated id for each axis.
|
|
9
|
+
function initializeZoomData(options, zoomData) {
|
|
10
|
+
const zoomDataMap = new Map();
|
|
11
|
+
zoomData?.forEach(zoom => {
|
|
12
|
+
const option = options[zoom.axisId];
|
|
13
|
+
if (option) {
|
|
14
|
+
zoomDataMap.set(zoom.axisId, zoom);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return Object.values(options).map(({
|
|
18
|
+
axisId,
|
|
19
|
+
minStart: start,
|
|
20
|
+
maxEnd: end
|
|
21
|
+
}) => {
|
|
22
|
+
if (zoomDataMap.has(axisId)) {
|
|
23
|
+
return zoomDataMap.get(axisId);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
axisId,
|
|
27
|
+
start,
|
|
28
|
+
end
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.initializeZoomInteractionConfig = void 0;
|
|
8
|
+
const initializeZoomInteractionConfig = zoomInteractionConfig => {
|
|
9
|
+
const defaultizedConfig = {
|
|
10
|
+
zoom: {},
|
|
11
|
+
pan: {}
|
|
12
|
+
};
|
|
13
|
+
if (!zoomInteractionConfig?.zoom) {
|
|
14
|
+
defaultizedConfig.zoom = {
|
|
15
|
+
wheel: {
|
|
16
|
+
type: 'wheel',
|
|
17
|
+
requiredKeys: [],
|
|
18
|
+
mouse: {},
|
|
19
|
+
touch: {}
|
|
20
|
+
},
|
|
21
|
+
pinch: {
|
|
22
|
+
type: 'pinch',
|
|
23
|
+
requiredKeys: [],
|
|
24
|
+
mouse: {},
|
|
25
|
+
touch: {}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
} else {
|
|
29
|
+
defaultizedConfig.zoom = initializeFor(zoomInteractionConfig.zoom);
|
|
30
|
+
}
|
|
31
|
+
if (!zoomInteractionConfig?.pan) {
|
|
32
|
+
defaultizedConfig.pan = {
|
|
33
|
+
drag: {
|
|
34
|
+
type: 'drag',
|
|
35
|
+
requiredKeys: [],
|
|
36
|
+
mouse: {},
|
|
37
|
+
touch: {}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
} else {
|
|
41
|
+
defaultizedConfig.pan = initializeFor(zoomInteractionConfig.pan);
|
|
42
|
+
}
|
|
43
|
+
return defaultizedConfig;
|
|
44
|
+
};
|
|
45
|
+
exports.initializeZoomInteractionConfig = initializeZoomInteractionConfig;
|
|
46
|
+
function initializeFor(zoomInteractionConfig) {
|
|
47
|
+
// We aggregate interactions by type
|
|
48
|
+
const aggregation = zoomInteractionConfig.reduce((acc, interaction) => {
|
|
49
|
+
if (typeof interaction === 'string') {
|
|
50
|
+
if (!acc[interaction]) {
|
|
51
|
+
acc[interaction] = [];
|
|
52
|
+
}
|
|
53
|
+
acc[interaction].push({
|
|
54
|
+
type: interaction,
|
|
55
|
+
requiredKeys: []
|
|
56
|
+
});
|
|
57
|
+
return acc;
|
|
58
|
+
}
|
|
59
|
+
const type = interaction.type;
|
|
60
|
+
if (!acc[type]) {
|
|
61
|
+
acc[type] = [];
|
|
62
|
+
}
|
|
63
|
+
acc[type].push({
|
|
64
|
+
type,
|
|
65
|
+
pointerMode: interaction.pointerMode,
|
|
66
|
+
requiredKeys: interaction.requiredKeys
|
|
67
|
+
});
|
|
68
|
+
return acc;
|
|
69
|
+
}, {});
|
|
70
|
+
|
|
71
|
+
// We then need to generate a usable config by type
|
|
72
|
+
// When a gesture type is provided without options, it means we enable it for all pointer modes
|
|
73
|
+
// Any interaction with a specific pointer mode should be restricted to that mode
|
|
74
|
+
const acc = {};
|
|
75
|
+
for (const [type, config] of Object.entries(aggregation)) {
|
|
76
|
+
const lastEmpty = config.findLast(item => !item.pointerMode);
|
|
77
|
+
const lastMouse = config.findLast(item => item.pointerMode === 'mouse');
|
|
78
|
+
const lastTouch = config.findLast(item => item.pointerMode === 'touch');
|
|
79
|
+
acc[type] = {
|
|
80
|
+
type,
|
|
81
|
+
pointerMode: lastEmpty ? [] : Array.from(new Set(config.filter(c => c.pointerMode).map(c => c.pointerMode))),
|
|
82
|
+
requiredKeys: lastEmpty?.requiredKeys ?? [],
|
|
83
|
+
mouse: lastMouse ? {
|
|
84
|
+
requiredKeys: lastMouse?.requiredKeys ?? []
|
|
85
|
+
} : {},
|
|
86
|
+
touch: lastTouch ? {
|
|
87
|
+
requiredKeys: lastTouch?.requiredKeys ?? []
|
|
88
|
+
} : {}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return acc;
|
|
92
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ChartPlugin
|
|
1
|
+
import { ChartPlugin } from '@mui/x-charts/internals';
|
|
2
2
|
import { UseChartProZoomSignature } from "./useChartProZoom.types.js";
|
|
3
|
-
export declare function initializeZoomData(options: Record<AxisId, Pick<DefaultizedZoomOptions, 'axisId' | 'minStart' | 'maxEnd'>>, zoomData?: readonly ZoomData[]): ZoomData[];
|
|
4
3
|
export declare const useChartProZoom: ChartPlugin<UseChartProZoomSignature>;
|
|
@@ -6,53 +6,41 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
value: true
|
|
8
8
|
});
|
|
9
|
-
exports.initializeZoomData = initializeZoomData;
|
|
10
9
|
exports.useChartProZoom = void 0;
|
|
11
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
11
|
var React = _interopRequireWildcard(require("react"));
|
|
13
12
|
var _internals = require("@mui/x-charts/internals");
|
|
14
13
|
var _debounce = _interopRequireDefault(require("@mui/utils/debounce"));
|
|
14
|
+
var _useEffectAfterFirstRender = require("@mui/x-internals/useEffectAfterFirstRender");
|
|
15
15
|
var _utils = require("@mui/material/utils");
|
|
16
16
|
var _calculateZoom = require("./calculateZoom");
|
|
17
17
|
var _useZoomOnWheel = require("./gestureHooks/useZoomOnWheel");
|
|
18
18
|
var _useZoomOnPinch = require("./gestureHooks/useZoomOnPinch");
|
|
19
19
|
var _usePanOnDrag = require("./gestureHooks/usePanOnDrag");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
return Object.values(options).map(({
|
|
30
|
-
axisId,
|
|
31
|
-
minStart: start,
|
|
32
|
-
maxEnd: end
|
|
33
|
-
}) => {
|
|
34
|
-
if (zoomDataMap.has(axisId)) {
|
|
35
|
-
return zoomDataMap.get(axisId);
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
axisId,
|
|
39
|
-
start,
|
|
40
|
-
end
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const useChartProZoom = ({
|
|
45
|
-
store,
|
|
46
|
-
instance,
|
|
47
|
-
svgRef,
|
|
48
|
-
params
|
|
49
|
-
}) => {
|
|
20
|
+
var _useZoomOnTapAndDrag = require("./gestureHooks/useZoomOnTapAndDrag");
|
|
21
|
+
var _initializeZoomInteractionConfig = require("./initializeZoomInteractionConfig");
|
|
22
|
+
var _initializeZoomData = require("./initializeZoomData");
|
|
23
|
+
const useChartProZoom = pluginData => {
|
|
24
|
+
const {
|
|
25
|
+
store,
|
|
26
|
+
params
|
|
27
|
+
} = pluginData;
|
|
50
28
|
const {
|
|
51
29
|
zoomData: paramsZoomData,
|
|
52
|
-
onZoomChange: onZoomChangeProp
|
|
30
|
+
onZoomChange: onZoomChangeProp,
|
|
31
|
+
zoomInteractionConfig
|
|
53
32
|
} = params;
|
|
54
33
|
const onZoomChange = (0, _utils.useEventCallback)(onZoomChangeProp ?? (() => {}));
|
|
55
34
|
const optionsLookup = (0, _internals.useSelector)(store, _internals.selectorChartZoomOptionsLookup);
|
|
35
|
+
(0, _useEffectAfterFirstRender.useEffectAfterFirstRender)(() => {
|
|
36
|
+
store.update(prevState => {
|
|
37
|
+
return (0, _extends2.default)({}, prevState, {
|
|
38
|
+
zoom: (0, _extends2.default)({}, prevState.zoom, {
|
|
39
|
+
zoomInteractionConfig: (0, _initializeZoomInteractionConfig.initializeZoomInteractionConfig)(zoomInteractionConfig)
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}, [store, zoomInteractionConfig]);
|
|
56
44
|
|
|
57
45
|
// Manage controlled state
|
|
58
46
|
React.useEffect(() => {
|
|
@@ -151,14 +139,10 @@ const useChartProZoom = ({
|
|
|
151
139
|
}, [removeIsInteracting]);
|
|
152
140
|
|
|
153
141
|
// Add events
|
|
154
|
-
const pluginData = {
|
|
155
|
-
store,
|
|
156
|
-
instance,
|
|
157
|
-
svgRef
|
|
158
|
-
};
|
|
159
142
|
(0, _usePanOnDrag.usePanOnDrag)(pluginData, setZoomDataCallback);
|
|
160
143
|
(0, _useZoomOnWheel.useZoomOnWheel)(pluginData, setZoomDataCallback);
|
|
161
144
|
(0, _useZoomOnPinch.useZoomOnPinch)(pluginData, setZoomDataCallback);
|
|
145
|
+
(0, _useZoomOnTapAndDrag.useZoomOnTapAndDrag)(pluginData, setZoomDataCallback);
|
|
162
146
|
const zoom = React.useCallback(step => {
|
|
163
147
|
setZoomDataCallback(prev => prev.map(zoomData => {
|
|
164
148
|
const zoomOptions = (0, _internals.selectorChartAxisZoomOptionsLookup)(store.getSnapshot(), zoomData.axisId);
|
|
@@ -187,12 +171,8 @@ exports.useChartProZoom = useChartProZoom;
|
|
|
187
171
|
useChartProZoom.params = {
|
|
188
172
|
initialZoom: true,
|
|
189
173
|
onZoomChange: true,
|
|
190
|
-
zoomData: true
|
|
191
|
-
|
|
192
|
-
useChartProZoom.getDefaultizedParams = ({
|
|
193
|
-
params
|
|
194
|
-
}) => {
|
|
195
|
-
return (0, _extends2.default)({}, params);
|
|
174
|
+
zoomData: true,
|
|
175
|
+
zoomInteractionConfig: true
|
|
196
176
|
};
|
|
197
177
|
useChartProZoom.getInitialState = params => {
|
|
198
178
|
const {
|
|
@@ -207,9 +187,10 @@ useChartProZoom.getInitialState = params => {
|
|
|
207
187
|
zoomData !== undefined ? zoomData : initialZoom !== undefined ? initialZoom : undefined;
|
|
208
188
|
return {
|
|
209
189
|
zoom: {
|
|
210
|
-
zoomData: initializeZoomData(optionsLookup, userZoomData),
|
|
190
|
+
zoomData: (0, _initializeZoomData.initializeZoomData)(optionsLookup, userZoomData),
|
|
211
191
|
isInteracting: false,
|
|
212
|
-
isControlled: zoomData !== undefined
|
|
192
|
+
isControlled: zoomData !== undefined,
|
|
193
|
+
zoomInteractionConfig: (0, _initializeZoomInteractionConfig.initializeZoomInteractionConfig)(params.zoomInteractionConfig)
|
|
213
194
|
}
|
|
214
195
|
};
|
|
215
196
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UseChartSeriesSignature, ChartPluginSignature, UseChartCartesianAxisSignature, UseChartCartesianAxisDefaultizedParameters, ZoomData, AxisId } from '@mui/x-charts/internals';
|
|
2
|
+
import { ZoomInteractionConfig, DefaultizedZoomInteractionConfig } from "./ZoomInteractionConfig.types.js";
|
|
2
3
|
export interface UseChartProZoomParameters {
|
|
3
4
|
/**
|
|
4
5
|
* The list of zoom data related to each axis.
|
|
@@ -15,6 +16,10 @@ export interface UseChartProZoomParameters {
|
|
|
15
16
|
* The list of zoom data related to each axis.
|
|
16
17
|
*/
|
|
17
18
|
zoomData?: readonly ZoomData[];
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for zoom interactions.
|
|
21
|
+
*/
|
|
22
|
+
zoomInteractionConfig?: ZoomInteractionConfig;
|
|
18
23
|
}
|
|
19
24
|
export type UseChartProZoomDefaultizedParameters = UseChartProZoomParameters & UseChartCartesianAxisDefaultizedParameters;
|
|
20
25
|
export interface UseChartProZoomState {
|
|
@@ -32,6 +37,10 @@ export interface UseChartProZoomState {
|
|
|
32
37
|
* Internal information to know if the user control the state or not.
|
|
33
38
|
*/
|
|
34
39
|
isControlled: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Configuration for zoom interactions.
|
|
42
|
+
*/
|
|
43
|
+
zoomInteractionConfig: DefaultizedZoomInteractionConfig;
|
|
35
44
|
};
|
|
36
45
|
}
|
|
37
46
|
export interface UseChartProZoomPublicApi {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts-pro",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.13.1",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "The Pro plan edition of the MUI X Charts components.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"directory": "packages/x-charts-pro"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/runtime": "^7.28.
|
|
30
|
+
"@babel/runtime": "^7.28.4",
|
|
31
31
|
"@mui/utils": "^7.3.2",
|
|
32
32
|
"clsx": "^2.1.1",
|
|
33
33
|
"prop-types": "^15.8.1",
|
|
34
|
-
"@mui/x-charts": "8.
|
|
34
|
+
"@mui/x-charts": "8.13.1",
|
|
35
35
|
"@mui/x-charts-vendor": "8.12.0",
|
|
36
|
-
"@mui/x-
|
|
37
|
-
"@mui/x-
|
|
38
|
-
"@mui/x-
|
|
36
|
+
"@mui/x-internal-gestures": "0.3.2",
|
|
37
|
+
"@mui/x-internals": "8.13.1",
|
|
38
|
+
"@mui/x-license": "8.12.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@emotion/react": "^11.9.0",
|