@mui/x-charts-pro 9.3.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.
- package/BarChartPro/BarChartPro.js +33 -3
- package/BarChartPro/BarChartPro.mjs +34 -4
- package/CHANGELOG.md +296 -0
- package/ChartsDataProviderPro/ChartsDataProviderPro.js +2 -2
- package/ChartsDataProviderPro/ChartsDataProviderPro.mjs +2 -2
- package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +1 -0
- package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.mjs +1 -0
- package/ChartsToolbarPro/ChartsToolbarPro.d.mts +1 -1
- package/ChartsToolbarPro/ChartsToolbarPro.d.ts +1 -1
- package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.d.mts +1 -1
- package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.d.ts +1 -1
- package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.js +35 -38
- package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.mjs +37 -40
- package/ChartsToolbarPro/Toolbar.types.d.mts +3 -2
- package/ChartsToolbarPro/Toolbar.types.d.ts +3 -2
- package/ChartsToolbarPro/rangeButtonValueToZoom.d.mts +18 -2
- package/ChartsToolbarPro/rangeButtonValueToZoom.d.ts +18 -2
- package/ChartsToolbarPro/rangeButtonValueToZoom.js +73 -10
- package/ChartsToolbarPro/rangeButtonValueToZoom.mjs +72 -10
- package/ChartsZoomSlider/internals/chartsAxisZoomSliderThumbClasses.js +9 -2
- package/ChartsZoomSlider/internals/chartsAxisZoomSliderThumbClasses.mjs +9 -2
- package/ChartsZoomSlider/internals/previews/ScatterPreviewPlot.js +2 -1
- package/ChartsZoomSlider/internals/previews/ScatterPreviewPlot.mjs +2 -1
- package/FunnelChart/funnel.types.d.mts +1 -1
- package/FunnelChart/funnel.types.d.ts +1 -1
- package/FunnelChart/funnelPlotSlots.types.d.mts +5 -4
- package/FunnelChart/funnelPlotSlots.types.d.ts +5 -4
- package/Heatmap/Heatmap.d.mts +3 -2
- package/Heatmap/Heatmap.d.ts +3 -2
- package/Heatmap/Heatmap.js +32 -2
- package/Heatmap/Heatmap.mjs +32 -2
- package/Heatmap/HeatmapItem.d.mts +3 -2
- package/Heatmap/HeatmapItem.d.ts +3 -2
- package/Heatmap/HeatmapItem.js +2 -0
- package/Heatmap/HeatmapItem.mjs +2 -0
- package/Heatmap/HeatmapTooltip/HeatmapTooltip.types.d.mts +3 -2
- package/Heatmap/HeatmapTooltip/HeatmapTooltip.types.d.ts +3 -2
- package/LineChartPro/LineChartPro.js +33 -3
- package/LineChartPro/LineChartPro.mjs +34 -4
- package/PieChartPro/PieChartPro.js +1 -1
- package/PieChartPro/PieChartPro.mjs +2 -2
- package/RadarChartPro/RadarChartPro.js +1 -1
- package/RadarChartPro/RadarChartPro.mjs +2 -2
- package/ScatterChartPro/ScatterChartPro.d.mts +2 -1
- package/ScatterChartPro/ScatterChartPro.d.ts +2 -1
- package/ScatterChartPro/ScatterChartPro.js +40 -6
- package/ScatterChartPro/ScatterChartPro.mjs +41 -7
- 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/useChartProExport/exportImage.js +8 -2
- package/internals/plugins/useChartProExport/exportImage.mjs +8 -2
- package/internals/plugins/useChartProExport/print.js +1 -0
- package/internals/plugins/useChartProExport/print.mjs +1 -0
- package/internals/plugins/useChartProExport/useChartProExport.types.d.mts +6 -0
- package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +6 -0
- 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/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 +77 -14
- package/internals/plugins/useChartProZoom/useChartProZoom.mjs +79 -15
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.mts +0 -3
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +0 -3
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +1 -2
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.mjs +0 -1
- package/internals/plugins/useChartProZoom/useChartProZoom.types.d.mts +28 -11
- package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +28 -11
- 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/internals/slots/chartsBaseSlots.d.mts +6 -5
- package/internals/slots/chartsBaseSlots.d.ts +6 -5
- package/internals/slots/chartsIconSlots.d.mts +4 -3
- package/internals/slots/chartsIconSlots.d.ts +4 -3
- package/models/chartsSlotsComponentsPropsPro.d.mts +11 -0
- package/models/chartsSlotsComponentsPropsPro.d.ts +11 -0
- package/models/chartsSlotsComponentsPropsPro.js +5 -0
- package/models/chartsSlotsComponentsPropsPro.mjs +1 -0
- package/models/index.d.mts +1 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +12 -0
- package/models/index.mjs +1 -0
- package/models/seriesType/heatmap.d.mts +1 -1
- package/models/seriesType/heatmap.d.ts +1 -1
- package/package.json +5 -5
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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,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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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,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
|
};
|