@mui/x-charts-pro 8.13.1 → 8.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/BarChartPro/BarChartPro.js +49 -37
  2. package/CHANGELOG.md +109 -1
  3. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  4. package/FunnelChart/funnelAxisPlugin/computeAxisValue.js +38 -36
  5. package/Heatmap/Heatmap.js +0 -4
  6. package/LineChartPro/LineChartPro.js +49 -37
  7. package/ScatterChartPro/ScatterChartPro.js +49 -37
  8. package/esm/BarChartPro/BarChartPro.js +49 -37
  9. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  10. package/esm/FunnelChart/funnelAxisPlugin/computeAxisValue.js +39 -37
  11. package/esm/Heatmap/Heatmap.js +0 -4
  12. package/esm/LineChartPro/LineChartPro.js +49 -37
  13. package/esm/ScatterChartPro/ScatterChartPro.js +49 -37
  14. package/esm/index.js +1 -1
  15. package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +2 -6
  16. package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +5 -1
  17. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.ts +8 -0
  18. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.js +73 -0
  19. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +2 -0
  20. package/index.js +1 -1
  21. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +2 -6
  22. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +5 -1
  23. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.ts +8 -0
  24. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.js +80 -0
  25. package/internals/plugins/useChartProZoom/useChartProZoom.js +2 -0
  26. package/package.json +7 -7
@@ -0,0 +1,73 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { useSelector, selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
5
+ import { rafThrottle } from '@mui/x-internals/rafThrottle';
6
+ import { translateZoom } from "./useZoom.utils.js";
7
+ import { selectorPanInteractionConfig } from "../ZoomInteractionConfig.selectors.js";
8
+ export const usePanOnPressAndDrag = ({
9
+ store,
10
+ instance,
11
+ svgRef
12
+ }, setZoomDataCallback) => {
13
+ const drawingArea = useSelector(store, selectorChartDrawingArea);
14
+ const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
15
+ const startRef = React.useRef(null);
16
+ const config = useSelector(store, selectorPanInteractionConfig, ['pressAndDrag']);
17
+ const isPanOnPressAndDragEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) && config || false, [optionsLookup, config]);
18
+ React.useEffect(() => {
19
+ if (!isPanOnPressAndDragEnabled) {
20
+ return;
21
+ }
22
+ instance.updateZoomInteractionListeners('zoomPressAndDrag', {
23
+ requiredKeys: config.requiredKeys,
24
+ pointerMode: config.pointerMode,
25
+ pointerOptions: {
26
+ mouse: config.mouse,
27
+ touch: config.touch
28
+ }
29
+ });
30
+ }, [isPanOnPressAndDragEnabled, config, instance]);
31
+
32
+ // Add event for chart panning with press and drag
33
+ React.useEffect(() => {
34
+ const element = svgRef.current;
35
+ if (element === null || !isPanOnPressAndDragEnabled) {
36
+ return () => {};
37
+ }
38
+ const handlePressAndDragStart = event => {
39
+ if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
40
+ startRef.current = store.value.zoom.zoomData;
41
+ }
42
+ };
43
+ const handlePressAndDragEnd = () => {
44
+ startRef.current = null;
45
+ };
46
+ const throttledCallback = rafThrottle((event, zoomData) => {
47
+ const newZoomData = translateZoom(zoomData, {
48
+ x: event.detail.activeDeltaX,
49
+ y: -event.detail.activeDeltaY
50
+ }, {
51
+ width: drawingArea.width,
52
+ height: drawingArea.height
53
+ }, optionsLookup);
54
+ setZoomDataCallback(newZoomData);
55
+ });
56
+ const handlePressAndDrag = event => {
57
+ const zoomData = startRef.current;
58
+ if (!zoomData) {
59
+ return;
60
+ }
61
+ throttledCallback(event, zoomData);
62
+ };
63
+ const pressAndDragHandler = instance.addInteractionListener('zoomPressAndDrag', handlePressAndDrag);
64
+ const pressAndDragStartHandler = instance.addInteractionListener('zoomPressAndDragStart', handlePressAndDragStart);
65
+ const pressAndDragEndHandler = instance.addInteractionListener('zoomPressAndDragEnd', handlePressAndDragEnd);
66
+ return () => {
67
+ pressAndDragStartHandler.cleanup();
68
+ pressAndDragHandler.cleanup();
69
+ pressAndDragEndHandler.cleanup();
70
+ throttledCallback.clear();
71
+ };
72
+ }, [instance, svgRef, isPanOnPressAndDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, startRef]);
73
+ };
@@ -11,6 +11,7 @@ import { useZoomOnWheel } from "./gestureHooks/useZoomOnWheel.js";
11
11
  import { useZoomOnPinch } from "./gestureHooks/useZoomOnPinch.js";
12
12
  import { usePanOnDrag } from "./gestureHooks/usePanOnDrag.js";
13
13
  import { useZoomOnTapAndDrag } from "./gestureHooks/useZoomOnTapAndDrag.js";
14
+ import { usePanOnPressAndDrag } from "./gestureHooks/usePanOnPressAndDrag.js";
14
15
  import { initializeZoomInteractionConfig } from "./initializeZoomInteractionConfig.js";
15
16
  import { initializeZoomData } from "./initializeZoomData.js";
16
17
  export const useChartProZoom = pluginData => {
@@ -133,6 +134,7 @@ export const useChartProZoom = pluginData => {
133
134
 
134
135
  // Add events
135
136
  usePanOnDrag(pluginData, setZoomDataCallback);
137
+ usePanOnPressAndDrag(pluginData, setZoomDataCallback);
136
138
  useZoomOnWheel(pluginData, setZoomDataCallback);
137
139
  useZoomOnPinch(pluginData, setZoomDataCallback);
138
140
  useZoomOnTapAndDrag(pluginData, setZoomDataCallback);
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts-pro v8.13.1
2
+ * @mui/x-charts-pro v8.14.0
3
3
  *
4
4
  * @license SEE LICENSE IN LICENSE
5
5
  * This source code is licensed under the SEE LICENSE IN LICENSE license found in the
@@ -7,11 +7,7 @@ export declare const selectorZoomInteractionConfig: import("reselect").Selector<
7
7
  };
8
8
  pointerMode?: import("@mui/x-internal-gestures/core").PointerMode[];
9
9
  }) | null, [interactionName: "wheel" | "pinch" | "tapAndDrag"]>;
10
- export declare const selectorPanInteractionConfig: import("reselect").Selector<any, (Omit<{
11
- type: "drag";
12
- pointerMode?: import("./ZoomInteractionConfig.types.js").InteractionMode | undefined;
13
- requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[] | undefined;
14
- }, "pointerMode"> & {
10
+ export declare const selectorPanInteractionConfig: import("reselect").Selector<any, (Omit<import("./ZoomInteractionConfig.types.js").PanInteraction, "pointerMode"> & {
15
11
  mouse: {
16
12
  requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
17
13
  };
@@ -19,4 +15,4 @@ export declare const selectorPanInteractionConfig: import("reselect").Selector<a
19
15
  requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
20
16
  };
21
17
  pointerMode?: import("@mui/x-internal-gestures/core").PointerMode[];
22
- }) | null, [interactionName: "drag"]>;
18
+ }) | null, [interactionName: "drag" | "pressAndDrag"]>;
@@ -12,6 +12,7 @@ export type ZoomInteractionConfig = {
12
12
  /**
13
13
  * Defines the interactions that trigger panning.
14
14
  * - `drag`: Pans the chart when dragged with the mouse.
15
+ * - `pressAndDrag`: Pans the chart by pressing and holding, then dragging. Useful for avoiding conflicts with selection gestures.
15
16
  *
16
17
  * @default ['drag']
17
18
  */
@@ -31,7 +32,7 @@ export type DefaultizedZoomInteractionConfig = {
31
32
  pan: Entry<PanInteraction>;
32
33
  };
33
34
  export type ZoomInteraction = WheelInteraction | PinchInteraction | TapAndDragInteraction;
34
- export type PanInteraction = DragInteraction;
35
+ export type PanInteraction = DragInteraction | PressAndDragInteraction;
35
36
  export type ZoomInteractionName = ZoomInteraction['type'];
36
37
  export type PanInteractionName = PanInteraction['type'];
37
38
  export type InteractionMode = Exclude<PointerMode, 'pen'>;
@@ -75,6 +76,9 @@ export type DragInteraction = Unpack<{
75
76
  export type TapAndDragInteraction = Unpack<{
76
77
  type: 'tapAndDrag';
77
78
  } & AllModeProp & AllKeysProp>;
79
+ export type PressAndDragInteraction = Unpack<{
80
+ type: 'pressAndDrag';
81
+ } & AllModeProp & AllKeysProp>;
78
82
  export type AnyInteraction = {
79
83
  type: string;
80
84
  pointerMode?: InteractionMode;
@@ -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 usePanOnPressAndDrag: ({
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.usePanOnPressAndDrag = 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 usePanOnPressAndDrag = ({
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 startRef = React.useRef(null);
22
+ const config = (0, _internals.useSelector)(store, _ZoomInteractionConfig.selectorPanInteractionConfig, ['pressAndDrag']);
23
+ const isPanOnPressAndDragEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) && config || false, [optionsLookup, config]);
24
+ React.useEffect(() => {
25
+ if (!isPanOnPressAndDragEnabled) {
26
+ return;
27
+ }
28
+ instance.updateZoomInteractionListeners('zoomPressAndDrag', {
29
+ requiredKeys: config.requiredKeys,
30
+ pointerMode: config.pointerMode,
31
+ pointerOptions: {
32
+ mouse: config.mouse,
33
+ touch: config.touch
34
+ }
35
+ });
36
+ }, [isPanOnPressAndDragEnabled, config, instance]);
37
+
38
+ // Add event for chart panning with press and drag
39
+ React.useEffect(() => {
40
+ const element = svgRef.current;
41
+ if (element === null || !isPanOnPressAndDragEnabled) {
42
+ return () => {};
43
+ }
44
+ const handlePressAndDragStart = event => {
45
+ if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
46
+ startRef.current = store.value.zoom.zoomData;
47
+ }
48
+ };
49
+ const handlePressAndDragEnd = () => {
50
+ startRef.current = null;
51
+ };
52
+ const throttledCallback = (0, _rafThrottle.rafThrottle)((event, zoomData) => {
53
+ const newZoomData = (0, _useZoom.translateZoom)(zoomData, {
54
+ x: event.detail.activeDeltaX,
55
+ y: -event.detail.activeDeltaY
56
+ }, {
57
+ width: drawingArea.width,
58
+ height: drawingArea.height
59
+ }, optionsLookup);
60
+ setZoomDataCallback(newZoomData);
61
+ });
62
+ const handlePressAndDrag = event => {
63
+ const zoomData = startRef.current;
64
+ if (!zoomData) {
65
+ return;
66
+ }
67
+ throttledCallback(event, zoomData);
68
+ };
69
+ const pressAndDragHandler = instance.addInteractionListener('zoomPressAndDrag', handlePressAndDrag);
70
+ const pressAndDragStartHandler = instance.addInteractionListener('zoomPressAndDragStart', handlePressAndDragStart);
71
+ const pressAndDragEndHandler = instance.addInteractionListener('zoomPressAndDragEnd', handlePressAndDragEnd);
72
+ return () => {
73
+ pressAndDragStartHandler.cleanup();
74
+ pressAndDragHandler.cleanup();
75
+ pressAndDragEndHandler.cleanup();
76
+ throttledCallback.clear();
77
+ };
78
+ }, [instance, svgRef, isPanOnPressAndDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, startRef]);
79
+ };
80
+ exports.usePanOnPressAndDrag = usePanOnPressAndDrag;
@@ -18,6 +18,7 @@ var _useZoomOnWheel = require("./gestureHooks/useZoomOnWheel");
18
18
  var _useZoomOnPinch = require("./gestureHooks/useZoomOnPinch");
19
19
  var _usePanOnDrag = require("./gestureHooks/usePanOnDrag");
20
20
  var _useZoomOnTapAndDrag = require("./gestureHooks/useZoomOnTapAndDrag");
21
+ var _usePanOnPressAndDrag = require("./gestureHooks/usePanOnPressAndDrag");
21
22
  var _initializeZoomInteractionConfig = require("./initializeZoomInteractionConfig");
22
23
  var _initializeZoomData = require("./initializeZoomData");
23
24
  const useChartProZoom = pluginData => {
@@ -140,6 +141,7 @@ const useChartProZoom = pluginData => {
140
141
 
141
142
  // Add events
142
143
  (0, _usePanOnDrag.usePanOnDrag)(pluginData, setZoomDataCallback);
144
+ (0, _usePanOnPressAndDrag.usePanOnPressAndDrag)(pluginData, setZoomDataCallback);
143
145
  (0, _useZoomOnWheel.useZoomOnWheel)(pluginData, setZoomDataCallback);
144
146
  (0, _useZoomOnPinch.useZoomOnPinch)(pluginData, setZoomDataCallback);
145
147
  (0, _useZoomOnTapAndDrag.useZoomOnTapAndDrag)(pluginData, setZoomDataCallback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts-pro",
3
- "version": "8.13.1",
3
+ "version": "8.14.0",
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",
@@ -28,14 +28,14 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7.28.4",
31
- "@mui/utils": "^7.3.2",
31
+ "@mui/utils": "^7.3.3",
32
32
  "clsx": "^2.1.1",
33
33
  "prop-types": "^15.8.1",
34
- "@mui/x-charts": "8.13.1",
35
- "@mui/x-charts-vendor": "8.12.0",
36
- "@mui/x-internal-gestures": "0.3.2",
37
- "@mui/x-internals": "8.13.1",
38
- "@mui/x-license": "8.12.0"
34
+ "@mui/x-charts-vendor": "8.14.0",
35
+ "@mui/x-charts": "8.14.0",
36
+ "@mui/x-internals": "8.14.0",
37
+ "@mui/x-internal-gestures": "0.3.3",
38
+ "@mui/x-license": "8.14.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@emotion/react": "^11.9.0",