@mui/x-charts-pro 8.6.0 → 8.7.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 (78) hide show
  1. package/CHANGELOG.md +104 -1
  2. package/ChartContainerPro/index.d.ts +7 -1
  3. package/ChartContainerPro/index.js +0 -11
  4. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  5. package/ChartZoomSlider/index.d.ts +2 -1
  6. package/ChartZoomSlider/index.js +10 -2
  7. package/ChartZoomSlider/internals/ChartAxisZoomSlider.js +4 -0
  8. package/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +7 -1
  9. package/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +9 -1
  10. package/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.d.ts +15 -0
  11. package/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.js +31 -0
  12. package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +1 -1
  13. package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.js +1 -1
  14. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.js +43 -33
  15. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +3 -3
  16. package/{ChartContainerPro → context}/ChartProApi.d.ts +2 -3
  17. package/context/index.d.ts +2 -1
  18. package/context/index.js +4 -4
  19. package/context/useChartProApiContext.d.ts +9 -0
  20. package/context/{useChartApiContext.js → useChartProApiContext.js} +4 -4
  21. package/esm/ChartContainerPro/index.d.ts +7 -1
  22. package/esm/ChartContainerPro/index.js +4 -1
  23. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  24. package/esm/ChartZoomSlider/index.d.ts +2 -1
  25. package/esm/ChartZoomSlider/index.js +2 -1
  26. package/esm/ChartZoomSlider/internals/ChartAxisZoomSlider.js +4 -0
  27. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +8 -1
  28. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +10 -1
  29. package/esm/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.d.ts +15 -0
  30. package/esm/ChartZoomSlider/internals/chartAxisZoomSliderTrackClasses.js +21 -0
  31. package/esm/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +2 -2
  32. package/esm/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.js +2 -2
  33. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.js +43 -33
  34. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +3 -3
  35. package/esm/{ChartContainerPro → context}/ChartProApi.d.ts +2 -3
  36. package/esm/context/index.d.ts +2 -1
  37. package/esm/context/index.js +2 -1
  38. package/esm/context/useChartProApiContext.d.ts +9 -0
  39. package/esm/context/{useChartApiContext.js → useChartProApiContext.js} +3 -3
  40. package/esm/hooks/index.d.ts +2 -1
  41. package/esm/hooks/index.js +2 -1
  42. package/esm/hooks/useChartProApiRef.d.ts +23 -0
  43. package/esm/hooks/useChartProApiRef.js +20 -0
  44. package/esm/index.d.ts +4 -2
  45. package/esm/index.js +3 -3
  46. package/esm/internals/plugins/allPlugins.d.ts +2 -2
  47. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.ts +8 -0
  48. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +58 -0
  49. package/esm/internals/plugins/useChartProZoom/{useChartProZoom.utils.d.ts → gestureHooks/useZoom.utils.d.ts} +14 -10
  50. package/esm/internals/plugins/useChartProZoom/{useChartProZoom.utils.js → gestureHooks/useZoom.utils.js} +41 -31
  51. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.ts +8 -0
  52. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +59 -0
  53. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.ts +8 -0
  54. package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +79 -0
  55. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +15 -227
  56. package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +4 -4
  57. package/hooks/index.d.ts +2 -1
  58. package/hooks/index.js +11 -0
  59. package/hooks/useChartProApiRef.d.ts +23 -0
  60. package/hooks/useChartProApiRef.js +28 -0
  61. package/index.d.ts +4 -2
  62. package/index.js +58 -22
  63. package/internals/plugins/allPlugins.d.ts +2 -2
  64. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.d.ts +8 -0
  65. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +65 -0
  66. package/internals/plugins/useChartProZoom/{useChartProZoom.utils.d.ts → gestureHooks/useZoom.utils.d.ts} +14 -10
  67. package/internals/plugins/useChartProZoom/{useChartProZoom.utils.js → gestureHooks/useZoom.utils.js} +43 -34
  68. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.d.ts +8 -0
  69. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +66 -0
  70. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.d.ts +8 -0
  71. package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +86 -0
  72. package/internals/plugins/useChartProZoom/useChartProZoom.js +14 -226
  73. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +4 -4
  74. package/package.json +5 -4
  75. package/context/useChartApiContext.d.ts +0 -9
  76. package/esm/context/useChartApiContext.d.ts +0 -9
  77. /package/{ChartContainerPro → context}/ChartProApi.js +0 -0
  78. /package/esm/{ChartContainerPro → context}/ChartProApi.js +0 -0
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import { styled } from '@mui/material/styles';
3
5
  import { getSVGPoint, invertScale, selectorChartAxis, selectorChartAxisZoomOptionsLookup, useChartContext, useDrawingArea, useSelector, useStore } from '@mui/x-charts/internals';
@@ -8,6 +10,7 @@ import { ChartAxisZoomSliderThumb } from "./ChartAxisZoomSliderThumb.js";
8
10
  import { ChartsTooltipZoomSliderValue } from "./ChartsTooltipZoomSliderValue.js";
9
11
  import { calculateZoomEnd, calculateZoomFromPoint, calculateZoomStart } from "./zoom-utils.js";
10
12
  import { ZOOM_SLIDER_ACTIVE_TRACK_SIZE, ZOOM_SLIDER_THUMB_HEIGHT, ZOOM_SLIDER_THUMB_WIDTH } from "./constants.js";
13
+ import { useUtilityClasses } from "./chartAxisZoomSliderTrackClasses.js";
11
14
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
15
  const ZoomSliderActiveTrackRect = styled('rect')(({
13
16
  theme
@@ -41,6 +44,9 @@ export function ChartAxisZoomSliderActiveTrack({
41
44
  tooltipStart,
42
45
  tooltipEnd
43
46
  } = getZoomSliderTooltipsText(axis, drawingArea);
47
+ const classes = useUtilityClasses({
48
+ axisDirection
49
+ });
44
50
  const previewThumbWidth = axisDirection === 'x' ? ZOOM_SLIDER_THUMB_WIDTH : ZOOM_SLIDER_THUMB_HEIGHT;
45
51
  const previewThumbHeight = axisDirection === 'x' ? ZOOM_SLIDER_THUMB_HEIGHT : ZOOM_SLIDER_THUMB_WIDTH;
46
52
  React.useEffect(() => {
@@ -194,7 +200,8 @@ export function ChartAxisZoomSliderActiveTrack({
194
200
  width: previewWidth,
195
201
  height: previewHeight,
196
202
  onPointerEnter: onPointerEnter,
197
- onPointerLeave: onPointerLeave
203
+ onPointerLeave: onPointerLeave,
204
+ className: classes.active
198
205
  }), /*#__PURE__*/_jsx(ChartAxisZoomSliderThumb, {
199
206
  ref: setStartThumbEl,
200
207
  x: startThumbX,
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
5
  const _excluded = ["axisId", "axisDirection", "reverse", "onSelectStart", "onSelectEnd"];
@@ -6,7 +8,9 @@ import { useChartContext, getSVGPoint, selectorChartAxisZoomOptionsLookup, useSt
6
8
  import { styled } from '@mui/material/styles';
7
9
  import { rafThrottle } from '@mui/x-internals/rafThrottle';
8
10
  import { shouldForwardProp } from '@mui/system';
11
+ import clsx from 'clsx';
9
12
  import { calculateZoomEnd, calculateZoomFromPoint, calculateZoomStart } from "./zoom-utils.js";
13
+ import { useUtilityClasses } from "./chartAxisZoomSliderTrackClasses.js";
10
14
  import { jsx as _jsx } from "react/jsx-runtime";
11
15
  const ZoomSliderTrack = styled('rect', {
12
16
  shouldForwardProp: prop => shouldForwardProp(prop) && prop !== 'axisDirection' && prop !== 'isSelecting'
@@ -48,6 +52,9 @@ export function ChartAxisZoomSliderTrack(_ref) {
48
52
  } = useChartContext();
49
53
  const store = useStore();
50
54
  const [isSelecting, setIsSelecting] = React.useState(false);
55
+ const classes = useUtilityClasses({
56
+ axisDirection
57
+ });
51
58
  const onPointerDown = function onPointerDown(event) {
52
59
  const rect = ref.current;
53
60
  const element = svgRef.current;
@@ -119,5 +126,7 @@ export function ChartAxisZoomSliderTrack(_ref) {
119
126
  onPointerDown: onPointerDown,
120
127
  axisDirection: axisDirection,
121
128
  isSelecting: isSelecting
122
- }, other));
129
+ }, other, {
130
+ className: clsx(classes.background, other.className)
131
+ }));
123
132
  }
@@ -0,0 +1,15 @@
1
+ import type { ChartAxisZoomSliderActiveTrackProps } from "./ChartAxisZoomSliderActiveTrack.js";
2
+ export interface ChartAxisZoomSliderTrackClasses {
3
+ /** Styles applied to the root element when it is horizontal. */
4
+ horizontal: string;
5
+ /** Styles applied to the root element when it is vertical. */
6
+ vertical: string;
7
+ /** Styles applied to the root element to the active part of the track. */
8
+ active: string;
9
+ /** Styles applied to the root element to the background part of the track. */
10
+ background: string;
11
+ }
12
+ export type ChartAxisZoomSliderTrackClassKey = keyof ChartAxisZoomSliderTrackClasses;
13
+ export declare const chartAxisZoomSliderTrackClasses: ChartAxisZoomSliderTrackClasses;
14
+ export declare function getAxisZoomSliderTrackUtilityClass(slot: string): string;
15
+ export declare const useUtilityClasses: (props: Partial<ChartAxisZoomSliderActiveTrackProps>) => Record<"background" | "active", string>;
@@ -0,0 +1,21 @@
1
+ import composeClasses from '@mui/utils/composeClasses';
2
+ import ClassNameGenerator from '@mui/utils/ClassNameGenerator';
3
+ export const chartAxisZoomSliderTrackClasses = ['horizontal', 'vertical', 'background', 'active'].reduce((acc, slot) => {
4
+ acc[slot] = getAxisZoomSliderTrackUtilityClass(slot);
5
+ return acc;
6
+ }, {});
7
+ export function getAxisZoomSliderTrackUtilityClass(slot) {
8
+ // We use the `ClassNameGenerator` because the original `generateUtilityClass` function
9
+ // has a special case for the `active` slot.
10
+ return `${ClassNameGenerator.generate('MuiChartAxisZoomSliderTrack')}-${slot}`;
11
+ }
12
+ export const useUtilityClasses = props => {
13
+ const {
14
+ axisDirection
15
+ } = props;
16
+ const slots = {
17
+ background: [axisDirection === 'x' ? 'horizontal' : 'vertical', 'background'],
18
+ active: [axisDirection === 'x' ? 'horizontal' : 'vertical', 'active']
19
+ };
20
+ return composeClasses(slots, getAxisZoomSliderTrackUtilityClass);
21
+ };
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
6
6
  import { forwardRef } from '@mui/x-internals/forwardRef';
7
7
  import { useComponentRenderer } from '@mui/x-internals/useComponentRenderer';
8
8
  import { useChartsSlots } from '@mui/x-charts/internals';
9
- import { useChartApiContext } from "../context/index.js";
9
+ import { useChartProApiContext } from "../context/index.js";
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  /**
12
12
  * A button that triggers an image export.
@@ -27,7 +27,7 @@ const ChartsToolbarImageExportTrigger = forwardRef(function ChartsToolbarImageEx
27
27
  slots,
28
28
  slotProps
29
29
  } = useChartsSlots();
30
- const apiRef = useChartApiContext();
30
+ const apiRef = useChartProApiContext();
31
31
  const handleClick = event => {
32
32
  apiRef.current.exportAsImage(options);
33
33
  onClick?.(event);
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
6
6
  import { forwardRef } from '@mui/x-internals/forwardRef';
7
7
  import { useComponentRenderer } from '@mui/x-internals/useComponentRenderer';
8
8
  import { useChartsSlots } from '@mui/x-charts/internals';
9
- import { useChartApiContext } from "../context/index.js";
9
+ import { useChartProApiContext } from "../context/index.js";
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  /**
12
12
  * A button that triggers a print export.
@@ -27,7 +27,7 @@ const ChartsToolbarPrintExportTrigger = forwardRef(function ChartsToolbarPrintEx
27
27
  slots,
28
28
  slotProps
29
29
  } = useChartsSlots();
30
- const apiRef = useChartApiContext();
30
+ const apiRef = useChartProApiContext();
31
31
  const handleClick = event => {
32
32
  apiRef.current.exportAsPrint(options);
33
33
  onClick?.(event);
@@ -45,39 +45,51 @@ export const useChartFunnelAxis = ({
45
45
  }, [seriesConfig, drawingArea, xAxis, yAxis, dataset, store, gap]);
46
46
  React.useEffect(() => {
47
47
  const element = svgRef.current;
48
- if (!isInteractionEnabled || element === null || params.disableAxisListener) {
48
+ if (!isInteractionEnabled || !element || params.disableAxisListener) {
49
49
  return () => {};
50
50
  }
51
- const handleOut = () => {
52
- instance.cleanInteraction?.();
53
- };
54
- const handleMove = event => {
55
- const target = 'targetTouches' in event ? event.targetTouches[0] : event;
56
- const svgPoint = getSVGPoint(element, target);
57
- if (!instance.isPointInside(svgPoint.x, svgPoint.y, event.target)) {
51
+
52
+ // Clean the interaction when the mouse leaves the chart.
53
+ const moveEndHandler = instance.addInteractionListener('moveEnd', event => {
54
+ if (!event.detail.activeGestures.pan) {
58
55
  instance.cleanInteraction?.();
59
- return;
60
56
  }
61
- instance.setPointerCoordinate?.(svgPoint);
62
- };
63
- const handleDown = event => {
64
- const target = event.currentTarget;
65
- if (!target) {
66
- return;
57
+ });
58
+ const panEndHandler = instance.addInteractionListener('panEnd', event => {
59
+ if (!event.detail.activeGestures.move) {
60
+ instance.cleanInteraction?.();
67
61
  }
68
- if ('hasPointerCapture' in target && target.hasPointerCapture(event.pointerId)) {
69
- target.releasePointerCapture(event.pointerId);
62
+ });
63
+ const pressEndHandler = instance.addInteractionListener('quickPressEnd', event => {
64
+ if (!event.detail.activeGestures.move && !event.detail.activeGestures.pan) {
65
+ instance.cleanInteraction?.();
66
+ }
67
+ });
68
+ const gestureHandler = event => {
69
+ const srvEvent = event.detail.srcEvent;
70
+ const target = event.detail.target;
71
+ const svgPoint = getSVGPoint(element, srvEvent);
72
+ // Release the pointer capture if we are panning, as this would cause the tooltip to
73
+ // be locked to the first "section" it touches.
74
+ if (event.detail.srcEvent.buttons >= 1 && target?.hasPointerCapture(event.detail.srcEvent.pointerId)) {
75
+ target?.releasePointerCapture(event.detail.srcEvent.pointerId);
70
76
  }
77
+ if (!instance.isPointInside(svgPoint.x, svgPoint.y, target)) {
78
+ instance.cleanInteraction?.();
79
+ return;
80
+ }
81
+ instance.setPointerCoordinate?.(svgPoint);
71
82
  };
72
- element.addEventListener('pointerdown', handleDown);
73
- element.addEventListener('pointermove', handleMove);
74
- element.addEventListener('pointercancel', handleOut);
75
- element.addEventListener('pointerleave', handleOut);
83
+ const moveHandler = instance.addInteractionListener('move', gestureHandler);
84
+ const panHandler = instance.addInteractionListener('pan', gestureHandler);
85
+ const pressHandler = instance.addInteractionListener('quickPress', gestureHandler);
76
86
  return () => {
77
- element.removeEventListener('pointerdown', handleDown);
78
- element.removeEventListener('pointermove', handleMove);
79
- element.removeEventListener('pointercancel', handleOut);
80
- element.removeEventListener('pointerleave', handleOut);
87
+ moveHandler.cleanup();
88
+ moveEndHandler.cleanup();
89
+ panHandler.cleanup();
90
+ panEndHandler.cleanup();
91
+ pressHandler.cleanup();
92
+ pressEndHandler.cleanup();
81
93
  };
82
94
  }, [svgRef, instance, params.disableAxisListener, isInteractionEnabled]);
83
95
  React.useEffect(() => {
@@ -86,8 +98,7 @@ export const useChartFunnelAxis = ({
86
98
  if (element === null || !onAxisClick) {
87
99
  return () => {};
88
100
  }
89
- const handleMouseClick = event => {
90
- event.preventDefault();
101
+ const axisClickHandler = instance.addInteractionListener('tap', event => {
91
102
  const {
92
103
  axis: xAxisWithScale,
93
104
  axisIds: xAxisIds
@@ -101,7 +112,7 @@ export const useChartFunnelAxis = ({
101
112
  const usedYAxis = yAxisIds[0];
102
113
  let dataIndex = null;
103
114
  let isXAxis = false;
104
- const svgPoint = getSVGPoint(element, event);
115
+ const svgPoint = getSVGPoint(element, event.detail.srcEvent);
105
116
  const xIndex = getCartesianAxisIndex(xAxisWithScale[usedXAxis], svgPoint.x);
106
117
  isXAxis = xIndex !== -1;
107
118
  dataIndex = isXAxis ? xIndex : getCartesianAxisIndex(yAxisWithScale[usedYAxis], svgPoint.y);
@@ -122,17 +133,16 @@ export const useChartFunnelAxis = ({
122
133
  seriesValues[seriesId] = seriesItem.data[dataIndex].value;
123
134
  }
124
135
  });
125
- onAxisClick(event, {
136
+ onAxisClick(event.detail.srcEvent, {
126
137
  dataIndex,
127
138
  axisValue,
128
139
  seriesValues
129
140
  });
130
- };
131
- element.addEventListener('click', handleMouseClick);
141
+ });
132
142
  return () => {
133
- element.removeEventListener('click', handleMouseClick);
143
+ axisClickHandler.cleanup();
134
144
  };
135
- }, [params.onAxisClick, svgRef, store]);
145
+ }, [params.onAxisClick, svgRef, store, instance]);
136
146
  return {};
137
147
  };
138
148
  useChartFunnelAxis.params = {
@@ -3,7 +3,7 @@ import { UseChartFunnelAxisSignature } from "./useChartFunnelAxis.types.js";
3
3
  export declare const selectorFunnel: (state: ChartState<[], [UseChartFunnelAxisSignature]>) => {
4
4
  gap: number;
5
5
  } | undefined;
6
- export declare const selectorFunnelGap: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & Partial<Pick<import("@mui/x-charts/internals").UseChartCartesianAxisState, "cartesianAxis"> & {
6
+ export declare const selectorFunnelGap: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & Partial<Pick<import("@mui/x-charts/internals").UseChartCartesianAxisState, "cartesianAxis"> & {
7
7
  funnel: {
8
8
  gap: number;
9
9
  };
@@ -12,7 +12,7 @@ export declare const selectorFunnelGap: import("reselect").Selector<import("@mui
12
12
  } & {
13
13
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
14
14
  }, number, []>;
15
- export declare const selectorChartXAxis: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & Partial<import("@mui/x-charts/internals").UseChartCartesianAxisState> & {
15
+ export declare const selectorChartXAxis: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & Partial<import("@mui/x-charts/internals").UseChartCartesianAxisState> & {
16
16
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
17
17
  } & Partial<{}> & {
18
18
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
@@ -33,7 +33,7 @@ export declare const selectorChartXAxis: import("reselect").Selector<import("@mu
33
33
  }> & {
34
34
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
35
35
  }, import("./computeAxisValue.js").ComputeResult<import("@mui/x-charts").ChartsXAxisProps>, []>;
36
- export declare const selectorChartYAxis: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & Partial<import("@mui/x-charts/internals").UseChartCartesianAxisState> & {
36
+ export declare const selectorChartYAxis: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & Partial<import("@mui/x-charts/internals").UseChartCartesianAxisState> & {
37
37
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
38
38
  } & Partial<{}> & {
39
39
  cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
@@ -7,7 +7,7 @@ import { AllPluginSignatures, DefaultPluginSignatures } from "../internals/plugi
7
7
  import { FunnelChartPluginsSignatures } from "../FunnelChart/FunnelChart.plugins.js";
8
8
  import { RadarChartProPluginsSignatures } from "../RadarChartPro/RadarChartPro.plugins.js";
9
9
  import { PieChartProPluginSignatures } from "../PieChartPro/PieChartPro.plugins.js";
10
- type PluginsPerSeriesType = {
10
+ export type ProPluginsPerSeriesType = {
11
11
  heatmap: HeatmapPluginsSignatures;
12
12
  line: LineChartProPluginsSignatures;
13
13
  scatter: ScatterChartProPluginsSignatures;
@@ -24,5 +24,4 @@ type PluginsPerSeriesType = {
24
24
  * If the chart is being created using composition, the `composition` value can be used.
25
25
  * @example ChartProApi<'composition'>
26
26
  */
27
- export type ChartProApi<TSeries extends keyof PluginsPerSeriesType | undefined = undefined, TSignatures extends readonly ChartAnyPluginSignature[] = (TSeries extends keyof PluginsPerSeriesType ? PluginsPerSeriesType[TSeries] : AllPluginSignatures)> = ChartPublicAPI<TSignatures>;
28
- export {};
27
+ export type ChartProApi<ChartType extends keyof ProPluginsPerSeriesType | undefined = undefined, Signatures extends readonly ChartAnyPluginSignature[] = (ChartType extends keyof ProPluginsPerSeriesType ? ProPluginsPerSeriesType[ChartType] : AllPluginSignatures)> = ChartPublicAPI<Signatures>;
@@ -1 +1,2 @@
1
- export * from "./useChartApiContext.js";
1
+ export * from "./useChartProApiContext.js";
2
+ export type { ChartProApi } from "./ChartProApi.js";
@@ -1 +1,2 @@
1
- export * from "./useChartApiContext.js";
1
+ export * from "./useChartProApiContext.js";
2
+ export {};
@@ -0,0 +1,9 @@
1
+ import { ChartProApi } from "./ChartProApi.js";
2
+ /**
3
+ * The `useChartProApiContext` hook provides access to the chart API.
4
+ * This is only available when the chart is rendered within a chart or a `ChartDataProvider` component.
5
+ * If you want to access the chart API outside those components, you should use the `apiRef` prop instead.
6
+ * @example
7
+ * const apiRef = useChartProApiContext<ChartProApi<'bar'>>();
8
+ */
9
+ export declare function useChartProApiContext<Api extends ChartProApi>(): import("react").RefObject<Api>;
@@ -1,11 +1,11 @@
1
1
  import { useChartApiContext as useChartApiContextCommunity } from '@mui/x-charts/context';
2
2
  /**
3
- * The `useChartApiContext` hook provides access to the chart API.
3
+ * The `useChartProApiContext` hook provides access to the chart API.
4
4
  * This is only available when the chart is rendered within a chart or a `ChartDataProvider` component.
5
5
  * If you want to access the chart API outside those components, you should use the `apiRef` prop instead.
6
6
  * @example
7
- * const apiRef = useChartApiContext<ChartProApi<'bar'>>();
7
+ * const apiRef = useChartProApiContext<ChartProApi<'bar'>>();
8
8
  */
9
- export function useChartApiContext() {
9
+ export function useChartProApiContext() {
10
10
  return useChartApiContextCommunity();
11
11
  }
@@ -1,3 +1,4 @@
1
1
  export * from "./useHeatmapSeries.js";
2
2
  export * from "./useFunnelSeries.js";
3
- export * from "./zoom/index.js";
3
+ export * from "./zoom/index.js";
4
+ export * from "./useChartProApiRef.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./useHeatmapSeries.js";
2
2
  export * from "./useFunnelSeries.js";
3
- export * from "./zoom/index.js";
3
+ export * from "./zoom/index.js";
4
+ export * from "./useChartProApiRef.js";
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ import { ChartAnyPluginSignature } from '@mui/x-charts/internals';
3
+ import { AllPluginSignatures } from "../internals/plugins/allPlugins.js";
4
+ import { ProPluginsPerSeriesType, type ChartProApi } from "../context/ChartProApi.js";
5
+ /**
6
+ * Hook that instantiates a [[ChartProApiRef]].
7
+ * The chart type needs to be given as the generic parameter to narrow down the API to the specific chart type.
8
+ * @example
9
+ * ```tsx
10
+ * const barApiRef = useChartProApiRef<'bar'>();
11
+ * ```
12
+ * @example
13
+ * ```tsx
14
+ * // The API can be passed to the chart component and used to interact with the chart.
15
+ * <BarChart apiRef={barApiRef} />
16
+ * ```
17
+ * @example
18
+ * ```tsx
19
+ * // The API can be used to access chart methods and properties.
20
+ * barApiRef.current?.getSeries();
21
+ * ```
22
+ */
23
+ export declare const useChartProApiRef: <ChartType extends keyof ProPluginsPerSeriesType = never, Signatures extends readonly ChartAnyPluginSignature[] = (ChartType extends keyof ProPluginsPerSeriesType ? ProPluginsPerSeriesType[ChartType] : AllPluginSignatures)>() => React.RefObject<ChartProApi<ChartType, Signatures> | undefined>;
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Hook that instantiates a [[ChartProApiRef]].
4
+ * The chart type needs to be given as the generic parameter to narrow down the API to the specific chart type.
5
+ * @example
6
+ * ```tsx
7
+ * const barApiRef = useChartProApiRef<'bar'>();
8
+ * ```
9
+ * @example
10
+ * ```tsx
11
+ * // The API can be passed to the chart component and used to interact with the chart.
12
+ * <BarChart apiRef={barApiRef} />
13
+ * ```
14
+ * @example
15
+ * ```tsx
16
+ * // The API can be used to access chart methods and properties.
17
+ * barApiRef.current?.getSeries();
18
+ * ```
19
+ */
20
+ export const useChartProApiRef = () => React.useRef(undefined);
package/esm/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./typeOverloads/modules.js";
2
2
  export * from '@mui/x-charts/constants';
3
- export * from '@mui/x-charts/context';
3
+ export type { FadeOptions, HighlightItemData, HighlightOptions, HighlightScope } from '@mui/x-charts/context';
4
4
  export * from '@mui/x-charts/hooks';
5
5
  export * from '@mui/x-charts/colorPalettes';
6
6
  export * from '@mui/x-charts/models';
@@ -26,9 +26,11 @@ export * from '@mui/x-charts/ChartsSurface';
26
26
  export * from '@mui/x-charts/ChartDataProvider';
27
27
  export * from '@mui/x-charts/ChartsLabel';
28
28
  export type { ZoomData, ZoomFilterMode, ZoomSliderShowTooltip, ZoomOptions, ZoomSliderOptions } from '@mui/x-charts/internals';
29
+ export * from "./context/index.js";
29
30
  export * from "./hooks/index.js";
30
31
  export * from "./Heatmap/index.js";
31
- export * from "./ChartContainerPro/index.js";
32
+ export { ChartContainerPro } from "./ChartContainerPro/index.js";
33
+ export type { ChartContainerProProps } from "./ChartContainerPro/index.js";
32
34
  export * from "./ChartDataProviderPro/index.js";
33
35
  export * from "./ScatterChartPro/index.js";
34
36
  export * from "./BarChartPro/index.js";
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts-pro v8.6.0
2
+ * @mui/x-charts-pro v8.7.0
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -9,7 +9,6 @@ import "./typeOverloads/modules.js";
9
9
 
10
10
  // exports from MIT package
11
11
  export * from '@mui/x-charts/constants';
12
- export * from '@mui/x-charts/context';
13
12
  export * from '@mui/x-charts/hooks';
14
13
  export * from '@mui/x-charts/colorPalettes';
15
14
  export * from '@mui/x-charts/models';
@@ -35,9 +34,10 @@ export * from '@mui/x-charts/ChartsSurface';
35
34
  export * from '@mui/x-charts/ChartDataProvider';
36
35
  export * from '@mui/x-charts/ChartsLabel';
37
36
  // Pro components
37
+ export * from "./context/index.js";
38
38
  export * from "./hooks/index.js";
39
39
  export * from "./Heatmap/index.js";
40
- export * from "./ChartContainerPro/index.js";
40
+ export { ChartContainerPro } from "./ChartContainerPro/index.js";
41
41
  export * from "./ChartDataProviderPro/index.js";
42
42
  export * from "./ScatterChartPro/index.js";
43
43
  export * from "./BarChartPro/index.js";
@@ -3,7 +3,7 @@ import { UseChartProExportSignature } from "./useChartProExport/index.js";
3
3
  import { UseChartProZoomSignature } from "./useChartProZoom/index.js";
4
4
  export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature, UseChartProExportSignature];
5
5
  export type AllPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<AllPluginSignatures<TSeries>>;
6
- export declare const ALL_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartProExportSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>> | import("@mui/x-charts/internals").ChartPlugin<UseChartPolarAxisSignature<any>>)[];
6
+ export declare const ALL_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProExportSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>> | import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartPolarAxisSignature<any>>)[];
7
7
  export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProZoomSignature, UseChartProExportSignature];
8
8
  export type DefaultPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<DefaultPluginSignatures<TSeries>>;
9
- export declare const DEFAULT_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartProExportSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>>)[];
9
+ export declare const DEFAULT_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProExportSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<any>> | import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature>)[];
@@ -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 usePanOnDrag: ({
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,58 @@
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
+ export const usePanOnDrag = ({
8
+ store,
9
+ instance,
10
+ svgRef
11
+ }, setZoomDataCallback) => {
12
+ const drawingArea = useSelector(store, selectorChartDrawingArea);
13
+ const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
14
+ const startRef = React.useRef(null);
15
+
16
+ // Add event for chart panning
17
+ const isPanEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) || false, [optionsLookup]);
18
+ React.useEffect(() => {
19
+ const element = svgRef.current;
20
+ if (element === null || !isPanEnabled) {
21
+ return () => {};
22
+ }
23
+ const handlePanStart = event => {
24
+ if (!event.detail.target?.closest('[data-charts-zoom-slider]')) {
25
+ startRef.current = store.value.zoom.zoomData;
26
+ }
27
+ };
28
+ const handlePanEnd = () => {
29
+ startRef.current = null;
30
+ };
31
+ const throttledCallback = rafThrottle((event, zoomData) => {
32
+ const newZoomData = translateZoom(zoomData, {
33
+ x: event.detail.activeDeltaX,
34
+ y: -event.detail.activeDeltaY
35
+ }, {
36
+ width: drawingArea.width,
37
+ height: drawingArea.height
38
+ }, optionsLookup);
39
+ setZoomDataCallback(newZoomData);
40
+ });
41
+ const handlePan = event => {
42
+ const zoomData = startRef.current;
43
+ if (!zoomData) {
44
+ return;
45
+ }
46
+ throttledCallback(event, zoomData);
47
+ };
48
+ const panHandler = instance.addInteractionListener('pan', handlePan);
49
+ const panStartHandler = instance.addInteractionListener('panStart', handlePanStart);
50
+ const panEndHandler = instance.addInteractionListener('panEnd', handlePanEnd);
51
+ return () => {
52
+ panStartHandler.cleanup();
53
+ panHandler.cleanup();
54
+ panEndHandler.cleanup();
55
+ throttledCallback.clear();
56
+ };
57
+ }, [instance, svgRef, isPanEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, startRef]);
58
+ };
@@ -17,14 +17,6 @@ export declare function getWheelScaleRatio(event: WheelEvent, step: number): {
17
17
  scaleRatio: number;
18
18
  isZoomIn: boolean;
19
19
  };
20
- /**
21
- * Get the scale ratio and if it's a zoom in or out from a pinch gesture.
22
- */
23
- export declare function getPinchScaleRatio(curDiff: number, prevDiff: number, step: number): {
24
- scaleRatio: number;
25
- isZoomIn: boolean;
26
- };
27
- export declare function getDiff(eventCache: PointerEvent[]): number;
28
20
  /**
29
21
  * Get the ratio of the point in the horizontal center of the area.
30
22
  */
@@ -35,11 +27,23 @@ export declare function getHorizontalCenterRatio(point: {
35
27
  left: number;
36
28
  width: number;
37
29
  }): number;
38
- export declare function preventDefault(event: TouchEvent): void;
30
+ /**
31
+ * Get the ratio of the point in the vertical center of the area.
32
+ */
39
33
  export declare function getVerticalCenterRatio(point: {
40
34
  x: number;
41
35
  y: number;
42
36
  }, area: {
43
37
  top: number;
44
38
  height: number;
45
- }): number;
39
+ }): number;
40
+ /**
41
+ * Translate the zoom data by a given movement.
42
+ */
43
+ export declare function translateZoom(initialZoomData: readonly ZoomData[], movement: {
44
+ x: number;
45
+ y: number;
46
+ }, drawingArea: {
47
+ width: number;
48
+ height: number;
49
+ }, optionsLookup: Record<string | number, DefaultizedZoomOptions>): ZoomData[];