Skip to content

Commit bd38018

Browse files
committed
feedback
1 parent 4afda13 commit bd38018

6 files changed

Lines changed: 18 additions & 15 deletions

File tree

packages/x-charts-pro/src/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { type UseChartProZoomSignature } from '../useChartProZoom.types';
99
import { translateZoom } from './useZoom.utils';
1010
import { selectorPanInteractionConfig } from '../ZoomInteractionConfig.selectors';
11-
import { usePanGesture } from '../../zoomGestures/usePanGesture';
11+
import { useDragGesture } from '../../zoomGestures/useDragGesture';
1212

1313
export const usePanOnDrag = (
1414
{
@@ -24,7 +24,7 @@ export const usePanOnDrag = (
2424
const isPanOnDragEnabled: boolean =
2525
Object.values(optionsLookup).some((v) => v.panning) && Boolean(config);
2626

27-
usePanGesture(instance, {
27+
useDragGesture(instance, {
2828
config: config ?? undefined,
2929
enabled: isPanOnDragEnabled,
3030
onPan: (delta) => {

packages/x-charts-pro/src/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { type UseChartProZoomSignature } from '../useChartProZoom.types';
99
import { translateZoom } from './useZoom.utils';
1010
import { selectorPanInteractionConfig } from '../ZoomInteractionConfig.selectors';
11-
import { usePanOnPressGesture } from '../../zoomGestures/usePanOnPressGesture';
11+
import { useDragOnPressGesture } from '../../zoomGestures/useDragOnPressGesture';
1212

1313
export const usePanOnPressAndDrag = (
1414
{
@@ -24,7 +24,7 @@ export const usePanOnPressAndDrag = (
2424
const isPanOnPressAndDragEnabled: boolean =
2525
Object.values(optionsLookup).some((v) => v.panning) && Boolean(config);
2626

27-
usePanOnPressGesture(instance, {
27+
useDragOnPressGesture(instance, {
2828
config: config ?? undefined,
2929
enabled: isPanOnPressAndDragEnabled,
3030
onPan: (delta) => {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export { usePanGesture, type UsePanGestureOptions } from './usePanGesture';
1+
export { useDragGesture, type UseDragGestureOptions } from './useDragGesture';
2+
export { useDragOnPressGesture, type UseDragOnPressGestureOptions } from './useDragOnPressGesture';
23
export { useWheelGesture, type UseWheelGestureOptions } from './useWheelGesture';
34
export { usePinchGesture, type UsePinchGestureOptions } from './usePinchGesture';
45
export type { GestureInstance, PanGestureConfig, ChartPoint } from './zoomGestures.types';

packages/x-charts-pro/src/internals/plugins/zoomGestures/usePanGesture.ts renamed to packages/x-charts-pro/src/internals/plugins/zoomGestures/useDragGesture.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { rafThrottle } from '@mui/x-internals/rafThrottle';
44
import { type PanEvent } from '@mui/x-internal-gestures/core';
55
import { type ChartPoint, type GestureInstance, type PanGestureConfig } from './zoomGestures.types';
66

7-
export interface UsePanGestureOptions {
7+
export interface UseDragGestureOptions {
88
/** Whether the gesture is active. */
99
enabled: boolean;
1010
/** Pointer/keyboard gating forwarded to the interaction listener. */
@@ -34,7 +34,7 @@ export interface UsePanGestureOptions {
3434
* the rAF throttling. What to do with the delta is entirely up to `onPan` — cartesian
3535
* zoom translates an axis range, a map translates the projection, etc.
3636
*/
37-
export function usePanGesture(instance: GestureInstance, options: UsePanGestureOptions): void {
37+
export function useDragGesture(instance: GestureInstance, options: UseDragGestureOptions): void {
3838
const { enabled, config, onPanStart, onPan, onPanEnd } = options;
3939
const { chartsLayerContainerRef } = instance;
4040

packages/x-charts-pro/src/internals/plugins/zoomGestures/usePanOnPressGesture.ts renamed to packages/x-charts-pro/src/internals/plugins/zoomGestures/useDragOnPressGesture.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { rafThrottle } from '@mui/x-internals/rafThrottle';
44
import type { PanEvent } from '@mui/x-internal-gestures/core';
55
import type { ChartPoint, GestureInstance, PanGestureConfig } from './zoomGestures.types';
66

7-
export interface UsePanOnPressGestureOptions {
7+
export interface UseDragOnPressGestureOptions {
88
/** Whether the gesture is active. */
99
enabled: boolean;
1010
/** Pointer/keyboard gating forwarded to the interaction listener. */
@@ -28,15 +28,13 @@ export interface UsePanOnPressGestureOptions {
2828
}
2929

3030
/**
31-
* Generic drag-to-pan gesture binding, decoupled from any coordinate system.
31+
* Generic drag-to-pan gesture binding.
3232
*
33-
* It owns the listener lifecycle, the per-frame accumulation of the pixel delta, and
34-
* the rAF throttling. What to do with the delta is entirely up to `onPan` — cartesian
35-
* zoom translates an axis range, a map translates the projection, etc.
33+
* It owns the listener lifecycle, and allows the user to create their own interactions by providing the delta change of the interaction.
3634
*/
37-
export function usePanOnPressGesture(
35+
export function useDragOnPressGesture(
3836
instance: GestureInstance,
39-
options: UsePanOnPressGestureOptions,
37+
options: UseDragOnPressGestureOptions,
4038
): void {
4139
const { enabled, config, onPanStart, onPan, onPanEnd } = options;
4240
const { chartsLayerContainerRef } = instance;

packages/x-charts-pro/src/internals/plugins/zoomGestures/useWheelGesture.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22
import * as React from 'react';
3+
import { rafThrottle } from '@mui/x-internals/rafThrottle';
34
import { getChartPoint } from '@mui/x-charts/internals';
45
import { type KeyboardKey } from '@mui/x-internal-gestures/core';
56
import { type ChartPoint, type GestureInstance } from './zoomGestures.types';
@@ -45,6 +46,8 @@ export function useWheelGesture(instance: GestureInstance, options: UseWheelGest
4546
return () => {};
4647
}
4748

49+
const rafThrottledOnWheel = rafThrottle(onWheelRef.current);
50+
4851
const handler = instance.addInteractionListener('zoomTurnWheel', (event) => {
4952
const point = getChartPoint(element, {
5053
clientX: event.detail.centroid.x,
@@ -67,7 +70,7 @@ export function useWheelGesture(instance: GestureInstance, options: UseWheelGest
6770

6871
event.detail.srcEvent.preventDefault();
6972

70-
onWheelRef.current(point, event.detail.srcEvent as WheelEvent);
73+
rafThrottledOnWheel(point, event.detail.srcEvent as WheelEvent);
7174
});
7275

7376
return () => {
@@ -77,6 +80,7 @@ export function useWheelGesture(instance: GestureInstance, options: UseWheelGest
7780
startedOutsideTimeoutRef.current = null;
7881
}
7982
startedOutsideRef.current = false;
83+
rafThrottledOnWheel.clear();
8084
};
8185
}, [chartsLayerContainerRef, enabled, instance]);
8286
}

0 commit comments

Comments
 (0)