@mui/x-charts-pro 8.0.0-alpha.6 → 8.0.0-alpha.8

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 (157) hide show
  1. package/BarChartPro/BarChartPro.d.ts +2 -2
  2. package/BarChartPro/BarChartPro.js +68 -23
  3. package/CHANGELOG.md +242 -1
  4. package/ChartContainerPro/ChartContainerPro.d.ts +32 -4
  5. package/ChartContainerPro/ChartContainerPro.js +53 -18
  6. package/ChartContainerPro/useChartContainerProProps.d.ts +5 -5
  7. package/ChartContainerPro/useChartContainerProProps.js +11 -5
  8. package/Heatmap/Heatmap.js +28 -2
  9. package/Heatmap/HeatmapTooltip.js +6 -4
  10. package/Heatmap/extremums.d.ts +2 -2
  11. package/Heatmap/formatter.d.ts +2 -2
  12. package/Heatmap/formatter.js +2 -1
  13. package/Heatmap/plugin.d.ts +2 -2
  14. package/Heatmap/plugin.js +1 -2
  15. package/LineChartPro/LineChartPro.d.ts +2 -2
  16. package/LineChartPro/LineChartPro.js +73 -32
  17. package/ScatterChartPro/ScatterChartPro.d.ts +2 -2
  18. package/ScatterChartPro/ScatterChartPro.js +46 -28
  19. package/hooks/index.d.ts +1 -0
  20. package/hooks/index.js +2 -1
  21. package/hooks/zoom/index.d.ts +1 -0
  22. package/hooks/zoom/index.js +1 -0
  23. package/hooks/zoom/useIsZoomInteracting.d.ts +6 -0
  24. package/hooks/zoom/useIsZoomInteracting.js +14 -0
  25. package/index.d.ts +0 -1
  26. package/index.js +2 -5
  27. package/internals/plugins/allPlugins.d.ts +10 -0
  28. package/internals/plugins/allPlugins.js +5 -0
  29. package/internals/plugins/useChartProZoom/defaultizeZoom.d.ts +2 -0
  30. package/internals/plugins/useChartProZoom/defaultizeZoom.js +25 -0
  31. package/internals/plugins/useChartProZoom/index.d.ts +3 -0
  32. package/internals/plugins/useChartProZoom/index.js +3 -0
  33. package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +3 -0
  34. package/internals/plugins/useChartProZoom/useChartProZoom.js +324 -0
  35. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +149 -0
  36. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +6 -0
  37. package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +54 -0
  38. package/internals/plugins/useChartProZoom/useChartProZoom.utils.d.ts +45 -0
  39. package/internals/plugins/useChartProZoom/useChartProZoom.utils.js +126 -0
  40. package/internals/plugins/useChartProZoom/zoom.types.d.ts +53 -0
  41. package/internals/utils/releaseInfo.js +1 -1
  42. package/models/index.d.ts +1 -0
  43. package/models/index.js +2 -1
  44. package/modern/BarChartPro/BarChartPro.js +68 -23
  45. package/modern/ChartContainerPro/ChartContainerPro.js +53 -18
  46. package/modern/ChartContainerPro/useChartContainerProProps.js +11 -5
  47. package/modern/Heatmap/Heatmap.js +28 -2
  48. package/modern/Heatmap/HeatmapTooltip.js +6 -4
  49. package/modern/Heatmap/formatter.js +2 -1
  50. package/modern/Heatmap/plugin.js +1 -2
  51. package/modern/LineChartPro/LineChartPro.js +73 -32
  52. package/modern/ScatterChartPro/ScatterChartPro.js +46 -28
  53. package/modern/hooks/index.js +2 -1
  54. package/modern/hooks/zoom/index.js +1 -0
  55. package/modern/hooks/zoom/useIsZoomInteracting.js +14 -0
  56. package/modern/index.js +2 -5
  57. package/modern/internals/plugins/allPlugins.js +5 -0
  58. package/modern/internals/plugins/useChartProZoom/defaultizeZoom.js +25 -0
  59. package/modern/internals/plugins/useChartProZoom/index.js +3 -0
  60. package/modern/internals/plugins/useChartProZoom/useChartProZoom.js +324 -0
  61. package/modern/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +6 -0
  62. package/modern/internals/plugins/useChartProZoom/useChartProZoom.types.js +1 -0
  63. package/modern/internals/plugins/useChartProZoom/useChartProZoom.utils.js +126 -0
  64. package/modern/internals/plugins/useChartProZoom/zoom.types.js +1 -0
  65. package/modern/internals/utils/releaseInfo.js +1 -1
  66. package/modern/models/index.js +2 -1
  67. package/node/BarChartPro/BarChartPro.js +67 -22
  68. package/node/ChartContainerPro/ChartContainerPro.js +53 -18
  69. package/node/ChartContainerPro/useChartContainerProProps.js +11 -5
  70. package/node/Heatmap/Heatmap.js +28 -2
  71. package/node/Heatmap/HeatmapTooltip.js +4 -2
  72. package/node/Heatmap/formatter.js +2 -1
  73. package/node/Heatmap/plugin.js +1 -2
  74. package/node/LineChartPro/LineChartPro.js +72 -31
  75. package/node/ScatterChartPro/ScatterChartPro.js +44 -26
  76. package/node/hooks/index.js +16 -1
  77. package/node/{context/CartesianProviderPro → hooks/zoom}/index.js +4 -4
  78. package/node/hooks/zoom/useIsZoomInteracting.js +19 -0
  79. package/node/index.js +1 -12
  80. package/node/internals/plugins/allPlugins.js +11 -0
  81. package/node/internals/plugins/useChartProZoom/defaultizeZoom.js +33 -0
  82. package/node/internals/plugins/useChartProZoom/index.js +38 -0
  83. package/node/internals/plugins/useChartProZoom/useChartProZoom.js +331 -0
  84. package/node/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +13 -0
  85. package/node/internals/plugins/useChartProZoom/useChartProZoom.utils.js +140 -0
  86. package/node/internals/plugins/useChartProZoom/zoom.types.js +5 -0
  87. package/node/internals/utils/releaseInfo.js +1 -1
  88. package/package.json +5 -5
  89. package/typeOverloads/modules.d.ts +8 -1
  90. package/context/CartesianProviderPro/CartesianProviderPro.d.ts +0 -6
  91. package/context/CartesianProviderPro/CartesianProviderPro.js +0 -89
  92. package/context/CartesianProviderPro/createAxisFilterMapper.d.ts +0 -13
  93. package/context/CartesianProviderPro/createAxisFilterMapper.js +0 -60
  94. package/context/CartesianProviderPro/index.d.ts +0 -1
  95. package/context/CartesianProviderPro/index.js +0 -1
  96. package/context/ChartDataProviderPro/ChartDataProviderPro.d.ts +0 -7
  97. package/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -50
  98. package/context/ChartDataProviderPro/index.d.ts +0 -1
  99. package/context/ChartDataProviderPro/index.js +0 -1
  100. package/context/ChartDataProviderPro/useChartDataProviderProProps.d.ts +0 -14
  101. package/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -43
  102. package/context/ZoomProvider/Zoom.types.d.ts +0 -144
  103. package/context/ZoomProvider/ZoomContext.d.ts +0 -4
  104. package/context/ZoomProvider/ZoomContext.js +0 -16
  105. package/context/ZoomProvider/ZoomProvider.d.ts +0 -3
  106. package/context/ZoomProvider/ZoomProvider.js +0 -56
  107. package/context/ZoomProvider/ZoomSetup.d.ts +0 -9
  108. package/context/ZoomProvider/ZoomSetup.js +0 -16
  109. package/context/ZoomProvider/defaultizeZoom.d.ts +0 -2
  110. package/context/ZoomProvider/defaultizeZoom.js +0 -32
  111. package/context/ZoomProvider/index.d.ts +0 -3
  112. package/context/ZoomProvider/index.js +0 -3
  113. package/context/ZoomProvider/initializeZoomData.d.ts +0 -6
  114. package/context/ZoomProvider/initializeZoomData.js +0 -13
  115. package/context/ZoomProvider/useSetupPan.d.ts +0 -1
  116. package/context/ZoomProvider/useSetupPan.js +0 -106
  117. package/context/ZoomProvider/useSetupZoom.d.ts +0 -1
  118. package/context/ZoomProvider/useSetupZoom.js +0 -274
  119. package/context/ZoomProvider/useZoom.d.ts +0 -7
  120. package/context/ZoomProvider/useZoom.js +0 -19
  121. package/context/index.d.ts +0 -3
  122. package/context/index.js +0 -5
  123. package/context/package.json +0 -6
  124. package/modern/context/CartesianProviderPro/CartesianProviderPro.js +0 -89
  125. package/modern/context/CartesianProviderPro/createAxisFilterMapper.js +0 -60
  126. package/modern/context/CartesianProviderPro/index.js +0 -1
  127. package/modern/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -50
  128. package/modern/context/ChartDataProviderPro/index.js +0 -1
  129. package/modern/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -43
  130. package/modern/context/ZoomProvider/ZoomContext.js +0 -16
  131. package/modern/context/ZoomProvider/ZoomProvider.js +0 -56
  132. package/modern/context/ZoomProvider/ZoomSetup.js +0 -16
  133. package/modern/context/ZoomProvider/defaultizeZoom.js +0 -32
  134. package/modern/context/ZoomProvider/index.js +0 -3
  135. package/modern/context/ZoomProvider/initializeZoomData.js +0 -13
  136. package/modern/context/ZoomProvider/useSetupPan.js +0 -106
  137. package/modern/context/ZoomProvider/useSetupZoom.js +0 -274
  138. package/modern/context/ZoomProvider/useZoom.js +0 -19
  139. package/modern/context/index.js +0 -5
  140. package/node/context/CartesianProviderPro/CartesianProviderPro.js +0 -95
  141. package/node/context/CartesianProviderPro/createAxisFilterMapper.js +0 -68
  142. package/node/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -56
  143. package/node/context/ChartDataProviderPro/index.js +0 -16
  144. package/node/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -50
  145. package/node/context/ZoomProvider/ZoomContext.js +0 -23
  146. package/node/context/ZoomProvider/ZoomProvider.js +0 -63
  147. package/node/context/ZoomProvider/ZoomSetup.js +0 -20
  148. package/node/context/ZoomProvider/defaultizeZoom.js +0 -40
  149. package/node/context/ZoomProvider/index.js +0 -38
  150. package/node/context/ZoomProvider/initializeZoomData.js +0 -20
  151. package/node/context/ZoomProvider/useSetupPan.js +0 -114
  152. package/node/context/ZoomProvider/useSetupZoom.js +0 -281
  153. package/node/context/ZoomProvider/useZoom.js +0 -25
  154. package/node/context/index.js +0 -27
  155. /package/{context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/useChartProZoom.types.js} +0 -0
  156. /package/{modern/context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/zoom.types.js} +0 -0
  157. /package/node/{context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/useChartProZoom.types.js} +0 -0
@@ -1,89 +0,0 @@
1
- 'use client';
2
-
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- import * as React from 'react';
5
- import { useDrawingArea, useSeries, CartesianContext, computeAxisValue, useXExtremumGetter, useYExtremumGetter } from '@mui/x-charts/internals';
6
- import { useZoom } from "../ZoomProvider/useZoom.js";
7
- import { createAxisFilterMapper, createGetAxisFilters } from "./createAxisFilterMapper.js";
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- function CartesianProviderPro(props) {
10
- const {
11
- xAxis,
12
- yAxis,
13
- children
14
- } = props;
15
- const formattedSeries = useSeries();
16
- const drawingArea = useDrawingArea();
17
- const {
18
- zoomData,
19
- options
20
- } = useZoom();
21
- const xExtremumGetters = useXExtremumGetter();
22
- const yExtremumGetters = useYExtremumGetter();
23
- const getFilters = React.useMemo(() => {
24
- const xMapper = createAxisFilterMapper({
25
- zoomData,
26
- extremumGetter: xExtremumGetters,
27
- formattedSeries,
28
- direction: 'x'
29
- });
30
- const yMapper = createAxisFilterMapper({
31
- zoomData,
32
- extremumGetter: yExtremumGetters,
33
- formattedSeries,
34
- direction: 'y'
35
- });
36
- const xFilters = xAxis.reduce((acc, axis, index) => {
37
- const filter = xMapper(axis, index);
38
- if (filter !== null) {
39
- acc[axis.id] = filter;
40
- }
41
- return acc;
42
- }, {});
43
- const yFilters = yAxis.reduce((acc, axis, index) => {
44
- const filter = yMapper(axis, index);
45
- if (filter !== null) {
46
- acc[axis.id] = filter;
47
- }
48
- return acc;
49
- }, {});
50
- if (Object.keys(xFilters).length === 0 && Object.keys(yFilters).length === 0) {
51
- return undefined;
52
- }
53
- return createGetAxisFilters(_extends({}, xFilters, yFilters));
54
- }, [formattedSeries, xAxis, xExtremumGetters, yAxis, yExtremumGetters, zoomData]);
55
- const xValues = React.useMemo(() => computeAxisValue({
56
- drawingArea,
57
- formattedSeries,
58
- axis: xAxis,
59
- extremumGetters: xExtremumGetters,
60
- axisDirection: 'x',
61
- zoomData,
62
- zoomOptions: options,
63
- getFilters
64
- }), [drawingArea, formattedSeries, xAxis, xExtremumGetters, zoomData, options, getFilters]);
65
- const yValues = React.useMemo(() => computeAxisValue({
66
- drawingArea,
67
- formattedSeries,
68
- axis: yAxis,
69
- extremumGetters: yExtremumGetters,
70
- axisDirection: 'y',
71
- zoomData,
72
- zoomOptions: options,
73
- getFilters
74
- }), [drawingArea, formattedSeries, yAxis, yExtremumGetters, zoomData, options, getFilters]);
75
- const value = React.useMemo(() => ({
76
- isInitialized: true,
77
- data: {
78
- xAxis: xValues.axis,
79
- yAxis: yValues.axis,
80
- xAxisIds: xValues.axisIds,
81
- yAxisIds: yValues.axisIds
82
- }
83
- }), [xValues, yValues]);
84
- return /*#__PURE__*/_jsx(CartesianContext.Provider, {
85
- value: value,
86
- children: children
87
- });
88
- }
89
- export { CartesianProviderPro };
@@ -1,13 +0,0 @@
1
- import { FormattedSeries, ExtremumGettersConfig, ExtremumFilter, ZoomAxisFilters, GetZoomAxisFilters } from '@mui/x-charts/internals';
2
- import { ScaleName, AxisConfig } from '@mui/x-charts/models';
3
- import { ChartsAxisProps } from '@mui/x-charts/ChartsAxis';
4
- import { ZoomData } from '../ZoomProvider';
5
- type CreateAxisFilterMapperParams = {
6
- zoomData: ZoomData[];
7
- extremumGetter: ExtremumGettersConfig;
8
- formattedSeries: FormattedSeries;
9
- direction: 'x' | 'y';
10
- };
11
- export declare const createAxisFilterMapper: ({ zoomData, extremumGetter, formattedSeries, direction }: CreateAxisFilterMapperParams) => (axis: AxisConfig<ScaleName, any, ChartsAxisProps>, axisIndex: number) => ExtremumFilter | null;
12
- export declare const createGetAxisFilters: (filters: ZoomAxisFilters) => GetZoomAxisFilters;
13
- export {};
@@ -1,60 +0,0 @@
1
- import { getAxisExtremum, isDefined, getScale } from '@mui/x-charts/internals';
2
- export const createAxisFilterMapper = ({
3
- zoomData,
4
- extremumGetter,
5
- formattedSeries,
6
- direction
7
- }) => (axis, axisIndex) => {
8
- if (typeof axis.zoom !== 'object' || axis.zoom.filterMode !== 'discard') {
9
- return null;
10
- }
11
- const zoom = zoomData?.find(({
12
- axisId
13
- }) => axisId === axis.id);
14
- if (zoom === undefined || zoom.start <= 0 && zoom.end >= 100) {
15
- // No zoom, or zoom with all data visible
16
- return null;
17
- }
18
- let extremums = [];
19
- const scaleType = axis.scaleType;
20
- if (scaleType === 'point' || scaleType === 'band') {
21
- extremums = [0, (axis.data?.length ?? 1) - 1];
22
- } else {
23
- extremums = getAxisExtremum(axis, extremumGetter, axisIndex, formattedSeries);
24
- }
25
- let min;
26
- let max;
27
-
28
- // @ts-expect-error The function defaults to linear scale if the scaleType is not recognized.
29
- [min, max] = getScale(scaleType, extremums, [0, 100]).nice().domain();
30
- min = min instanceof Date ? min.getTime() : min;
31
- max = max instanceof Date ? max.getTime() : max;
32
- const minVal = min + zoom.start * (max - min) / 100;
33
- const maxVal = min + zoom.end * (max - min) / 100;
34
- return (value, dataIndex) => {
35
- const val = value[direction] ?? axis.data?.[dataIndex];
36
- if (val == null) {
37
- // If the value does not exist because of missing data point, or out of range index, we just ignore.
38
- return true;
39
- }
40
- if (axis.scaleType === 'point' || axis.scaleType === 'band' || typeof val === 'string') {
41
- return dataIndex >= minVal && dataIndex <= maxVal;
42
- }
43
- return val >= minVal && val <= maxVal;
44
- };
45
- };
46
- export const createGetAxisFilters = filters => ({
47
- currentAxisId,
48
- seriesXAxisId,
49
- seriesYAxisId,
50
- isDefaultAxis
51
- }) => {
52
- return (value, dataIndex) => {
53
- const axisId = currentAxisId === seriesXAxisId ? seriesYAxisId : seriesXAxisId;
54
- if (!axisId || isDefaultAxis) {
55
- return Object.values(filters ?? {})[0]?.(value, dataIndex) ?? true;
56
- }
57
- const data = [seriesYAxisId, seriesXAxisId].filter(id => id !== currentAxisId).map(id => filters[id ?? '']).filter(isDefined);
58
- return data.every(f => f(value, dataIndex));
59
- };
60
- };
@@ -1 +0,0 @@
1
- export * from './CartesianProviderPro';
@@ -1 +0,0 @@
1
- export * from "./CartesianProviderPro.js";
@@ -1,7 +0,0 @@
1
- import * as React from 'react';
2
- import { ChartDataProviderProps } from '@mui/x-charts/internals';
3
- import { ZoomProps } from '../ZoomProvider';
4
- export interface ChartDataProviderProProps extends ChartDataProviderProps, ZoomProps {
5
- }
6
- declare function ChartDataProviderPro(props: ChartDataProviderProProps): React.JSX.Element;
7
- export { ChartDataProviderPro };
@@ -1,50 +0,0 @@
1
- 'use client';
2
-
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- import * as React from 'react';
5
- import { DrawingAreaProvider, PluginProvider, SeriesProvider, AnimationProvider, SizeProvider, ChartProvider } from '@mui/x-charts/internals';
6
- import { HighlightedProvider, ZAxisContextProvider } from '@mui/x-charts/context';
7
- import { useLicenseVerifier } from '@mui/x-license/useLicenseVerifier';
8
- import { getReleaseInfo } from "../../internals/utils/releaseInfo.js";
9
- import { CartesianProviderPro } from "../CartesianProviderPro/index.js";
10
- import { ZoomProvider } from "../ZoomProvider/index.js";
11
- import { useChartContainerProProps } from "./useChartDataProviderProProps.js";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- const releaseInfo = getReleaseInfo();
14
- function ChartDataProviderPro(props) {
15
- const {
16
- zoomProviderProps,
17
- drawingAreaProviderProps,
18
- seriesProviderProps,
19
- zAxisContextProps,
20
- highlightedProviderProps,
21
- cartesianProviderProps,
22
- sizeProviderProps,
23
- pluginProviderProps,
24
- animationProviderProps,
25
- children
26
- } = useChartContainerProProps(props);
27
- useLicenseVerifier('x-charts-pro', releaseInfo);
28
- return /*#__PURE__*/_jsx(ChartProvider, {
29
- children: /*#__PURE__*/_jsx(SizeProvider, _extends({}, sizeProviderProps, {
30
- children: /*#__PURE__*/_jsx(DrawingAreaProvider, _extends({}, drawingAreaProviderProps, {
31
- children: /*#__PURE__*/_jsx(AnimationProvider, _extends({}, animationProviderProps, {
32
- children: /*#__PURE__*/_jsx(PluginProvider, _extends({}, pluginProviderProps, {
33
- children: /*#__PURE__*/_jsx(ZoomProvider, _extends({}, zoomProviderProps, {
34
- children: /*#__PURE__*/_jsx(SeriesProvider, _extends({}, seriesProviderProps, {
35
- children: /*#__PURE__*/_jsx(CartesianProviderPro, _extends({}, cartesianProviderProps, {
36
- children: /*#__PURE__*/_jsx(ZAxisContextProvider, _extends({}, zAxisContextProps, {
37
- children: /*#__PURE__*/_jsx(HighlightedProvider, _extends({}, highlightedProviderProps, {
38
- children: children
39
- }))
40
- }))
41
- }))
42
- }))
43
- }))
44
- }))
45
- }))
46
- }))
47
- }))
48
- });
49
- }
50
- export { ChartDataProviderPro };
@@ -1 +0,0 @@
1
- export * from './ChartDataProviderPro';
@@ -1 +0,0 @@
1
- export * from "./ChartDataProviderPro.js";
@@ -1,14 +0,0 @@
1
- import { ZoomProviderProps } from '../ZoomProvider';
2
- import type { ChartDataProviderProProps } from './ChartDataProviderPro';
3
- export declare const useChartContainerProProps: (props: ChartDataProviderProProps) => {
4
- zoomProviderProps: Omit<ZoomProviderProps, "children">;
5
- children: import("react").ReactNode;
6
- drawingAreaProviderProps: Omit<import("@mui/x-charts/internals").DrawingAreaProviderProps, "children">;
7
- pluginProviderProps: Omit<import("@mui/x-charts/internals").PluginProviderProps, "children">;
8
- seriesProviderProps: Omit<import("@mui/x-charts/internals").SeriesProviderProps, "children">;
9
- cartesianProviderProps: Omit<import("@mui/x-charts/internals").CartesianProviderProps, "children">;
10
- zAxisContextProps: Omit<import("@mui/x-charts").ZAxisContextProviderProps, "children">;
11
- highlightedProviderProps: Omit<import("@mui/x-charts").HighlightedProviderProps, "children">;
12
- sizeProviderProps: Omit<import("@mui/x-charts/internals").SizeProviderProps, "children">;
13
- animationProviderProps: Omit<import("@mui/x-charts/internals").AnimationProviderProps, "children">;
14
- };
@@ -1,43 +0,0 @@
1
- 'use client';
2
-
3
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
- const _excluded = ["zoom", "onZoomChange"];
5
- import { useChartDataProviderProps } from '@mui/x-charts/internals';
6
- export const useChartContainerProProps = props => {
7
- const {
8
- zoom,
9
- onZoomChange
10
- } = props,
11
- baseProps = _objectWithoutPropertiesLoose(props, _excluded);
12
- const {
13
- children,
14
- drawingAreaProviderProps,
15
- seriesProviderProps,
16
- cartesianProviderProps,
17
- zAxisContextProps,
18
- highlightedProviderProps,
19
- sizeProviderProps,
20
- pluginProviderProps,
21
- animationProviderProps,
22
- xAxis,
23
- yAxis
24
- } = useChartDataProviderProps(baseProps);
25
- const zoomProviderProps = {
26
- zoom,
27
- onZoomChange,
28
- xAxis,
29
- yAxis
30
- };
31
- return {
32
- zoomProviderProps,
33
- children,
34
- drawingAreaProviderProps,
35
- pluginProviderProps,
36
- seriesProviderProps,
37
- cartesianProviderProps,
38
- zAxisContextProps,
39
- highlightedProviderProps,
40
- sizeProviderProps,
41
- animationProviderProps
42
- };
43
- };
@@ -1,144 +0,0 @@
1
- import { AxisId } from '@mui/x-charts/internals';
2
- export type ZoomProviderProps = {
3
- children: React.ReactNode;
4
- /**
5
- * The configuration of the x-axes.
6
- * If not provided, a default axis config is used.
7
- * An array of [[AxisConfig]] objects.
8
- */
9
- xAxis?: AxisConfigForZoom[];
10
- /**
11
- * The configuration of the y-axes.
12
- * If not provided, a default axis config is used.
13
- * An array of [[AxisConfig]] objects.
14
- */
15
- yAxis?: AxisConfigForZoom[];
16
- } & ZoomProps;
17
- /**
18
- * Represents the state of the ZoomProvider.
19
- */
20
- export type ZoomState = {
21
- /**
22
- * Whether zooming is enabled.
23
- */
24
- isZoomEnabled: boolean;
25
- /**
26
- * Whether panning is enabled.
27
- */
28
- isPanEnabled: boolean;
29
- /**
30
- * The zoom options for each axis.
31
- */
32
- options: Record<AxisId, DefaultizedZoomOptions>;
33
- /**
34
- * The zoom data for each axis
35
- * @default []
36
- */
37
- zoomData: ZoomData[];
38
- /**
39
- * Set the zoom data for each axis.
40
- * @param {ZoomData[]} zoomData The new zoom data.
41
- */
42
- setZoomData: (zoomData: ZoomData[] | ((zoomData: ZoomData[]) => ZoomData[])) => void;
43
- /**
44
- * Whether the user is currently interacting with the chart.
45
- * This is useful to prevent animations from running while the user is interacting.
46
- */
47
- isInteracting: boolean;
48
- /**
49
- * Set the interaction state of the chart.
50
- * @param {boolean} isInteracting The new interaction state.
51
- */
52
- setIsInteracting: (isInteracting: boolean) => void;
53
- };
54
- export type ZoomOptions = {
55
- /**
56
- * The starting percentage of the zoom range. In the range of 0 to 100.
57
- *
58
- * @default 0
59
- */
60
- minStart?: number;
61
- /**
62
- * The ending percentage of the zoom range. In the range of 0 to 100.
63
- *
64
- * @default 100
65
- */
66
- maxEnd?: number;
67
- /**
68
- * The step size of the zooming function. Defines the granularity of the zoom.
69
- *
70
- * @default 5
71
- */
72
- step?: number;
73
- /**
74
- * Restricts the minimum span size in the range of 0 to 100.
75
- *
76
- * If the span size is smaller than the minSpan, the span will be resized to the minSpan.
77
- *
78
- * @default 10
79
- */
80
- minSpan?: number;
81
- /**
82
- * Restricts the maximum span size in the range of 0 to 100.
83
- *
84
- * If the span size is larger than the maxSpan, the span will be resized to the maxSpan.
85
- *
86
- * @default 100
87
- */
88
- maxSpan?: number;
89
- /**
90
- * Set to `false` to disable panning. Useful when you want to pan programmatically,
91
- * or to show only a specific section of the chart.
92
- *
93
- * @default true
94
- */
95
- panning?: boolean;
96
- /**
97
- * Defines how to filter the axis data when it is outside of the zoomed range of this axis.
98
- *
99
- * - `keep`: The data outside the zoomed range is kept. And the other axes will stay the same.
100
- * - `discard`: The data outside the zoomed range is discarded for the other axes.
101
- * The other axes will be adjusted to fit the zoomed range.
102
- *
103
- * @default 'keep'
104
- */
105
- filterMode?: 'discard' | 'keep';
106
- };
107
- export type ZoomData = {
108
- /**
109
- * The starting percentage of the zoom range. In the range of 0 to 100.
110
- *
111
- * @default 0
112
- */
113
- start: number;
114
- /**
115
- * The ending percentage of the zoom range. In the range of 0 to 100.
116
- *
117
- * @default 100
118
- */
119
- end: number;
120
- /**
121
- * The axis id that the zoom data belongs to.
122
- */
123
- axisId: AxisId;
124
- };
125
- export type ZoomProps = {
126
- /**
127
- * The list of zoom data related to each axis.
128
- */
129
- zoom?: ZoomData[];
130
- /**
131
- * Callback fired when the zoom has changed.
132
- *
133
- * @param {ZoomData[]} zoomData Updated zoom data.
134
- */
135
- onZoomChange?: (zoomData: ZoomData[] | ((zoomData: ZoomData[]) => ZoomData[])) => void;
136
- };
137
- export type DefaultizedZoomOptions = Required<ZoomOptions> & {
138
- axisId: AxisId;
139
- axisDirection: 'x' | 'y';
140
- };
141
- export type AxisConfigForZoom = {
142
- id: AxisId;
143
- zoom?: ZoomOptions | boolean;
144
- };
@@ -1,4 +0,0 @@
1
- import * as React from 'react';
2
- import { Initializable } from '@mui/x-charts/internals';
3
- import { ZoomState } from './Zoom.types';
4
- export declare const ZoomContext: React.Context<Initializable<ZoomState>>;
@@ -1,16 +0,0 @@
1
- import * as React from 'react';
2
- export const ZoomContext = /*#__PURE__*/React.createContext({
3
- isInitialized: false,
4
- data: {
5
- isZoomEnabled: false,
6
- isPanEnabled: false,
7
- options: {},
8
- zoomData: [],
9
- setZoomData: () => {},
10
- isInteracting: false,
11
- setIsInteracting: () => {}
12
- }
13
- });
14
- if (process.env.NODE_ENV !== 'production') {
15
- ZoomContext.displayName = 'ZoomContext';
16
- }
@@ -1,3 +0,0 @@
1
- import * as React from 'react';
2
- import { ZoomProviderProps } from './Zoom.types';
3
- export declare function ZoomProvider({ children, xAxis, yAxis, zoom, onZoomChange }: ZoomProviderProps): React.JSX.Element;
@@ -1,56 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import useControlled from '@mui/utils/useControlled';
5
- import { ZoomContext } from "./ZoomContext.js";
6
- import { defaultizeZoom } from "./defaultizeZoom.js";
7
- import { initializeZoomData } from "./initializeZoomData.js";
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- export function ZoomProvider({
10
- children,
11
- xAxis,
12
- yAxis,
13
- zoom,
14
- onZoomChange
15
- }) {
16
- const [isInteracting, setIsInteracting] = React.useState(false);
17
- const options = React.useMemo(() => [...defaultizeZoom(xAxis, 'x'), ...defaultizeZoom(yAxis, 'y')].reduce((acc, v) => {
18
- acc[v.axisId] = v;
19
- return acc;
20
- }, {}), [xAxis, yAxis]);
21
-
22
- // Default zoom data is initialized only once when uncontrolled. If the user changes the options
23
- // after the initial render, the zoom data will not be updated until the next zoom interaction.
24
- // This is required to avoid warnings about controlled/uncontrolled components.
25
- const defaultZoomData = React.useRef(initializeZoomData(options));
26
- const [zoomData, setZoomData] = useControlled({
27
- controlled: zoom,
28
- // eslint-disable-next-line react-compiler/react-compiler
29
- default: defaultZoomData.current,
30
- name: 'ZoomProvider',
31
- state: 'zoom'
32
- });
33
- const setZoomDataCallback = React.useCallback(newZoomData => {
34
- setZoomData(newZoomData);
35
- onZoomChange?.(newZoomData);
36
- }, [setZoomData, onZoomChange]);
37
- const value = React.useMemo(() => ({
38
- isInitialized: true,
39
- data: {
40
- isZoomEnabled: Object.keys(options).length > 0,
41
- isPanEnabled: isPanEnabled(options),
42
- options,
43
- zoomData,
44
- setZoomData: setZoomDataCallback,
45
- isInteracting,
46
- setIsInteracting
47
- }
48
- }), [zoomData, isInteracting, setIsInteracting, options, setZoomDataCallback]);
49
- return /*#__PURE__*/_jsx(ZoomContext.Provider, {
50
- value: value,
51
- children: children
52
- });
53
- }
54
- function isPanEnabled(options) {
55
- return Object.values(options).some(v => v.panning) || false;
56
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Sets up the zoom functionality if using composition or a custom chart.
3
- *
4
- * Simply add this component at the same level as the chart component to enable zooming and panning.
5
- *
6
- * See: [Composition](https://mui.com/x/react-charts/composition/)
7
- */
8
- declare function ZoomSetup(): null;
9
- export { ZoomSetup };
@@ -1,16 +0,0 @@
1
- import { useSetupPan } from "./useSetupPan.js";
2
- import { useSetupZoom } from "./useSetupZoom.js";
3
-
4
- /**
5
- * Sets up the zoom functionality if using composition or a custom chart.
6
- *
7
- * Simply add this component at the same level as the chart component to enable zooming and panning.
8
- *
9
- * See: [Composition](https://mui.com/x/react-charts/composition/)
10
- */
11
- function ZoomSetup() {
12
- useSetupZoom();
13
- useSetupPan();
14
- return null;
15
- }
16
- export { ZoomSetup };
@@ -1,2 +0,0 @@
1
- import { AxisConfigForZoom, DefaultizedZoomOptions } from './Zoom.types';
2
- export declare const defaultizeZoom: (axis: AxisConfigForZoom[] | undefined, axisDirection: "x" | "y") => DefaultizedZoomOptions[];
@@ -1,32 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { isDefined } from '@mui/x-charts/internals';
3
- const defaultZoomOptions = {
4
- minStart: 0,
5
- maxEnd: 100,
6
- step: 5,
7
- minSpan: 10,
8
- maxSpan: 100,
9
- panning: true,
10
- filterMode: 'keep'
11
- };
12
- export const defaultizeZoom = (axis, axisDirection) => {
13
- if (!axis) {
14
- return [];
15
- }
16
- const defaultized = axis.map(v => {
17
- if (!v.zoom) {
18
- return undefined;
19
- }
20
- if (v.zoom === true) {
21
- return _extends({
22
- axisId: v.id,
23
- axisDirection
24
- }, defaultZoomOptions);
25
- }
26
- return _extends({
27
- axisId: v.id,
28
- axisDirection
29
- }, defaultZoomOptions, v.zoom);
30
- }).filter(isDefined);
31
- return defaultized;
32
- };
@@ -1,3 +0,0 @@
1
- export * from './ZoomContext';
2
- export * from './ZoomProvider';
3
- export * from './Zoom.types';
@@ -1,3 +0,0 @@
1
- export * from "./ZoomContext.js";
2
- export * from "./ZoomProvider.js";
3
- export * from "./Zoom.types.js";
@@ -1,6 +0,0 @@
1
- import { ZoomState } from './Zoom.types';
2
- export declare const initializeZoomData: (options: ZoomState["options"]) => {
3
- axisId: import("@mui/x-charts/internals").AxisId;
4
- start: number;
5
- end: number;
6
- }[];
@@ -1,13 +0,0 @@
1
- // This function is used to initialize the zoom data when it is not provided by the user.
2
- // It is helpful to avoid the need to provide the possibly auto-generated id for each axis.
3
- export const initializeZoomData = options => {
4
- return Object.values(options).map(({
5
- axisId,
6
- minStart: start,
7
- maxEnd: end
8
- }) => ({
9
- axisId,
10
- start,
11
- end
12
- }));
13
- };
@@ -1 +0,0 @@
1
- export declare const useSetupPan: () => void;