@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.
- package/BarChartPro/BarChartPro.js +6 -4
- package/BarChartPro/BarChartPro.mjs +7 -5
- package/CHANGELOG.md +251 -0
- package/ChartsDataProviderPro/ChartsDataProviderPro.js +7 -3
- package/ChartsDataProviderPro/ChartsDataProviderPro.mjs +7 -3
- package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +1 -1
- package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.mjs +1 -1
- package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.js +1 -1
- package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.mjs +1 -1
- package/ChartsToolbarPro/ChartsToolbarPro.js +3 -2
- package/ChartsToolbarPro/ChartsToolbarPro.mjs +3 -2
- package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.js +1 -1
- package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.mjs +1 -1
- package/ChartsToolbarPro/ChartsToolbarZoomInTrigger.js +1 -1
- package/ChartsToolbarPro/ChartsToolbarZoomInTrigger.mjs +1 -1
- package/ChartsToolbarPro/ChartsToolbarZoomOutTrigger.js +1 -1
- package/ChartsToolbarPro/ChartsToolbarZoomOutTrigger.mjs +1 -1
- package/FunnelChart/FunnelChart.js +1 -1
- package/FunnelChart/FunnelChart.mjs +1 -1
- package/FunnelChart/FunnelPlot.js +5 -1
- package/FunnelChart/FunnelPlot.mjs +5 -1
- package/FunnelChart/funnel.types.d.mts +1 -1
- package/FunnelChart/funnel.types.d.ts +1 -1
- package/Heatmap/Heatmap.js +5 -3
- package/Heatmap/Heatmap.mjs +5 -3
- package/Heatmap/HeatmapCell.js +1 -1
- package/Heatmap/HeatmapCell.mjs +1 -1
- package/Heatmap/HeatmapPlot.js +1 -1
- package/Heatmap/HeatmapPlot.mjs +1 -1
- package/Heatmap/HeatmapTooltip/HeatmapTooltip.js +5 -25
- package/Heatmap/HeatmapTooltip/HeatmapTooltip.mjs +5 -25
- package/Heatmap/HeatmapTooltip/HeatmapTooltipContent.js +1 -1
- package/Heatmap/HeatmapTooltip/HeatmapTooltipContent.mjs +1 -1
- package/LineChartPro/LineChartPro.js +6 -4
- package/LineChartPro/LineChartPro.mjs +7 -5
- package/PieChartPro/PieChartPro.js +2 -2
- package/PieChartPro/PieChartPro.mjs +3 -3
- package/RadarChartPro/RadarChartPro.js +2 -2
- package/RadarChartPro/RadarChartPro.mjs +3 -3
- package/SankeyChart/SankeyChart.js +1 -1
- package/SankeyChart/SankeyChart.mjs +1 -1
- package/SankeyChart/SankeyDataProvider.d.mts +3 -0
- package/SankeyChart/SankeyDataProvider.d.ts +3 -0
- package/SankeyChart/SankeyDataProvider.js +170 -1
- package/SankeyChart/SankeyDataProvider.mjs +169 -0
- package/SankeyChart/SankeyLinkLabelPlot.d.mts +3 -0
- package/SankeyChart/SankeyLinkLabelPlot.d.ts +3 -0
- package/SankeyChart/SankeyLinkLabelPlot.js +12 -1
- package/SankeyChart/SankeyLinkLabelPlot.mjs +11 -0
- package/SankeyChart/SankeyLinkPlot.d.mts +3 -0
- package/SankeyChart/SankeyLinkPlot.d.ts +3 -0
- package/SankeyChart/SankeyLinkPlot.js +18 -1
- package/SankeyChart/SankeyLinkPlot.mjs +17 -0
- package/SankeyChart/SankeyNodeLabelPlot.d.mts +3 -0
- package/SankeyChart/SankeyNodeLabelPlot.d.ts +3 -0
- package/SankeyChart/SankeyNodeLabelPlot.js +12 -1
- package/SankeyChart/SankeyNodeLabelPlot.mjs +11 -0
- package/SankeyChart/SankeyNodePlot.d.mts +3 -0
- package/SankeyChart/SankeyNodePlot.d.ts +3 -0
- package/SankeyChart/SankeyNodePlot.js +18 -1
- package/SankeyChart/SankeyNodePlot.mjs +17 -0
- package/SankeyChart/SankeyPlot.js +5 -1
- package/SankeyChart/SankeyPlot.mjs +5 -1
- package/SankeyChart/SankeyTooltip/SankeyTooltip.js +8 -28
- package/SankeyChart/SankeyTooltip/SankeyTooltip.mjs +8 -28
- package/SankeyChart/SankeyTooltip/SankeyTooltipContent.js +1 -1
- package/SankeyChart/SankeyTooltip/SankeyTooltipContent.mjs +1 -1
- package/ScatterChartPro/ScatterChartPro.js +13 -7
- package/ScatterChartPro/ScatterChartPro.mjs +14 -8
- package/ScatterChartPro/ScatterChartPro.plugins.d.mts +2 -2
- package/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -2
- package/ScatterChartPro/ScatterChartPro.plugins.js +1 -1
- package/ScatterChartPro/ScatterChartPro.plugins.mjs +2 -2
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/internals/plugins/allPlugins.d.mts +5 -5
- package/internals/plugins/allPlugins.d.ts +5 -5
- package/internals/plugins/allPlugins.js +2 -2
- package/internals/plugins/allPlugins.mjs +3 -3
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.mts +36 -4
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +36 -4
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.js +2 -4
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.mjs +1 -3
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.mts +11 -11
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +11 -11
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.mts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.ts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +9 -65
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.mjs +9 -64
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.mts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.ts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.js +9 -69
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.mjs +9 -68
- package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.d.mts +10 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.d.ts +10 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.js +49 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useRegisterZoomGestures.mjs +42 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.mts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.ts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +9 -39
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.mjs +10 -39
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.mts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.ts +0 -1
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +9 -58
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.mjs +10 -58
- package/internals/plugins/useChartProZoom/useChartProZoom.js +2 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.mjs +2 -0
- package/internals/plugins/zoomGestures/index.d.mts +5 -0
- package/internals/plugins/zoomGestures/index.d.ts +5 -0
- package/internals/plugins/zoomGestures/index.js +33 -0
- package/internals/plugins/zoomGestures/index.mjs +4 -0
- package/internals/plugins/zoomGestures/useDragGesture.d.mts +30 -0
- package/internals/plugins/zoomGestures/useDragGesture.d.ts +30 -0
- package/internals/plugins/zoomGestures/useDragGesture.js +105 -0
- package/internals/plugins/zoomGestures/useDragGesture.mjs +99 -0
- package/internals/plugins/zoomGestures/useDragOnPressGesture.d.mts +30 -0
- package/internals/plugins/zoomGestures/useDragOnPressGesture.d.ts +30 -0
- package/internals/plugins/zoomGestures/useDragOnPressGesture.js +105 -0
- package/internals/plugins/zoomGestures/useDragOnPressGesture.mjs +99 -0
- package/internals/plugins/zoomGestures/usePinchGesture.d.mts +22 -0
- package/internals/plugins/zoomGestures/usePinchGesture.d.ts +22 -0
- package/internals/plugins/zoomGestures/usePinchGesture.js +77 -0
- package/internals/plugins/zoomGestures/usePinchGesture.mjs +71 -0
- package/internals/plugins/zoomGestures/useWheelGesture.d.mts +21 -0
- package/internals/plugins/zoomGestures/useWheelGesture.d.ts +21 -0
- package/internals/plugins/zoomGestures/useWheelGesture.js +78 -0
- package/internals/plugins/zoomGestures/useWheelGesture.mjs +72 -0
- package/internals/plugins/zoomGestures/zoomGestures.types.d.mts +29 -0
- package/internals/plugins/zoomGestures/zoomGestures.types.d.ts +29 -0
- package/internals/plugins/zoomGestures/zoomGestures.types.js +5 -0
- package/internals/plugins/zoomGestures/zoomGestures.types.mjs +1 -0
- package/models/seriesType/heatmap.d.mts +1 -1
- package/models/seriesType/heatmap.d.ts +1 -1
- 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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 =
|
|
52
|
-
const scaleRatio = 1 +
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 =
|
|
46
|
-
const scaleRatio = 1 +
|
|
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
|
-
|
|
65
|
-
return () => {
|
|
66
|
-
zoomHandler.cleanup();
|
|
67
|
-
rafThrottledCallback.clear();
|
|
68
|
-
};
|
|
69
|
-
}, [chartsLayerContainerRef, drawingArea, isZoomOnPinchEnabled, optionsLookup, store, instance, setZoomDataCallback]);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
70
41
|
};
|
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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)(
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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(
|
|
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
|
-
|
|
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,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
|
+
}
|