@mui/x-charts-pro 8.11.3 → 8.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChartPro/BarChartPro.d.ts +2 -2
- package/BarChartPro/BarChartPro.js +25 -1
- package/BarChartPro/BarChartPro.plugins.d.ts +3 -3
- package/BarChartPro/BarChartPro.plugins.js +1 -1
- package/BarChartPro/index.d.ts +2 -1
- package/BarChartPro/index.js +11 -0
- package/CHANGELOG.md +296 -6
- package/ChartContainerPro/useChartContainerProProps.js +3 -1
- package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/FunnelChart/FunnelChart.d.ts +2 -2
- package/FunnelChart/FunnelChart.plugins.d.ts +2 -2
- package/FunnelChart/funnelAxisPlugin/computeAxisValue.js +2 -5
- package/FunnelChart/index.d.ts +1 -0
- package/FunnelChart/index.js +12 -0
- package/FunnelChart/useFunnelChartProps.d.ts +2 -2
- package/Heatmap/Heatmap.d.ts +2 -2
- package/Heatmap/Heatmap.plugins.d.ts +2 -2
- package/Heatmap/index.d.ts +1 -0
- package/Heatmap/index.js +12 -0
- package/LineChartPro/LineChartPro.d.ts +2 -2
- package/LineChartPro/LineChartPro.js +25 -1
- package/LineChartPro/LineChartPro.plugins.d.ts +3 -3
- package/LineChartPro/LineChartPro.plugins.js +1 -1
- package/LineChartPro/index.d.ts +2 -1
- package/LineChartPro/index.js +11 -0
- package/PieChartPro/PieChartPro.js +1 -0
- package/PieChartPro/PieChartPro.plugins.d.ts +2 -2
- package/PieChartPro/index.d.ts +2 -1
- package/PieChartPro/index.js +11 -0
- package/RadarChartPro/RadarChartPro.d.ts +2 -2
- package/RadarChartPro/RadarChartPro.plugins.d.ts +2 -2
- package/RadarChartPro/index.d.ts +2 -1
- package/RadarChartPro/index.js +11 -0
- package/SankeyChart/SankeyChart.d.ts +2 -2
- package/SankeyChart/SankeyChart.js +4 -1
- package/SankeyChart/SankeyChart.plugins.d.ts +3 -2
- package/SankeyChart/SankeyChart.plugins.js +2 -4
- package/SankeyChart/SankeyLinkLabel.js +12 -1
- package/SankeyChart/calculateSankeyLayout.js +8 -2
- package/SankeyChart/sankey.types.d.ts +55 -5
- package/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +2 -0
- package/SankeyChart/seriesConfig/tooltipGetter.js +13 -3
- package/SankeyChart/useSankeyChartProps.d.ts +2 -2
- package/ScatterChartPro/ScatterChartPro.d.ts +2 -2
- package/ScatterChartPro/ScatterChartPro.js +37 -3
- package/ScatterChartPro/ScatterChartPro.plugins.d.ts +3 -3
- package/ScatterChartPro/ScatterChartPro.plugins.js +1 -1
- package/ScatterChartPro/index.d.ts +2 -1
- package/ScatterChartPro/index.js +11 -0
- package/context/ChartProApi.d.ts +14 -12
- package/esm/BarChartPro/BarChartPro.d.ts +2 -2
- package/esm/BarChartPro/BarChartPro.js +25 -1
- package/esm/BarChartPro/BarChartPro.plugins.d.ts +3 -3
- package/esm/BarChartPro/BarChartPro.plugins.js +2 -2
- package/esm/BarChartPro/index.d.ts +2 -1
- package/esm/BarChartPro/index.js +2 -1
- package/esm/ChartContainerPro/useChartContainerProProps.js +3 -1
- package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/esm/FunnelChart/FunnelChart.d.ts +2 -2
- package/esm/FunnelChart/FunnelChart.plugins.d.ts +2 -2
- package/esm/FunnelChart/funnelAxisPlugin/computeAxisValue.js +3 -6
- package/esm/FunnelChart/index.d.ts +1 -0
- package/esm/FunnelChart/index.js +1 -0
- package/esm/FunnelChart/useFunnelChartProps.d.ts +2 -2
- package/esm/Heatmap/Heatmap.d.ts +2 -2
- package/esm/Heatmap/Heatmap.plugins.d.ts +2 -2
- package/esm/Heatmap/index.d.ts +1 -0
- package/esm/Heatmap/index.js +1 -0
- package/esm/LineChartPro/LineChartPro.d.ts +2 -2
- package/esm/LineChartPro/LineChartPro.js +25 -1
- package/esm/LineChartPro/LineChartPro.plugins.d.ts +3 -3
- package/esm/LineChartPro/LineChartPro.plugins.js +2 -2
- package/esm/LineChartPro/index.d.ts +2 -1
- package/esm/LineChartPro/index.js +2 -1
- package/esm/PieChartPro/PieChartPro.js +1 -0
- package/esm/PieChartPro/PieChartPro.plugins.d.ts +2 -2
- package/esm/PieChartPro/index.d.ts +2 -1
- package/esm/PieChartPro/index.js +2 -1
- package/esm/RadarChartPro/RadarChartPro.d.ts +2 -2
- package/esm/RadarChartPro/RadarChartPro.plugins.d.ts +2 -2
- package/esm/RadarChartPro/index.d.ts +2 -1
- package/esm/RadarChartPro/index.js +2 -1
- package/esm/SankeyChart/SankeyChart.d.ts +2 -2
- package/esm/SankeyChart/SankeyChart.js +4 -1
- package/esm/SankeyChart/SankeyChart.plugins.d.ts +3 -2
- package/esm/SankeyChart/SankeyChart.plugins.js +2 -6
- package/esm/SankeyChart/SankeyLinkLabel.js +12 -1
- package/esm/SankeyChart/calculateSankeyLayout.js +8 -2
- package/esm/SankeyChart/sankey.types.d.ts +55 -5
- package/esm/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +2 -0
- package/esm/SankeyChart/seriesConfig/tooltipGetter.js +13 -3
- package/esm/SankeyChart/useSankeyChartProps.d.ts +2 -2
- package/esm/ScatterChartPro/ScatterChartPro.d.ts +2 -2
- package/esm/ScatterChartPro/ScatterChartPro.js +37 -3
- package/esm/ScatterChartPro/ScatterChartPro.plugins.d.ts +3 -3
- package/esm/ScatterChartPro/ScatterChartPro.plugins.js +2 -2
- package/esm/ScatterChartPro/index.d.ts +2 -1
- package/esm/ScatterChartPro/index.js +2 -1
- package/esm/context/ChartProApi.d.ts +14 -12
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -1
- package/esm/internals/plugins/useChartProExport/useChartProExport.types.d.ts +1 -2
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +22 -0
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.js +4 -0
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +92 -0
- package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.js +1 -0
- package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +21 -6
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoom.utils.js +1 -1
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +18 -9
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.d.ts +8 -0
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.js +73 -0
- package/esm/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +14 -4
- package/esm/internals/plugins/useChartProZoom/initializeZoomData.d.ts +2 -0
- package/esm/internals/plugins/useChartProZoom/initializeZoomData.js +26 -0
- package/esm/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.d.ts +2 -0
- package/esm/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.js +86 -0
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -2
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +25 -44
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +9 -0
- package/esm/plugins/index.d.ts +3 -0
- package/esm/plugins/index.js +3 -0
- package/index.d.ts +1 -0
- package/index.js +13 -1
- package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +1 -2
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +22 -0
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.js +10 -0
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +92 -0
- package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.js +5 -0
- package/internals/plugins/useChartProZoom/gestureHooks/usePanOnDrag.js +21 -6
- package/internals/plugins/useChartProZoom/gestureHooks/useZoom.utils.js +1 -1
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnPinch.js +18 -9
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.d.ts +8 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnTapAndDrag.js +80 -0
- package/internals/plugins/useChartProZoom/gestureHooks/useZoomOnWheel.js +14 -4
- package/internals/plugins/useChartProZoom/initializeZoomData.d.ts +2 -0
- package/internals/plugins/useChartProZoom/initializeZoomData.js +31 -0
- package/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.d.ts +2 -0
- package/internals/plugins/useChartProZoom/initializeZoomInteractionConfig.js +92 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -2
- package/internals/plugins/useChartProZoom/useChartProZoom.js +26 -45
- package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +9 -0
- package/package.json +7 -7
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +35 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const tooltipGetter = params => {
|
|
2
2
|
const {
|
|
3
|
-
identifier
|
|
3
|
+
identifier,
|
|
4
|
+
series
|
|
4
5
|
} = params;
|
|
5
6
|
if (!identifier) {
|
|
6
7
|
return null;
|
|
@@ -15,7 +16,11 @@ export const tooltipGetter = params => {
|
|
|
15
16
|
color: node.color,
|
|
16
17
|
label: `${node.label}:`,
|
|
17
18
|
value: node.value,
|
|
18
|
-
formattedValue:
|
|
19
|
+
formattedValue: series.valueFormatter(node.value, {
|
|
20
|
+
type: 'node',
|
|
21
|
+
nodeId: node.id,
|
|
22
|
+
location: 'tooltip'
|
|
23
|
+
}),
|
|
19
24
|
markType: 'square'
|
|
20
25
|
};
|
|
21
26
|
}
|
|
@@ -31,7 +36,12 @@ export const tooltipGetter = params => {
|
|
|
31
36
|
color: link.color,
|
|
32
37
|
label: `${sourceLabel} → ${targetLabel}:`,
|
|
33
38
|
value: link.value,
|
|
34
|
-
formattedValue:
|
|
39
|
+
formattedValue: series.valueFormatter(link.value, {
|
|
40
|
+
type: 'link',
|
|
41
|
+
sourceId: link.source.id,
|
|
42
|
+
targetId: link.target.id,
|
|
43
|
+
location: 'tooltip'
|
|
44
|
+
}),
|
|
35
45
|
markType: 'line'
|
|
36
46
|
};
|
|
37
47
|
}
|
|
@@ -2,7 +2,7 @@ import type { ChartsOverlayProps } from '@mui/x-charts/ChartsOverlay';
|
|
|
2
2
|
import type { ChartsWrapperProps } from '@mui/x-charts/ChartsWrapper';
|
|
3
3
|
import type { SankeyChartProps } from "./SankeyChart.js";
|
|
4
4
|
import type { ChartContainerProProps } from "../ChartContainerPro/index.js";
|
|
5
|
-
import { type
|
|
5
|
+
import { type SankeyChartPluginSignatures } from "./SankeyChart.plugins.js";
|
|
6
6
|
/**
|
|
7
7
|
* A helper function that extracts SankeyChartProps from the input props
|
|
8
8
|
* and returns an object with props for the children components of SankeyChart.
|
|
@@ -11,7 +11,7 @@ import { type SankeyChartPluginsSignatures } from "./SankeyChart.plugins.js";
|
|
|
11
11
|
* @returns An object with props for the children components of SankeyChart
|
|
12
12
|
*/
|
|
13
13
|
export declare const useSankeyChartProps: (props: SankeyChartProps) => {
|
|
14
|
-
chartContainerProps: ChartContainerProProps<"sankey",
|
|
14
|
+
chartContainerProps: ChartContainerProProps<"sankey", SankeyChartPluginSignatures>;
|
|
15
15
|
sankeyPlotProps: {
|
|
16
16
|
onNodeClick: ((event: React.MouseEvent<SVGElement, MouseEvent>, node: import("./sankey.types.js").SankeyNodeIdentifierWithData) => void) | undefined;
|
|
17
17
|
onLinkClick: ((event: React.MouseEvent<SVGElement, MouseEvent>, link: import("./sankey.types.js").SankeyLinkIdentifierWithData) => void) | undefined;
|
|
@@ -3,7 +3,7 @@ import { ScatterChartProps, ScatterChartSlotProps, ScatterChartSlots } from '@mu
|
|
|
3
3
|
import { ChartsTooltipProps } from '@mui/x-charts/ChartsTooltip';
|
|
4
4
|
import { ChartsSlotPropsPro, ChartsSlotsPro } from "../internals/material/index.js";
|
|
5
5
|
import { ChartContainerProProps } from "../ChartContainerPro/ChartContainerPro.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ScatterChartProPluginSignatures } from "./ScatterChartPro.plugins.js";
|
|
7
7
|
import { ChartsToolbarProSlots, ChartsToolbarProSlotProps } from "../ChartsToolbarPro/Toolbar.types.js";
|
|
8
8
|
export interface ScatterChartProSlots extends Omit<ScatterChartSlots, 'toolbar'>, ChartsToolbarProSlots, Partial<ChartsSlotsPro> {}
|
|
9
9
|
export interface ScatterChartProSlotProps extends Omit<ScatterChartSlotProps, 'toolbar' | 'tooltip'>, ChartsToolbarProSlotProps, Partial<ChartsSlotPropsPro> {
|
|
@@ -13,7 +13,7 @@ export interface ScatterChartProSlotProps extends Omit<ScatterChartSlotProps, 't
|
|
|
13
13
|
*/
|
|
14
14
|
tooltip?: Partial<ChartsTooltipProps<'item' | 'none'>>;
|
|
15
15
|
}
|
|
16
|
-
export interface ScatterChartProProps extends Omit<ScatterChartProps, 'apiRef' | 'slots' | 'slotProps'>, Omit<ChartContainerProProps<'scatter',
|
|
16
|
+
export interface ScatterChartProProps extends Omit<ScatterChartProps, 'apiRef' | 'slots' | 'slotProps'>, Omit<ChartContainerProProps<'scatter', ScatterChartProPluginSignatures>, 'series' | 'plugins' | 'seriesConfig' | 'onItemClick' | 'slots' | 'slotProps' | 'experimentalFeatures' | 'highlightedAxis' | 'onHighlightedAxisChange'> {
|
|
17
17
|
/**
|
|
18
18
|
* Overridable component slots.
|
|
19
19
|
* @default {}
|
|
@@ -127,6 +127,7 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
127
127
|
* @default false
|
|
128
128
|
*/
|
|
129
129
|
disableVoronoi: PropTypes.bool,
|
|
130
|
+
enableKeyboardNavigation: PropTypes.bool,
|
|
130
131
|
/**
|
|
131
132
|
* Option to display a cartesian grid in the background.
|
|
132
133
|
*/
|
|
@@ -210,6 +211,15 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
210
211
|
* @param {ZoomData[]} zoomData Updated zoom data.
|
|
211
212
|
*/
|
|
212
213
|
onZoomChange: PropTypes.func,
|
|
214
|
+
/**
|
|
215
|
+
* The type of renderer to use for the scatter plot.
|
|
216
|
+
* - `svg-single`: Renders every scatter item in a `<circle />` element.
|
|
217
|
+
* - `svg-batch`: Batch renders scatter items in `<path />` elements for better performance with large datasets, at the cost of some limitations.
|
|
218
|
+
* Read more: https://mui.com/x/react-charts/scatter/#performance
|
|
219
|
+
*
|
|
220
|
+
* @default 'svg-single'
|
|
221
|
+
*/
|
|
222
|
+
renderer: PropTypes.oneOf(['svg-batch', 'svg-single']),
|
|
213
223
|
/**
|
|
214
224
|
* The series to display in the scatter chart.
|
|
215
225
|
* An array of [[ScatterSeries]] objects.
|
|
@@ -239,10 +249,11 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
239
249
|
theme: PropTypes.oneOf(['dark', 'light']),
|
|
240
250
|
title: PropTypes.string,
|
|
241
251
|
/**
|
|
242
|
-
* Defines the
|
|
252
|
+
* Defines the maximum distance between a scatter point and the pointer that triggers the interaction.
|
|
253
|
+
* If set to `'item'`, the radius is the `markerSize`.
|
|
243
254
|
* If `undefined`, the radius is assumed to be infinite.
|
|
244
255
|
*/
|
|
245
|
-
voronoiMaxRadius: PropTypes.number,
|
|
256
|
+
voronoiMaxRadius: PropTypes.oneOfType([PropTypes.oneOf(['item']), PropTypes.number]),
|
|
246
257
|
/**
|
|
247
258
|
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
248
259
|
*/
|
|
@@ -1390,6 +1401,29 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
1390
1401
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
1391
1402
|
end: PropTypes.number.isRequired,
|
|
1392
1403
|
start: PropTypes.number.isRequired
|
|
1393
|
-
}))
|
|
1404
|
+
})),
|
|
1405
|
+
/**
|
|
1406
|
+
* Configuration for zoom interactions.
|
|
1407
|
+
*/
|
|
1408
|
+
zoomInteractionConfig: PropTypes.shape({
|
|
1409
|
+
pan: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf(['drag']), PropTypes.shape({
|
|
1410
|
+
pointerMode: PropTypes.oneOf(['mouse', 'touch']),
|
|
1411
|
+
requiredKeys: PropTypes.arrayOf(PropTypes.string),
|
|
1412
|
+
type: PropTypes.oneOf(['drag']).isRequired
|
|
1413
|
+
})]).isRequired),
|
|
1414
|
+
zoom: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf(['pinch', 'tapAndDrag', 'wheel']), PropTypes.shape({
|
|
1415
|
+
pointerMode: PropTypes.any,
|
|
1416
|
+
requiredKeys: PropTypes.arrayOf(PropTypes.string),
|
|
1417
|
+
type: PropTypes.oneOf(['wheel']).isRequired
|
|
1418
|
+
}), PropTypes.shape({
|
|
1419
|
+
pointerMode: PropTypes.any,
|
|
1420
|
+
requiredKeys: PropTypes.array,
|
|
1421
|
+
type: PropTypes.oneOf(['pinch']).isRequired
|
|
1422
|
+
}), PropTypes.shape({
|
|
1423
|
+
pointerMode: PropTypes.oneOf(['mouse', 'touch']),
|
|
1424
|
+
requiredKeys: PropTypes.arrayOf(PropTypes.string),
|
|
1425
|
+
type: PropTypes.oneOf(['tapAndDrag']).isRequired
|
|
1426
|
+
})]).isRequired)
|
|
1427
|
+
})
|
|
1394
1428
|
} : void 0;
|
|
1395
1429
|
export { ScatterChartPro };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UseChartZAxisSignature, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature,
|
|
1
|
+
import { UseChartZAxisSignature, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature, ConvertSignaturesIntoPlugins } from '@mui/x-charts/internals';
|
|
2
2
|
import { UseChartProExportSignature } from "../internals/plugins/useChartProExport/index.js";
|
|
3
3
|
import { UseChartProZoomSignature } from "../internals/plugins/useChartProZoom/index.js";
|
|
4
|
-
export type
|
|
5
|
-
export declare const SCATTER_CHART_PRO_PLUGINS: ConvertSignaturesIntoPlugins<
|
|
4
|
+
export type ScatterChartProPluginSignatures = [UseChartZAxisSignature, UseChartCartesianAxisSignature<'scatter'>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature, UseChartProZoomSignature, UseChartProExportSignature];
|
|
5
|
+
export declare const SCATTER_CHART_PRO_PLUGINS: ConvertSignaturesIntoPlugins<ScatterChartProPluginSignatures>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight,
|
|
1
|
+
import { useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartClosestPoint, useChartKeyboardNavigation } from '@mui/x-charts/internals';
|
|
2
2
|
import { useChartProExport } from "../internals/plugins/useChartProExport/index.js";
|
|
3
3
|
import { useChartProZoom } from "../internals/plugins/useChartProZoom/index.js";
|
|
4
|
-
export const SCATTER_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight,
|
|
4
|
+
export const SCATTER_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartClosestPoint, useChartKeyboardNavigation, useChartProZoom, useChartProExport];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./ScatterChartPro.js";
|
|
1
|
+
export * from "./ScatterChartPro.js";
|
|
2
|
+
export * from "./ScatterChartPro.plugins.js";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./ScatterChartPro.js";
|
|
1
|
+
export * from "./ScatterChartPro.js";
|
|
2
|
+
export * from "./ScatterChartPro.plugins.js";
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { ChartAnyPluginSignature, ChartPublicAPI } from '@mui/x-charts/internals';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { HeatmapPluginSignatures } from "../Heatmap/Heatmap.plugins.js";
|
|
3
|
+
import { LineChartProPluginSignatures } from "../LineChartPro/LineChartPro.plugins.js";
|
|
4
|
+
import { ScatterChartProPluginSignatures } from "../ScatterChartPro/ScatterChartPro.plugins.js";
|
|
5
|
+
import { BarChartProPluginSignatures } from "../BarChartPro/BarChartPro.plugins.js";
|
|
6
6
|
import { AllPluginSignatures, DefaultPluginSignatures } from "../internals/plugins/allPlugins.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { FunnelChartPluginSignatures } from "../FunnelChart/FunnelChart.plugins.js";
|
|
8
|
+
import { RadarChartProPluginSignatures } from "../RadarChartPro/RadarChartPro.plugins.js";
|
|
9
9
|
import { PieChartProPluginSignatures } from "../PieChartPro/PieChartPro.plugins.js";
|
|
10
|
+
import { SankeyChartPluginSignatures } from "../SankeyChart/SankeyChart.plugins.js";
|
|
10
11
|
export type ProPluginsPerSeriesType = {
|
|
11
|
-
heatmap:
|
|
12
|
-
line:
|
|
13
|
-
scatter:
|
|
14
|
-
bar:
|
|
15
|
-
funnel:
|
|
16
|
-
radar:
|
|
12
|
+
heatmap: HeatmapPluginSignatures;
|
|
13
|
+
line: LineChartProPluginSignatures;
|
|
14
|
+
scatter: ScatterChartProPluginSignatures;
|
|
15
|
+
bar: BarChartProPluginSignatures;
|
|
16
|
+
funnel: FunnelChartPluginSignatures;
|
|
17
|
+
radar: RadarChartProPluginSignatures;
|
|
17
18
|
pie: PieChartProPluginSignatures;
|
|
19
|
+
sankey: SankeyChartPluginSignatures;
|
|
18
20
|
composition: DefaultPluginSignatures;
|
|
19
21
|
};
|
|
20
22
|
/**
|
package/esm/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export * from "./constants/index.js";
|
|
|
26
26
|
export * from "./hooks/index.js";
|
|
27
27
|
export * from "./context/index.js";
|
|
28
28
|
export * from "./models/index.js";
|
|
29
|
+
export * from "./plugins/index.js";
|
|
29
30
|
export * from "./colorPalettes/index.js";
|
|
30
31
|
export * from "./Heatmap/index.js";
|
|
31
32
|
export { ChartContainerPro } from "./ChartContainerPro/index.js";
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts-pro v8.
|
|
2
|
+
* @mui/x-charts-pro v8.13.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
|
|
@@ -37,6 +37,7 @@ export * from "./constants/index.js";
|
|
|
37
37
|
export * from "./hooks/index.js";
|
|
38
38
|
export * from "./context/index.js";
|
|
39
39
|
export * from "./models/index.js";
|
|
40
|
+
export * from "./plugins/index.js";
|
|
40
41
|
// Locales should be imported from `@mui/x-charts-pro/locales`
|
|
41
42
|
// export * from './locales';
|
|
42
43
|
export * from "./colorPalettes/index.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChartPluginSignature } from '@mui/x-charts/internals';
|
|
2
2
|
export interface UseChartProExportParameters {}
|
|
3
3
|
export type UseChartProExportDefaultizedParameters = UseChartProExportParameters;
|
|
4
4
|
export interface UseChartProExportState {
|
|
@@ -74,5 +74,4 @@ export type UseChartProExportSignature = ChartPluginSignature<{
|
|
|
74
74
|
state: UseChartProExportState;
|
|
75
75
|
publicAPI: UseChartProExportPublicApi;
|
|
76
76
|
instance: UseChartProExportInstance;
|
|
77
|
-
dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
|
|
78
77
|
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const selectorZoomInteractionConfig: import("reselect").Selector<any, (Omit<import("./ZoomInteractionConfig.types.js").ZoomInteraction, "pointerMode"> & {
|
|
2
|
+
mouse: {
|
|
3
|
+
requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
|
|
4
|
+
};
|
|
5
|
+
touch: {
|
|
6
|
+
requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
|
|
7
|
+
};
|
|
8
|
+
pointerMode?: import("@mui/x-internal-gestures/core").PointerMode[];
|
|
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"> & {
|
|
15
|
+
mouse: {
|
|
16
|
+
requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
|
|
17
|
+
};
|
|
18
|
+
touch: {
|
|
19
|
+
requiredKeys?: import("@mui/x-internal-gestures/core").KeyboardKey[];
|
|
20
|
+
};
|
|
21
|
+
pointerMode?: import("@mui/x-internal-gestures/core").PointerMode[];
|
|
22
|
+
}) | null, [interactionName: "drag"]>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createSelector } from '@mui/x-charts/internals';
|
|
2
|
+
import { selectorChartZoomState } from "./useChartProZoom.selectors.js";
|
|
3
|
+
export const selectorZoomInteractionConfig = createSelector([selectorChartZoomState, (_state, interactionName) => interactionName], (zoomState, interactionName) => zoomState.zoomInteractionConfig.zoom[interactionName] ?? null);
|
|
4
|
+
export const selectorPanInteractionConfig = createSelector([selectorChartZoomState, (_state, interactionName) => interactionName], (zoomState, interactionName) => zoomState.zoomInteractionConfig.pan[interactionName] ?? null);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { KeyboardKey, PointerMode } from '@mui/x-internal-gestures/core';
|
|
2
|
+
export type ZoomInteractionConfig = {
|
|
3
|
+
/**
|
|
4
|
+
* Defines the interactions that trigger zooming.
|
|
5
|
+
* - `wheel`: Zooms in or out when the mouse wheel is scrolled.
|
|
6
|
+
* - `pinch`: Zooms in or out when a pinch gesture is detected.
|
|
7
|
+
* - `tapAndDrag`: Zooms in or out by tapping twice and then dragging vertically. Dragging up zooms in, dragging down zooms out.
|
|
8
|
+
*
|
|
9
|
+
* @default ['wheel', 'pinch']
|
|
10
|
+
*/
|
|
11
|
+
zoom?: (ZoomInteraction | ZoomInteraction['type'])[];
|
|
12
|
+
/**
|
|
13
|
+
* Defines the interactions that trigger panning.
|
|
14
|
+
* - `drag`: Pans the chart when dragged with the mouse.
|
|
15
|
+
*
|
|
16
|
+
* @default ['drag']
|
|
17
|
+
*/
|
|
18
|
+
pan?: (PanInteraction | PanInteraction['type'])[];
|
|
19
|
+
};
|
|
20
|
+
type Entry<T extends AnyInteraction> = { [K in T['type']]?: Omit<T, 'pointerMode'> & {
|
|
21
|
+
mouse: {
|
|
22
|
+
requiredKeys?: KeyboardKey[];
|
|
23
|
+
};
|
|
24
|
+
touch: {
|
|
25
|
+
requiredKeys?: KeyboardKey[];
|
|
26
|
+
};
|
|
27
|
+
pointerMode?: PointerMode[];
|
|
28
|
+
} };
|
|
29
|
+
export type DefaultizedZoomInteractionConfig = {
|
|
30
|
+
zoom: Entry<ZoomInteraction>;
|
|
31
|
+
pan: Entry<PanInteraction>;
|
|
32
|
+
};
|
|
33
|
+
export type ZoomInteraction = WheelInteraction | PinchInteraction | TapAndDragInteraction;
|
|
34
|
+
export type PanInteraction = DragInteraction;
|
|
35
|
+
export type ZoomInteractionName = ZoomInteraction['type'];
|
|
36
|
+
export type PanInteractionName = PanInteraction['type'];
|
|
37
|
+
export type InteractionMode = Exclude<PointerMode, 'pen'>;
|
|
38
|
+
type AllKeysProp = {
|
|
39
|
+
/**
|
|
40
|
+
* The keys that must be pressed to trigger the interaction.
|
|
41
|
+
*/
|
|
42
|
+
requiredKeys?: KeyboardKey[];
|
|
43
|
+
};
|
|
44
|
+
type AllModeProp = {
|
|
45
|
+
/**
|
|
46
|
+
* Defines which type of pointer can trigger the interaction.
|
|
47
|
+
* - `mouse`: Only mouse interactions will trigger the interaction.
|
|
48
|
+
* - `touch`: Only touch interactions will trigger the interaction.
|
|
49
|
+
* - undefined: All interactions will trigger the interaction.
|
|
50
|
+
*/
|
|
51
|
+
pointerMode?: InteractionMode;
|
|
52
|
+
};
|
|
53
|
+
type NoKeysProp = {
|
|
54
|
+
/**
|
|
55
|
+
* This interaction does not support key combinations.
|
|
56
|
+
*/
|
|
57
|
+
requiredKeys?: any[];
|
|
58
|
+
};
|
|
59
|
+
type NoModeProp = {
|
|
60
|
+
/**
|
|
61
|
+
* This gesture only works on a specific pointer mode. Mode has no effect.
|
|
62
|
+
*/
|
|
63
|
+
pointerMode?: any;
|
|
64
|
+
};
|
|
65
|
+
type Unpack<T> = { [K in keyof T]: T[K] extends object ? Unpack<T[K]> : T[K] };
|
|
66
|
+
export type WheelInteraction = Unpack<{
|
|
67
|
+
type: 'wheel';
|
|
68
|
+
} & NoModeProp & AllKeysProp>;
|
|
69
|
+
export type PinchInteraction = Unpack<{
|
|
70
|
+
type: 'pinch';
|
|
71
|
+
} & NoModeProp & NoKeysProp>;
|
|
72
|
+
export type DragInteraction = Unpack<{
|
|
73
|
+
type: 'drag';
|
|
74
|
+
} & AllModeProp & AllKeysProp>;
|
|
75
|
+
export type TapAndDragInteraction = Unpack<{
|
|
76
|
+
type: 'tapAndDrag';
|
|
77
|
+
} & AllModeProp & AllKeysProp>;
|
|
78
|
+
export type AnyInteraction = {
|
|
79
|
+
type: string;
|
|
80
|
+
pointerMode?: InteractionMode;
|
|
81
|
+
requiredKeys?: KeyboardKey[];
|
|
82
|
+
};
|
|
83
|
+
export type AnyEntry = Omit<AnyInteraction, 'pointerMode'> & {
|
|
84
|
+
mouse: {
|
|
85
|
+
requiredKeys?: KeyboardKey[];
|
|
86
|
+
};
|
|
87
|
+
touch: {
|
|
88
|
+
requiredKeys?: KeyboardKey[];
|
|
89
|
+
};
|
|
90
|
+
pointerMode?: PointerMode[];
|
|
91
|
+
};
|
|
92
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { useSelector, selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
|
|
5
5
|
import { rafThrottle } from '@mui/x-internals/rafThrottle';
|
|
6
6
|
import { translateZoom } from "./useZoom.utils.js";
|
|
7
|
+
import { selectorPanInteractionConfig } from "../ZoomInteractionConfig.selectors.js";
|
|
7
8
|
export const usePanOnDrag = ({
|
|
8
9
|
store,
|
|
9
10
|
instance,
|
|
@@ -12,12 +13,26 @@ export const usePanOnDrag = ({
|
|
|
12
13
|
const drawingArea = useSelector(store, selectorChartDrawingArea);
|
|
13
14
|
const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
|
|
14
15
|
const startRef = React.useRef(null);
|
|
16
|
+
const config = useSelector(store, selectorPanInteractionConfig, ['drag']);
|
|
17
|
+
const isPanOnDragEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) && config || false, [optionsLookup, config]);
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
if (!isPanOnDragEnabled) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
instance.updateZoomInteractionListeners('zoomPan', {
|
|
23
|
+
requiredKeys: config.requiredKeys,
|
|
24
|
+
pointerMode: config.pointerMode,
|
|
25
|
+
pointerOptions: {
|
|
26
|
+
mouse: config.mouse,
|
|
27
|
+
touch: config.touch
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}, [isPanOnDragEnabled, config, instance]);
|
|
15
31
|
|
|
16
32
|
// Add event for chart panning
|
|
17
|
-
const isPanEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) || false, [optionsLookup]);
|
|
18
33
|
React.useEffect(() => {
|
|
19
34
|
const element = svgRef.current;
|
|
20
|
-
if (element === null || !
|
|
35
|
+
if (element === null || !isPanOnDragEnabled) {
|
|
21
36
|
return () => {};
|
|
22
37
|
}
|
|
23
38
|
const handlePanStart = event => {
|
|
@@ -45,14 +60,14 @@ export const usePanOnDrag = ({
|
|
|
45
60
|
}
|
|
46
61
|
throttledCallback(event, zoomData);
|
|
47
62
|
};
|
|
48
|
-
const panHandler = instance.addInteractionListener('
|
|
49
|
-
const panStartHandler = instance.addInteractionListener('
|
|
50
|
-
const panEndHandler = instance.addInteractionListener('
|
|
63
|
+
const panHandler = instance.addInteractionListener('zoomPan', handlePan);
|
|
64
|
+
const panStartHandler = instance.addInteractionListener('zoomPanStart', handlePanStart);
|
|
65
|
+
const panEndHandler = instance.addInteractionListener('zoomPanEnd', handlePanEnd);
|
|
51
66
|
return () => {
|
|
52
67
|
panStartHandler.cleanup();
|
|
53
68
|
panHandler.cleanup();
|
|
54
69
|
panEndHandler.cleanup();
|
|
55
70
|
throttledCallback.clear();
|
|
56
71
|
};
|
|
57
|
-
}, [instance, svgRef,
|
|
72
|
+
}, [instance, svgRef, isPanOnDragEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store, startRef]);
|
|
58
73
|
};
|
|
@@ -39,7 +39,7 @@ export const zoomAtPoint = (centerRatio, scaleRatio, currentZoomData, options) =
|
|
|
39
39
|
*/
|
|
40
40
|
export function isSpanValid(minRange, maxRange, isZoomIn, option) {
|
|
41
41
|
const newSpanPercent = maxRange - minRange;
|
|
42
|
-
if (isZoomIn && newSpanPercent < option.minSpan || !isZoomIn && newSpanPercent > option.maxSpan) {
|
|
42
|
+
if (newSpanPercent < 0 || isZoomIn && newSpanPercent < option.minSpan || !isZoomIn && newSpanPercent > option.maxSpan) {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
45
|
if (minRange < option.minStart || maxRange > option.maxEnd) {
|
|
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { useSelector, getSVGPoint, selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
|
|
5
5
|
import { rafThrottle } from '@mui/x-internals/rafThrottle';
|
|
6
6
|
import { getHorizontalCenterRatio, getVerticalCenterRatio, isSpanValid, zoomAtPoint } from "./useZoom.utils.js";
|
|
7
|
+
import { selectorZoomInteractionConfig } from "../ZoomInteractionConfig.selectors.js";
|
|
7
8
|
export const useZoomOnPinch = ({
|
|
8
9
|
store,
|
|
9
10
|
instance,
|
|
@@ -11,15 +12,28 @@ export const useZoomOnPinch = ({
|
|
|
11
12
|
}, setZoomDataCallback) => {
|
|
12
13
|
const drawingArea = useSelector(store, selectorChartDrawingArea);
|
|
13
14
|
const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
|
|
14
|
-
const
|
|
15
|
+
const config = useSelector(store, selectorZoomInteractionConfig, ['pinch']);
|
|
16
|
+
const isZoomOnPinchEnabled = React.useMemo(() => Object.keys(optionsLookup).length > 0 && config || false, [optionsLookup, config]);
|
|
17
|
+
React.useEffect(() => {
|
|
18
|
+
if (!isZoomOnPinchEnabled) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
instance.updateZoomInteractionListeners('zoomPinch', {
|
|
22
|
+
requiredKeys: config.requiredKeys
|
|
23
|
+
});
|
|
24
|
+
}, [config, isZoomOnPinchEnabled, instance]);
|
|
15
25
|
|
|
16
26
|
// Zoom on pinch
|
|
17
27
|
React.useEffect(() => {
|
|
18
28
|
const element = svgRef.current;
|
|
19
|
-
if (element === null || !
|
|
29
|
+
if (element === null || !isZoomOnPinchEnabled) {
|
|
20
30
|
return () => {};
|
|
21
31
|
}
|
|
22
32
|
const rafThrottledCallback = rafThrottle(event => {
|
|
33
|
+
// If the delta is 0, it means the pinch gesture is not valid.
|
|
34
|
+
if (event.detail.direction === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
23
37
|
setZoomDataCallback(prev => {
|
|
24
38
|
return prev.map(zoom => {
|
|
25
39
|
const option = optionsLookup[zoom.axisId];
|
|
@@ -28,11 +42,6 @@ export const useZoomOnPinch = ({
|
|
|
28
42
|
}
|
|
29
43
|
const isZoomIn = event.detail.direction > 0;
|
|
30
44
|
const scaleRatio = 1 + event.detail.deltaScale;
|
|
31
|
-
|
|
32
|
-
// If the delta is 0, it means the pinch gesture is not valid.
|
|
33
|
-
if (event.detail.direction === 0) {
|
|
34
|
-
return zoom;
|
|
35
|
-
}
|
|
36
45
|
const point = getSVGPoint(element, {
|
|
37
46
|
clientX: event.detail.centroid.x,
|
|
38
47
|
clientY: event.detail.centroid.y
|
|
@@ -50,10 +59,10 @@ export const useZoomOnPinch = ({
|
|
|
50
59
|
});
|
|
51
60
|
});
|
|
52
61
|
});
|
|
53
|
-
const zoomHandler = instance.addInteractionListener('
|
|
62
|
+
const zoomHandler = instance.addInteractionListener('zoomPinch', rafThrottledCallback);
|
|
54
63
|
return () => {
|
|
55
64
|
zoomHandler.cleanup();
|
|
56
65
|
rafThrottledCallback.clear();
|
|
57
66
|
};
|
|
58
|
-
}, [svgRef, drawingArea,
|
|
67
|
+
}, [svgRef, drawingArea, isZoomOnPinchEnabled, optionsLookup, store, instance, setZoomDataCallback]);
|
|
59
68
|
};
|
|
@@ -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 useZoomOnTapAndDrag: ({
|
|
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,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useSelector, getSVGPoint, selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
|
|
5
|
+
import { rafThrottle } from '@mui/x-internals/rafThrottle';
|
|
6
|
+
import { getHorizontalCenterRatio, getVerticalCenterRatio, isSpanValid, zoomAtPoint } from "./useZoom.utils.js";
|
|
7
|
+
import { selectorZoomInteractionConfig } from "../ZoomInteractionConfig.selectors.js";
|
|
8
|
+
export const useZoomOnTapAndDrag = ({
|
|
9
|
+
store,
|
|
10
|
+
instance,
|
|
11
|
+
svgRef
|
|
12
|
+
}, setZoomDataCallback) => {
|
|
13
|
+
const drawingArea = useSelector(store, selectorChartDrawingArea);
|
|
14
|
+
const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
|
|
15
|
+
const config = useSelector(store, selectorZoomInteractionConfig, ['tapAndDrag']);
|
|
16
|
+
const isZoomOnTapAndDragEnabled = React.useMemo(() => Object.keys(optionsLookup).length > 0 && config || false, [optionsLookup, config]);
|
|
17
|
+
React.useEffect(() => {
|
|
18
|
+
if (!isZoomOnTapAndDragEnabled) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
instance.updateZoomInteractionListeners('zoomTapAndDrag', {
|
|
22
|
+
requiredKeys: config.requiredKeys,
|
|
23
|
+
pointerMode: config.pointerMode,
|
|
24
|
+
pointerOptions: {
|
|
25
|
+
mouse: config.mouse,
|
|
26
|
+
touch: config.touch
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}, [config, isZoomOnTapAndDragEnabled, instance]);
|
|
30
|
+
|
|
31
|
+
// Zoom on tap and drag
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
const element = svgRef.current;
|
|
34
|
+
if (element === null || !isZoomOnTapAndDragEnabled) {
|
|
35
|
+
return () => {};
|
|
36
|
+
}
|
|
37
|
+
const rafThrottledCallback = rafThrottle(event => {
|
|
38
|
+
// If the delta is 0, we didn't move
|
|
39
|
+
if (event.detail.deltaY === 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
setZoomDataCallback(prev => {
|
|
43
|
+
return prev.map(zoom => {
|
|
44
|
+
const option = optionsLookup[zoom.axisId];
|
|
45
|
+
if (!option) {
|
|
46
|
+
return zoom;
|
|
47
|
+
}
|
|
48
|
+
const isZoomIn = event.detail.deltaY > 0;
|
|
49
|
+
const scaleRatio = 1 + event.detail.deltaY / 100;
|
|
50
|
+
const point = getSVGPoint(element, {
|
|
51
|
+
clientX: event.detail.initialCentroid.x,
|
|
52
|
+
clientY: event.detail.initialCentroid.y
|
|
53
|
+
});
|
|
54
|
+
const centerRatio = option.axisDirection === 'x' ? getHorizontalCenterRatio(point, drawingArea) : getVerticalCenterRatio(point, drawingArea);
|
|
55
|
+
const [newMinRange, newMaxRange] = zoomAtPoint(centerRatio, scaleRatio, zoom, option);
|
|
56
|
+
if (!isSpanValid(newMinRange, newMaxRange, isZoomIn, option)) {
|
|
57
|
+
return zoom;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
axisId: zoom.axisId,
|
|
61
|
+
start: newMinRange,
|
|
62
|
+
end: newMaxRange
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
const zoomHandler = instance.addInteractionListener('zoomTapAndDrag', rafThrottledCallback);
|
|
68
|
+
return () => {
|
|
69
|
+
zoomHandler.cleanup();
|
|
70
|
+
rafThrottledCallback.clear();
|
|
71
|
+
};
|
|
72
|
+
}, [svgRef, drawingArea, isZoomOnTapAndDragEnabled, optionsLookup, store, instance, setZoomDataCallback]);
|
|
73
|
+
};
|
|
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { useSelector, getSVGPoint, selectorChartDrawingArea, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
|
|
5
5
|
import { rafThrottle } from '@mui/x-internals/rafThrottle';
|
|
6
6
|
import { getHorizontalCenterRatio, getVerticalCenterRatio, getWheelScaleRatio, isSpanValid, zoomAtPoint } from "./useZoom.utils.js";
|
|
7
|
+
import { selectorZoomInteractionConfig } from "../ZoomInteractionConfig.selectors.js";
|
|
7
8
|
export const useZoomOnWheel = ({
|
|
8
9
|
store,
|
|
9
10
|
instance,
|
|
@@ -11,18 +12,27 @@ export const useZoomOnWheel = ({
|
|
|
11
12
|
}, setZoomDataCallback) => {
|
|
12
13
|
const drawingArea = useSelector(store, selectorChartDrawingArea);
|
|
13
14
|
const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
|
|
14
|
-
const isZoomEnabled = Object.keys(optionsLookup).length > 0;
|
|
15
15
|
const startedOutsideRef = React.useRef(false);
|
|
16
16
|
const startedOutsideTimeoutRef = React.useRef(null);
|
|
17
|
+
const config = useSelector(store, selectorZoomInteractionConfig, ['wheel']);
|
|
18
|
+
const isZoomOnWheelEnabled = React.useMemo(() => Object.keys(optionsLookup).length > 0 && config || false, [optionsLookup, config]);
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (!isZoomOnWheelEnabled) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
instance.updateZoomInteractionListeners('zoomTurnWheel', {
|
|
24
|
+
requiredKeys: config.requiredKeys
|
|
25
|
+
});
|
|
26
|
+
}, [config, isZoomOnWheelEnabled, instance]);
|
|
17
27
|
|
|
18
28
|
// Add event for chart zoom in/out
|
|
19
29
|
React.useEffect(() => {
|
|
20
30
|
const element = svgRef.current;
|
|
21
|
-
if (element === null || !
|
|
31
|
+
if (element === null || !isZoomOnWheelEnabled) {
|
|
22
32
|
return () => {};
|
|
23
33
|
}
|
|
24
34
|
const rafThrottledSetZoomData = rafThrottle(setZoomDataCallback);
|
|
25
|
-
const zoomOnWheelHandler = instance.addInteractionListener('
|
|
35
|
+
const zoomOnWheelHandler = instance.addInteractionListener('zoomTurnWheel', event => {
|
|
26
36
|
const point = getSVGPoint(element, {
|
|
27
37
|
clientX: event.detail.centroid.x,
|
|
28
38
|
clientY: event.detail.centroid.y
|
|
@@ -75,5 +85,5 @@ export const useZoomOnWheel = ({
|
|
|
75
85
|
startedOutsideRef.current = false;
|
|
76
86
|
rafThrottledSetZoomData.clear();
|
|
77
87
|
};
|
|
78
|
-
}, [svgRef, drawingArea,
|
|
88
|
+
}, [svgRef, drawingArea, isZoomOnWheelEnabled, optionsLookup, instance, setZoomDataCallback, store]);
|
|
79
89
|
};
|