@mui/x-charts-pro 8.0.0-alpha.1 → 8.0.0-alpha.11
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 +75 -34
- package/BarChartPro/BarChartPro.plugins.d.ts +10 -0
- package/BarChartPro/BarChartPro.plugins.js +3 -0
- package/CHANGELOG.md +2007 -230
- package/ChartContainerPro/ChartContainerPro.d.ts +33 -5
- package/ChartContainerPro/ChartContainerPro.js +55 -37
- package/ChartContainerPro/useChartContainerProProps.d.ts +6 -5
- package/ChartContainerPro/useChartContainerProProps.js +17 -13
- package/ChartDataProviderPro/ChartDataProviderPro.d.ts +37 -0
- package/ChartDataProviderPro/ChartDataProviderPro.js +105 -0
- package/{context → ChartDataProviderPro}/package.json +1 -1
- package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +8 -0
- package/ChartDataProviderPro/useChartDataProviderProProps.js +15 -0
- package/Heatmap/Heatmap.d.ts +1 -2
- package/Heatmap/Heatmap.js +36 -13
- package/Heatmap/Heatmap.plugins.d.ts +8 -0
- package/Heatmap/Heatmap.plugins.js +2 -0
- package/Heatmap/HeatmapItem.js +1 -1
- package/Heatmap/HeatmapTooltip.js +8 -28
- package/Heatmap/extremums.d.ts +2 -2
- package/Heatmap/formatter.d.ts +2 -2
- package/Heatmap/formatter.js +2 -1
- package/Heatmap/heatmapClasses.js +2 -1
- package/Heatmap/plugin.d.ts +2 -2
- package/Heatmap/plugin.js +4 -2
- package/Heatmap/tooltip.d.ts +3 -0
- package/Heatmap/tooltip.js +25 -0
- package/LineChartPro/LineChartPro.d.ts +2 -2
- package/LineChartPro/LineChartPro.js +81 -54
- package/LineChartPro/LineChartPro.plugins.d.ts +10 -0
- package/LineChartPro/LineChartPro.plugins.js +3 -0
- package/README.md +1 -1
- package/ScatterChartPro/ScatterChartPro.d.ts +2 -2
- package/ScatterChartPro/ScatterChartPro.js +59 -34
- package/ScatterChartPro/ScatterChartPro.plugins.d.ts +10 -0
- package/ScatterChartPro/ScatterChartPro.plugins.js +3 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +2 -1
- package/hooks/useSeries.d.ts +2 -4
- package/hooks/zoom/index.d.ts +1 -0
- package/hooks/zoom/index.js +1 -0
- package/hooks/zoom/useIsZoomInteracting.d.ts +6 -0
- package/hooks/zoom/useIsZoomInteracting.js +14 -0
- package/index.d.ts +3 -2
- package/index.js +5 -6
- package/internals/plugins/allPlugins.d.ts +11 -0
- package/internals/plugins/allPlugins.js +5 -0
- package/internals/plugins/useChartProZoom/creatZoomLookup.d.ts +3 -0
- package/internals/plugins/useChartProZoom/creatZoomLookup.js +12 -0
- package/internals/plugins/useChartProZoom/defaultizeZoom.d.ts +2 -0
- package/internals/plugins/useChartProZoom/defaultizeZoom.js +25 -0
- package/internals/plugins/useChartProZoom/index.d.ts +3 -0
- package/internals/plugins/useChartProZoom/index.js +3 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +3 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.js +303 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +377 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +10 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +50 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.utils.d.ts +45 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.utils.js +126 -0
- package/internals/plugins/useChartProZoom/zoom.types.d.ts +53 -0
- package/internals/utils/releaseInfo.js +2 -2
- package/models/index.d.ts +1 -0
- package/models/index.js +2 -1
- package/modern/BarChartPro/BarChartPro.js +75 -34
- package/modern/BarChartPro/BarChartPro.plugins.js +3 -0
- package/modern/ChartContainerPro/ChartContainerPro.js +55 -37
- package/modern/ChartContainerPro/useChartContainerProProps.js +17 -13
- package/modern/ChartDataProviderPro/ChartDataProviderPro.js +105 -0
- package/modern/ChartDataProviderPro/useChartDataProviderProProps.js +15 -0
- package/modern/Heatmap/Heatmap.js +36 -13
- package/modern/Heatmap/Heatmap.plugins.js +2 -0
- package/modern/Heatmap/HeatmapItem.js +1 -1
- package/modern/Heatmap/HeatmapTooltip.js +8 -28
- package/modern/Heatmap/formatter.js +2 -1
- package/modern/Heatmap/heatmapClasses.js +2 -1
- package/modern/Heatmap/plugin.js +4 -2
- package/modern/Heatmap/tooltip.js +25 -0
- package/modern/LineChartPro/LineChartPro.js +81 -54
- package/modern/LineChartPro/LineChartPro.plugins.js +3 -0
- package/modern/ScatterChartPro/ScatterChartPro.js +59 -34
- package/modern/ScatterChartPro/ScatterChartPro.plugins.js +3 -0
- package/modern/hooks/index.js +2 -1
- package/modern/hooks/zoom/index.js +1 -0
- package/modern/hooks/zoom/useIsZoomInteracting.js +14 -0
- package/modern/index.js +5 -6
- package/modern/internals/plugins/allPlugins.js +5 -0
- package/modern/internals/plugins/useChartProZoom/creatZoomLookup.js +12 -0
- package/modern/internals/plugins/useChartProZoom/defaultizeZoom.js +25 -0
- package/modern/internals/plugins/useChartProZoom/index.js +3 -0
- package/modern/internals/plugins/useChartProZoom/useChartProZoom.js +303 -0
- package/modern/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +10 -0
- package/modern/internals/plugins/useChartProZoom/useChartProZoom.types.js +1 -0
- package/modern/internals/plugins/useChartProZoom/useChartProZoom.utils.js +126 -0
- package/modern/internals/plugins/useChartProZoom/zoom.types.js +1 -0
- package/modern/internals/utils/releaseInfo.js +2 -2
- package/modern/models/index.js +2 -1
- package/node/BarChartPro/BarChartPro.js +74 -33
- package/node/BarChartPro/BarChartPro.plugins.js +9 -0
- package/node/ChartContainerPro/ChartContainerPro.js +54 -36
- package/node/ChartContainerPro/useChartContainerProProps.js +17 -13
- package/node/ChartDataProviderPro/ChartDataProviderPro.js +111 -0
- package/node/ChartDataProviderPro/useChartDataProviderProProps.js +21 -0
- package/node/Heatmap/Heatmap.js +36 -13
- package/node/Heatmap/Heatmap.plugins.js +8 -0
- package/node/Heatmap/HeatmapItem.js +2 -2
- package/node/Heatmap/HeatmapTooltip.js +6 -26
- package/node/Heatmap/formatter.js +2 -1
- package/node/Heatmap/heatmapClasses.js +5 -4
- package/node/Heatmap/plugin.js +4 -2
- package/node/Heatmap/tooltip.js +31 -0
- package/node/LineChartPro/LineChartPro.js +80 -53
- package/node/LineChartPro/LineChartPro.plugins.js +9 -0
- package/node/ScatterChartPro/ScatterChartPro.js +58 -33
- package/node/ScatterChartPro/ScatterChartPro.plugins.js +9 -0
- package/node/hooks/index.js +16 -1
- package/node/{context/CartesianProviderPro → hooks/zoom}/index.js +4 -4
- package/node/hooks/zoom/useIsZoomInteracting.js +19 -0
- package/node/index.js +34 -23
- package/node/internals/plugins/allPlugins.js +11 -0
- package/node/internals/plugins/useChartProZoom/creatZoomLookup.js +19 -0
- package/node/internals/plugins/useChartProZoom/defaultizeZoom.js +33 -0
- package/node/internals/plugins/useChartProZoom/index.js +38 -0
- package/node/internals/plugins/useChartProZoom/useChartProZoom.js +310 -0
- package/node/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +18 -0
- package/node/internals/plugins/useChartProZoom/useChartProZoom.utils.js +140 -0
- package/node/internals/plugins/useChartProZoom/zoom.types.js +5 -0
- package/node/internals/utils/releaseInfo.js +4 -3
- package/package.json +6 -6
- package/typeOverloads/modules.d.ts +8 -1
- package/context/CartesianProviderPro/CartesianProviderPro.d.ts +0 -6
- package/context/CartesianProviderPro/CartesianProviderPro.js +0 -89
- package/context/CartesianProviderPro/createAxisFilterMapper.d.ts +0 -12
- package/context/CartesianProviderPro/createAxisFilterMapper.js +0 -60
- package/context/CartesianProviderPro/index.d.ts +0 -1
- package/context/CartesianProviderPro/index.js +0 -1
- package/context/ChartDataProviderPro/ChartDataProviderPro.d.ts +0 -10
- package/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -299
- package/context/ChartDataProviderPro/useChartDataProviderProProps.d.ts +0 -14
- package/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -43
- package/context/ZoomProvider/Zoom.types.d.ts +0 -144
- package/context/ZoomProvider/ZoomContext.d.ts +0 -4
- package/context/ZoomProvider/ZoomContext.js +0 -16
- package/context/ZoomProvider/ZoomProvider.d.ts +0 -3
- package/context/ZoomProvider/ZoomProvider.js +0 -56
- package/context/ZoomProvider/ZoomSetup.d.ts +0 -9
- package/context/ZoomProvider/ZoomSetup.js +0 -16
- package/context/ZoomProvider/defaultizeZoom.d.ts +0 -2
- package/context/ZoomProvider/defaultizeZoom.js +0 -32
- package/context/ZoomProvider/index.d.ts +0 -3
- package/context/ZoomProvider/index.js +0 -3
- package/context/ZoomProvider/initializeZoomData.d.ts +0 -6
- package/context/ZoomProvider/initializeZoomData.js +0 -13
- package/context/ZoomProvider/useSetupPan.d.ts +0 -1
- package/context/ZoomProvider/useSetupPan.js +0 -106
- package/context/ZoomProvider/useSetupZoom.d.ts +0 -1
- package/context/ZoomProvider/useSetupZoom.js +0 -274
- package/context/ZoomProvider/useZoom.d.ts +0 -7
- package/context/ZoomProvider/useZoom.js +0 -19
- package/context/index.d.ts +0 -3
- package/context/index.js +0 -5
- package/modern/context/CartesianProviderPro/CartesianProviderPro.js +0 -89
- package/modern/context/CartesianProviderPro/createAxisFilterMapper.js +0 -60
- package/modern/context/CartesianProviderPro/index.js +0 -1
- package/modern/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -299
- package/modern/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -43
- package/modern/context/ZoomProvider/ZoomContext.js +0 -16
- package/modern/context/ZoomProvider/ZoomProvider.js +0 -56
- package/modern/context/ZoomProvider/ZoomSetup.js +0 -16
- package/modern/context/ZoomProvider/defaultizeZoom.js +0 -32
- package/modern/context/ZoomProvider/index.js +0 -3
- package/modern/context/ZoomProvider/initializeZoomData.js +0 -13
- package/modern/context/ZoomProvider/useSetupPan.js +0 -106
- package/modern/context/ZoomProvider/useSetupZoom.js +0 -274
- package/modern/context/ZoomProvider/useZoom.js +0 -19
- package/modern/context/index.js +0 -5
- package/node/context/CartesianProviderPro/CartesianProviderPro.js +0 -95
- package/node/context/CartesianProviderPro/createAxisFilterMapper.js +0 -68
- package/node/context/ChartDataProviderPro/ChartDataProviderPro.js +0 -305
- package/node/context/ChartDataProviderPro/useChartDataProviderProProps.js +0 -50
- package/node/context/ZoomProvider/ZoomContext.js +0 -23
- package/node/context/ZoomProvider/ZoomProvider.js +0 -63
- package/node/context/ZoomProvider/ZoomSetup.js +0 -20
- package/node/context/ZoomProvider/defaultizeZoom.js +0 -40
- package/node/context/ZoomProvider/index.js +0 -38
- package/node/context/ZoomProvider/initializeZoomData.js +0 -20
- package/node/context/ZoomProvider/useSetupPan.js +0 -114
- package/node/context/ZoomProvider/useSetupZoom.js +0 -281
- package/node/context/ZoomProvider/useZoom.js +0 -25
- package/node/context/index.js +0 -27
- /package/{context/ChartDataProviderPro → ChartDataProviderPro}/index.d.ts +0 -0
- /package/{context/ChartDataProviderPro → ChartDataProviderPro}/index.js +0 -0
- /package/{context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/useChartProZoom.types.js} +0 -0
- /package/{modern/context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/zoom.types.js} +0 -0
- /package/modern/{context/ChartDataProviderPro → ChartDataProviderPro}/index.js +0 -0
- /package/node/{context/ChartDataProviderPro → ChartDataProviderPro}/index.js +0 -0
- /package/node/{context/ZoomProvider/Zoom.types.js → internals/plugins/useChartProZoom/useChartProZoom.types.js} +0 -0
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["
|
|
5
|
+
const _excluded = ["initialZoom", "onZoomChange", "apiRef"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { useThemeProps } from '@mui/material/styles';
|
|
9
9
|
import { ChartsOverlay } from '@mui/x-charts/ChartsOverlay';
|
|
10
10
|
import { ScatterPlot } from '@mui/x-charts/ScatterChart';
|
|
11
|
-
import { ZAxisContextProvider } from '@mui/x-charts/context';
|
|
12
11
|
import { ChartsVoronoiHandler } from '@mui/x-charts/ChartsVoronoiHandler';
|
|
13
12
|
import { ChartsAxis } from '@mui/x-charts/ChartsAxis';
|
|
14
13
|
import { ChartsGrid } from '@mui/x-charts/ChartsGrid';
|
|
15
14
|
import { ChartsLegend } from '@mui/x-charts/ChartsLegend';
|
|
15
|
+
import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
|
|
16
16
|
import { ChartsAxisHighlight } from '@mui/x-charts/ChartsAxisHighlight';
|
|
17
17
|
import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip';
|
|
18
|
-
import { useScatterChartProps } from '@mui/x-charts/internals';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
18
|
+
import { useScatterChartProps, ChartsWrapper } from '@mui/x-charts/internals';
|
|
19
|
+
import { useChartContainerProProps } from "../ChartContainerPro/useChartContainerProProps.js";
|
|
20
|
+
import { ChartDataProviderPro } from "../ChartDataProviderPro/index.js";
|
|
21
|
+
import { SCATTER_CHART_PRO_PLUGINS } from "./ScatterChartPro.plugins.js";
|
|
21
22
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
23
|
/**
|
|
23
24
|
* Demos:
|
|
@@ -35,13 +36,14 @@ const ScatterChartPro = /*#__PURE__*/React.forwardRef(function ScatterChartPro(i
|
|
|
35
36
|
name: 'MuiScatterChartPro'
|
|
36
37
|
});
|
|
37
38
|
const {
|
|
38
|
-
|
|
39
|
-
onZoomChange
|
|
39
|
+
initialZoom,
|
|
40
|
+
onZoomChange,
|
|
41
|
+
apiRef
|
|
40
42
|
} = props,
|
|
41
43
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
42
44
|
const {
|
|
45
|
+
chartsWrapperProps,
|
|
43
46
|
chartContainerProps,
|
|
44
|
-
zAxisProps,
|
|
45
47
|
voronoiHandlerProps,
|
|
46
48
|
chartsAxisProps,
|
|
47
49
|
gridProps,
|
|
@@ -51,17 +53,26 @@ const ScatterChartPro = /*#__PURE__*/React.forwardRef(function ScatterChartPro(i
|
|
|
51
53
|
axisHighlightProps,
|
|
52
54
|
children
|
|
53
55
|
} = useScatterChartProps(other);
|
|
56
|
+
const {
|
|
57
|
+
chartDataProviderProProps,
|
|
58
|
+
chartsSurfaceProps
|
|
59
|
+
} = useChartContainerProProps(_extends({}, chartContainerProps, {
|
|
60
|
+
initialZoom,
|
|
61
|
+
onZoomChange,
|
|
62
|
+
apiRef,
|
|
63
|
+
plugins: SCATTER_CHART_PRO_PLUGINS
|
|
64
|
+
}), ref);
|
|
54
65
|
const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
|
|
55
|
-
return /*#__PURE__*/_jsx(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
66
|
+
return /*#__PURE__*/_jsx(ChartDataProviderPro, _extends({}, chartDataProviderProProps, {
|
|
67
|
+
children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
|
|
68
|
+
children: [!props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
|
|
69
|
+
children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx("g", {
|
|
70
|
+
"data-drawing-container": true,
|
|
71
|
+
children: /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps))
|
|
72
|
+
}), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props?.slotProps?.tooltip, {
|
|
73
|
+
trigger: "item"
|
|
74
|
+
})), children]
|
|
75
|
+
}))]
|
|
65
76
|
}))
|
|
66
77
|
}));
|
|
67
78
|
});
|
|
@@ -70,6 +81,11 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
70
81
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
71
82
|
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
72
83
|
// ----------------------------------------------------------------------
|
|
84
|
+
apiRef: PropTypes.shape({
|
|
85
|
+
current: PropTypes.shape({
|
|
86
|
+
setZoomData: PropTypes.func.isRequired
|
|
87
|
+
})
|
|
88
|
+
}),
|
|
73
89
|
/**
|
|
74
90
|
* The configuration of axes highlight.
|
|
75
91
|
* @see See {@link https://mui.com/x/react-charts/highlighting/ highlighting docs} for more details.
|
|
@@ -89,7 +105,7 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
89
105
|
className: PropTypes.string,
|
|
90
106
|
/**
|
|
91
107
|
* Color palette used to colorize multiple series.
|
|
92
|
-
* @default
|
|
108
|
+
* @default rainbowSurgePalette
|
|
93
109
|
*/
|
|
94
110
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
95
111
|
/**
|
|
@@ -124,12 +140,26 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
124
140
|
*/
|
|
125
141
|
hideLegend: PropTypes.bool,
|
|
126
142
|
/**
|
|
127
|
-
* The
|
|
143
|
+
* The highlighted item.
|
|
144
|
+
* Used when the highlight is controlled.
|
|
128
145
|
*/
|
|
129
146
|
highlightedItem: PropTypes.shape({
|
|
130
147
|
dataIndex: PropTypes.number,
|
|
131
|
-
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
148
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired
|
|
132
149
|
}),
|
|
150
|
+
/**
|
|
151
|
+
* This prop is used to help implement the accessibility logic.
|
|
152
|
+
* If you don't provide this prop. It falls back to a randomly generated id.
|
|
153
|
+
*/
|
|
154
|
+
id: PropTypes.string,
|
|
155
|
+
/**
|
|
156
|
+
* The list of zoom data related to each axis.
|
|
157
|
+
*/
|
|
158
|
+
initialZoom: PropTypes.arrayOf(PropTypes.shape({
|
|
159
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
160
|
+
end: PropTypes.number.isRequired,
|
|
161
|
+
start: PropTypes.number.isRequired
|
|
162
|
+
})),
|
|
133
163
|
/**
|
|
134
164
|
* Indicate which axis to display the left of the charts.
|
|
135
165
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -145,7 +175,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
145
175
|
* The margin between the SVG and the drawing area.
|
|
146
176
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
147
177
|
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
148
|
-
* @default object Depends on the charts type.
|
|
149
178
|
*/
|
|
150
179
|
margin: PropTypes.shape({
|
|
151
180
|
bottom: PropTypes.number,
|
|
@@ -153,6 +182,13 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
153
182
|
right: PropTypes.number,
|
|
154
183
|
top: PropTypes.number
|
|
155
184
|
}),
|
|
185
|
+
/**
|
|
186
|
+
* The function called for onClick events.
|
|
187
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
188
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
189
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
190
|
+
*/
|
|
191
|
+
onAxisClick: PropTypes.func,
|
|
156
192
|
/**
|
|
157
193
|
* The callback fired when the highlighted item changes.
|
|
158
194
|
*
|
|
@@ -198,6 +234,7 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
198
234
|
*/
|
|
199
235
|
slots: PropTypes.object,
|
|
200
236
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
237
|
+
theme: PropTypes.oneOf(['dark', 'light']),
|
|
201
238
|
title: PropTypes.string,
|
|
202
239
|
/**
|
|
203
240
|
* Indicate which axis to display the top of the charts.
|
|
@@ -245,7 +282,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
245
282
|
hideTooltip: PropTypes.bool,
|
|
246
283
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
247
284
|
label: PropTypes.string,
|
|
248
|
-
labelFontSize: PropTypes.number,
|
|
249
285
|
labelStyle: PropTypes.object,
|
|
250
286
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
251
287
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
@@ -256,7 +292,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
256
292
|
slots: PropTypes.object,
|
|
257
293
|
stroke: PropTypes.string,
|
|
258
294
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
259
|
-
tickFontSize: PropTypes.number,
|
|
260
295
|
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
261
296
|
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
262
297
|
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
@@ -308,7 +343,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
308
343
|
hideTooltip: PropTypes.bool,
|
|
309
344
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
310
345
|
label: PropTypes.string,
|
|
311
|
-
labelFontSize: PropTypes.number,
|
|
312
346
|
labelStyle: PropTypes.object,
|
|
313
347
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
314
348
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
@@ -319,7 +353,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
319
353
|
slots: PropTypes.object,
|
|
320
354
|
stroke: PropTypes.string,
|
|
321
355
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
322
|
-
tickFontSize: PropTypes.number,
|
|
323
356
|
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
324
357
|
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
325
358
|
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
@@ -364,14 +397,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
364
397
|
id: PropTypes.string,
|
|
365
398
|
max: PropTypes.number,
|
|
366
399
|
min: PropTypes.number
|
|
367
|
-
})),
|
|
368
|
-
/**
|
|
369
|
-
* The list of zoom data related to each axis.
|
|
370
|
-
*/
|
|
371
|
-
zoom: PropTypes.arrayOf(PropTypes.shape({
|
|
372
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
373
|
-
end: PropTypes.number.isRequired,
|
|
374
|
-
start: PropTypes.number.isRequired
|
|
375
400
|
}))
|
|
376
401
|
} : void 0;
|
|
377
402
|
export { ScatterChartPro };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight } from '@mui/x-charts/internals';
|
|
2
|
+
import { useChartProZoom } from "../internals/plugins/useChartProZoom/index.js";
|
|
3
|
+
export const SCATTER_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartProZoom];
|
package/modern/hooks/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { useHeatmapSeries as unstable_useHeatmapSeries } from "./useSeries.js";
|
|
1
|
+
export { useHeatmapSeries as unstable_useHeatmapSeries } from "./useSeries.js";
|
|
2
|
+
export * from "./zoom/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useIsZoomInteracting.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useSelector, useStore } from '@mui/x-charts/internals';
|
|
4
|
+
import { selectorChartZoomIsInteracting } from "../../internals/plugins/useChartProZoom/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Get access to the zoom state.
|
|
7
|
+
*
|
|
8
|
+
* @returns {boolean} Inform the zoom is interacting.
|
|
9
|
+
*/
|
|
10
|
+
export function useIsZoomInteracting() {
|
|
11
|
+
const store = useStore();
|
|
12
|
+
const isInteracting = useSelector(store, selectorChartZoomIsInteracting);
|
|
13
|
+
return isInteracting;
|
|
14
|
+
}
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts-pro v8.0.0-alpha.
|
|
2
|
+
* @mui/x-charts-pro v8.0.0-alpha.11
|
|
3
3
|
*
|
|
4
4
|
* @license MUI X Commercial
|
|
5
5
|
* This source code is licensed under the commercial license found in the
|
|
@@ -24,7 +24,6 @@ export * from '@mui/x-charts/ChartsTooltip';
|
|
|
24
24
|
export * from '@mui/x-charts/ChartsLegend';
|
|
25
25
|
export * from '@mui/x-charts/ChartsAxisHighlight';
|
|
26
26
|
export * from '@mui/x-charts/ChartsVoronoiHandler';
|
|
27
|
-
export * from '@mui/x-charts/ChartsOnAxisClickHandler';
|
|
28
27
|
export * from '@mui/x-charts/BarChart';
|
|
29
28
|
export * from '@mui/x-charts/LineChart';
|
|
30
29
|
export * from '@mui/x-charts/PieChart';
|
|
@@ -32,13 +31,13 @@ export * from '@mui/x-charts/ScatterChart';
|
|
|
32
31
|
export * from '@mui/x-charts/SparkLineChart';
|
|
33
32
|
export * from '@mui/x-charts/Gauge';
|
|
34
33
|
export * from '@mui/x-charts/ChartsSurface';
|
|
34
|
+
export * from '@mui/x-charts/ChartDataProvider';
|
|
35
|
+
export * from '@mui/x-charts/ChartsLabel';
|
|
35
36
|
|
|
36
37
|
// Pro components
|
|
37
38
|
export * from "./Heatmap/index.js";
|
|
38
39
|
export * from "./ChartContainerPro/index.js";
|
|
40
|
+
export * from "./ChartDataProviderPro/index.js";
|
|
39
41
|
export * from "./ScatterChartPro/index.js";
|
|
40
42
|
export * from "./BarChartPro/index.js";
|
|
41
|
-
export * from "./LineChartPro/index.js";
|
|
42
|
-
|
|
43
|
-
// Pro context
|
|
44
|
-
export * from "./context/index.js";
|
|
43
|
+
export * from "./LineChartPro/index.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// This file should be removed after creating all plugins in favor of a file per chart type.
|
|
2
|
+
|
|
3
|
+
import { useChartCartesianAxis, useChartInteraction, useChartZAxis, useChartHighlight } from '@mui/x-charts/internals';
|
|
4
|
+
import { useChartProZoom } from "./useChartProZoom/index.js";
|
|
5
|
+
export const ALL_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartProZoom];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defaultizeZoom } from "./defaultizeZoom.js";
|
|
2
|
+
export const creatZoomLookup = axisDirection => axes => axes.reduce((acc, v) => {
|
|
3
|
+
const {
|
|
4
|
+
zoom,
|
|
5
|
+
id: axisId
|
|
6
|
+
} = v;
|
|
7
|
+
const defaultizedZoom = defaultizeZoom(zoom, axisId, axisDirection);
|
|
8
|
+
if (defaultizedZoom) {
|
|
9
|
+
acc[axisId] = defaultizedZoom;
|
|
10
|
+
}
|
|
11
|
+
return acc;
|
|
12
|
+
}, {});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
const defaultZoomOptions = {
|
|
3
|
+
minStart: 0,
|
|
4
|
+
maxEnd: 100,
|
|
5
|
+
step: 5,
|
|
6
|
+
minSpan: 10,
|
|
7
|
+
maxSpan: 100,
|
|
8
|
+
panning: true,
|
|
9
|
+
filterMode: 'keep'
|
|
10
|
+
};
|
|
11
|
+
export const defaultizeZoom = (zoom, axisId, axisDirection) => {
|
|
12
|
+
if (!zoom) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (zoom === true) {
|
|
16
|
+
return _extends({
|
|
17
|
+
axisId,
|
|
18
|
+
axisDirection
|
|
19
|
+
}, defaultZoomOptions);
|
|
20
|
+
}
|
|
21
|
+
return _extends({
|
|
22
|
+
axisId,
|
|
23
|
+
axisDirection
|
|
24
|
+
}, defaultZoomOptions, zoom);
|
|
25
|
+
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useSelector, getSVGPoint, selectorChartDrawingArea } from '@mui/x-charts/internals';
|
|
6
|
+
import { creatZoomLookup } from "./creatZoomLookup.js";
|
|
7
|
+
import { getDiff, getHorizontalCenterRatio, getPinchScaleRatio, getVerticalCenterRatio, getWheelScaleRatio, isSpanValid, preventDefault, zoomAtPoint } from "./useChartProZoom.utils.js";
|
|
8
|
+
import { selectorChartZoomOptionsLookup } from "./useChartProZoom.selectors.js";
|
|
9
|
+
|
|
10
|
+
// It is helpful to avoid the need to provide the possibly auto-generated id for each axis.
|
|
11
|
+
function initializeZoomData(options) {
|
|
12
|
+
return Object.values(options).map(({
|
|
13
|
+
axisId,
|
|
14
|
+
minStart: start,
|
|
15
|
+
maxEnd: end
|
|
16
|
+
}) => ({
|
|
17
|
+
axisId,
|
|
18
|
+
start,
|
|
19
|
+
end
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
export const useChartProZoom = ({
|
|
23
|
+
store,
|
|
24
|
+
instance,
|
|
25
|
+
svgRef,
|
|
26
|
+
params
|
|
27
|
+
}) => {
|
|
28
|
+
const drawingArea = useSelector(store, selectorChartDrawingArea);
|
|
29
|
+
const optionsLookup = useSelector(store, selectorChartZoomOptionsLookup);
|
|
30
|
+
const isZoomEnabled = Object.keys(optionsLookup).length > 0;
|
|
31
|
+
|
|
32
|
+
// Add events
|
|
33
|
+
const panningEventCacheRef = React.useRef([]);
|
|
34
|
+
const zoomEventCacheRef = React.useRef([]);
|
|
35
|
+
const eventPrevDiff = React.useRef(0);
|
|
36
|
+
const interactionTimeoutRef = React.useRef(undefined);
|
|
37
|
+
const setIsInteracting = React.useCallback(isInteracting => {
|
|
38
|
+
store.update(prev => _extends({}, prev, {
|
|
39
|
+
zoom: _extends({}, prev.zoom, {
|
|
40
|
+
isInteracting
|
|
41
|
+
})
|
|
42
|
+
}));
|
|
43
|
+
}, [store]);
|
|
44
|
+
const setZoomDataCallback = React.useCallback(zoomData => {
|
|
45
|
+
store.update(prevState => {
|
|
46
|
+
const newZoomData = typeof zoomData === 'function' ? zoomData(prevState.zoom.zoomData) : zoomData;
|
|
47
|
+
params.onZoomChange?.(newZoomData);
|
|
48
|
+
return _extends({}, prevState, {
|
|
49
|
+
zoom: _extends({}, prevState.zoom, {
|
|
50
|
+
zoomData: newZoomData
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}, [params, store]);
|
|
55
|
+
|
|
56
|
+
// Add event for chart panning
|
|
57
|
+
const isPanEnabled = React.useMemo(() => Object.values(optionsLookup).some(v => v.panning) || false, [optionsLookup]);
|
|
58
|
+
const isDraggingRef = React.useRef(false);
|
|
59
|
+
const touchStartRef = React.useRef(null);
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
const element = svgRef.current;
|
|
62
|
+
if (element === null || !isPanEnabled) {
|
|
63
|
+
return () => {};
|
|
64
|
+
}
|
|
65
|
+
const handlePan = event => {
|
|
66
|
+
if (element === null || !isDraggingRef.current || panningEventCacheRef.current.length > 1) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (touchStartRef.current == null) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const point = getSVGPoint(element, event);
|
|
73
|
+
const movementX = point.x - touchStartRef.current.x;
|
|
74
|
+
const movementY = (point.y - touchStartRef.current.y) * -1;
|
|
75
|
+
const newZoomData = touchStartRef.current.zoomData.map(zoom => {
|
|
76
|
+
const options = optionsLookup[zoom.axisId];
|
|
77
|
+
if (!options || !options.panning) {
|
|
78
|
+
return zoom;
|
|
79
|
+
}
|
|
80
|
+
const min = zoom.start;
|
|
81
|
+
const max = zoom.end;
|
|
82
|
+
const span = max - min;
|
|
83
|
+
const MIN_PERCENT = options.minStart;
|
|
84
|
+
const MAX_PERCENT = options.maxEnd;
|
|
85
|
+
const movement = options.axisDirection === 'x' ? movementX : movementY;
|
|
86
|
+
const dimension = options.axisDirection === 'x' ? drawingArea.width : drawingArea.height;
|
|
87
|
+
let newMinPercent = min - movement / dimension * span;
|
|
88
|
+
let newMaxPercent = max - movement / dimension * span;
|
|
89
|
+
if (newMinPercent < MIN_PERCENT) {
|
|
90
|
+
newMinPercent = MIN_PERCENT;
|
|
91
|
+
newMaxPercent = newMinPercent + span;
|
|
92
|
+
}
|
|
93
|
+
if (newMaxPercent > MAX_PERCENT) {
|
|
94
|
+
newMaxPercent = MAX_PERCENT;
|
|
95
|
+
newMinPercent = newMaxPercent - span;
|
|
96
|
+
}
|
|
97
|
+
if (newMinPercent < MIN_PERCENT || newMaxPercent > MAX_PERCENT || span < options.minSpan || span > options.maxSpan) {
|
|
98
|
+
return zoom;
|
|
99
|
+
}
|
|
100
|
+
return _extends({}, zoom, {
|
|
101
|
+
start: newMinPercent,
|
|
102
|
+
end: newMaxPercent
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
setZoomDataCallback(newZoomData);
|
|
106
|
+
};
|
|
107
|
+
const handleDown = event => {
|
|
108
|
+
panningEventCacheRef.current.push(event);
|
|
109
|
+
const point = getSVGPoint(element, event);
|
|
110
|
+
if (!instance.isPointInside(point)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// If there is only one pointer, prevent selecting text
|
|
114
|
+
if (panningEventCacheRef.current.length === 1) {
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
}
|
|
117
|
+
isDraggingRef.current = true;
|
|
118
|
+
setIsInteracting(true);
|
|
119
|
+
touchStartRef.current = {
|
|
120
|
+
x: point.x,
|
|
121
|
+
y: point.y,
|
|
122
|
+
zoomData: store.getSnapshot().zoom.zoomData
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const handleUp = event => {
|
|
126
|
+
panningEventCacheRef.current.splice(panningEventCacheRef.current.findIndex(cachedEvent => cachedEvent.pointerId === event.pointerId), 1);
|
|
127
|
+
setIsInteracting(false);
|
|
128
|
+
isDraggingRef.current = false;
|
|
129
|
+
touchStartRef.current = null;
|
|
130
|
+
};
|
|
131
|
+
element.addEventListener('pointerdown', handleDown);
|
|
132
|
+
document.addEventListener('pointermove', handlePan);
|
|
133
|
+
document.addEventListener('pointerup', handleUp);
|
|
134
|
+
document.addEventListener('pointercancel', handleUp);
|
|
135
|
+
document.addEventListener('pointerleave', handleUp);
|
|
136
|
+
return () => {
|
|
137
|
+
element.removeEventListener('pointerdown', handleDown);
|
|
138
|
+
document.removeEventListener('pointermove', handlePan);
|
|
139
|
+
document.removeEventListener('pointerup', handleUp);
|
|
140
|
+
document.removeEventListener('pointercancel', handleUp);
|
|
141
|
+
document.removeEventListener('pointerleave', handleUp);
|
|
142
|
+
};
|
|
143
|
+
}, [instance, svgRef, isDraggingRef, setIsInteracting, isPanEnabled, optionsLookup, drawingArea.width, drawingArea.height, setZoomDataCallback, store]);
|
|
144
|
+
|
|
145
|
+
// Add event for chart zoom in/out
|
|
146
|
+
React.useEffect(() => {
|
|
147
|
+
const element = svgRef.current;
|
|
148
|
+
if (element === null || !isZoomEnabled) {
|
|
149
|
+
return () => {};
|
|
150
|
+
}
|
|
151
|
+
const wheelHandler = event => {
|
|
152
|
+
if (element === null) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const point = getSVGPoint(element, event);
|
|
156
|
+
if (!instance.isPointInside(point)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
if (interactionTimeoutRef.current) {
|
|
161
|
+
clearTimeout(interactionTimeoutRef.current);
|
|
162
|
+
}
|
|
163
|
+
setIsInteracting(true);
|
|
164
|
+
// Debounce transition to `isInteractive=false`.
|
|
165
|
+
// Useful because wheel events don't have an "end" event.
|
|
166
|
+
interactionTimeoutRef.current = window.setTimeout(() => {
|
|
167
|
+
setIsInteracting(false);
|
|
168
|
+
}, 166);
|
|
169
|
+
setZoomDataCallback(prevZoomData => {
|
|
170
|
+
return prevZoomData.map(zoom => {
|
|
171
|
+
const option = optionsLookup[zoom.axisId];
|
|
172
|
+
if (!option) {
|
|
173
|
+
return zoom;
|
|
174
|
+
}
|
|
175
|
+
const centerRatio = option.axisDirection === 'x' ? getHorizontalCenterRatio(point, drawingArea) : getVerticalCenterRatio(point, drawingArea);
|
|
176
|
+
const {
|
|
177
|
+
scaleRatio,
|
|
178
|
+
isZoomIn
|
|
179
|
+
} = getWheelScaleRatio(event, option.step);
|
|
180
|
+
const [newMinRange, newMaxRange] = zoomAtPoint(centerRatio, scaleRatio, zoom, option);
|
|
181
|
+
if (!isSpanValid(newMinRange, newMaxRange, isZoomIn, option)) {
|
|
182
|
+
return zoom;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
axisId: zoom.axisId,
|
|
186
|
+
start: newMinRange,
|
|
187
|
+
end: newMaxRange
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
function pointerDownHandler(event) {
|
|
193
|
+
zoomEventCacheRef.current.push(event);
|
|
194
|
+
setIsInteracting(true);
|
|
195
|
+
}
|
|
196
|
+
function pointerMoveHandler(event) {
|
|
197
|
+
if (element === null) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const index = zoomEventCacheRef.current.findIndex(cachedEv => cachedEv.pointerId === event.pointerId);
|
|
201
|
+
zoomEventCacheRef.current[index] = event;
|
|
202
|
+
|
|
203
|
+
// Not a pinch gesture
|
|
204
|
+
if (zoomEventCacheRef.current.length !== 2) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const firstEvent = zoomEventCacheRef.current[0];
|
|
208
|
+
const curDiff = getDiff(zoomEventCacheRef.current);
|
|
209
|
+
setZoomDataCallback(prevZoomData => {
|
|
210
|
+
const newZoomData = prevZoomData.map(zoom => {
|
|
211
|
+
const option = optionsLookup[zoom.axisId];
|
|
212
|
+
if (!option) {
|
|
213
|
+
return zoom;
|
|
214
|
+
}
|
|
215
|
+
const {
|
|
216
|
+
scaleRatio,
|
|
217
|
+
isZoomIn
|
|
218
|
+
} = getPinchScaleRatio(curDiff, eventPrevDiff.current, option.step);
|
|
219
|
+
|
|
220
|
+
// If the scale ratio is 0, it means the pinch gesture is not valid.
|
|
221
|
+
if (scaleRatio === 0) {
|
|
222
|
+
return zoom;
|
|
223
|
+
}
|
|
224
|
+
const point = getSVGPoint(element, firstEvent);
|
|
225
|
+
const centerRatio = option.axisDirection === 'x' ? getHorizontalCenterRatio(point, drawingArea) : getVerticalCenterRatio(point, drawingArea);
|
|
226
|
+
const [newMinRange, newMaxRange] = zoomAtPoint(centerRatio, scaleRatio, zoom, option);
|
|
227
|
+
if (!isSpanValid(newMinRange, newMaxRange, isZoomIn, option)) {
|
|
228
|
+
return zoom;
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
axisId: zoom.axisId,
|
|
232
|
+
start: newMinRange,
|
|
233
|
+
end: newMaxRange
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
eventPrevDiff.current = curDiff;
|
|
237
|
+
return newZoomData;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function pointerUpHandler(event) {
|
|
241
|
+
zoomEventCacheRef.current.splice(zoomEventCacheRef.current.findIndex(cachedEvent => cachedEvent.pointerId === event.pointerId), 1);
|
|
242
|
+
if (zoomEventCacheRef.current.length < 2) {
|
|
243
|
+
eventPrevDiff.current = 0;
|
|
244
|
+
}
|
|
245
|
+
if (event.type === 'pointerup' || event.type === 'pointercancel') {
|
|
246
|
+
setIsInteracting(false);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
element.addEventListener('wheel', wheelHandler);
|
|
250
|
+
element.addEventListener('pointerdown', pointerDownHandler);
|
|
251
|
+
element.addEventListener('pointermove', pointerMoveHandler);
|
|
252
|
+
element.addEventListener('pointerup', pointerUpHandler);
|
|
253
|
+
element.addEventListener('pointercancel', pointerUpHandler);
|
|
254
|
+
element.addEventListener('pointerout', pointerUpHandler);
|
|
255
|
+
element.addEventListener('pointerleave', pointerUpHandler);
|
|
256
|
+
|
|
257
|
+
// Prevent zooming the entire page on touch devices
|
|
258
|
+
element.addEventListener('touchstart', preventDefault);
|
|
259
|
+
element.addEventListener('touchmove', preventDefault);
|
|
260
|
+
return () => {
|
|
261
|
+
element.removeEventListener('wheel', wheelHandler);
|
|
262
|
+
element.removeEventListener('pointerdown', pointerDownHandler);
|
|
263
|
+
element.removeEventListener('pointermove', pointerMoveHandler);
|
|
264
|
+
element.removeEventListener('pointerup', pointerUpHandler);
|
|
265
|
+
element.removeEventListener('pointercancel', pointerUpHandler);
|
|
266
|
+
element.removeEventListener('pointerout', pointerUpHandler);
|
|
267
|
+
element.removeEventListener('pointerleave', pointerUpHandler);
|
|
268
|
+
element.removeEventListener('touchstart', preventDefault);
|
|
269
|
+
element.removeEventListener('touchmove', preventDefault);
|
|
270
|
+
if (interactionTimeoutRef.current) {
|
|
271
|
+
clearTimeout(interactionTimeoutRef.current);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}, [svgRef, drawingArea, isZoomEnabled, optionsLookup, setIsInteracting, instance, setZoomDataCallback]);
|
|
275
|
+
return {
|
|
276
|
+
publicAPI: {
|
|
277
|
+
setZoomData: setZoomDataCallback
|
|
278
|
+
},
|
|
279
|
+
instance: {
|
|
280
|
+
setZoomData: setZoomDataCallback
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
useChartProZoom.params = {
|
|
285
|
+
initialZoom: true,
|
|
286
|
+
onZoomChange: true
|
|
287
|
+
};
|
|
288
|
+
useChartProZoom.getDefaultizedParams = ({
|
|
289
|
+
params
|
|
290
|
+
}) => {
|
|
291
|
+
const optionsLookup = _extends({}, creatZoomLookup('x')(params.defaultizedXAxis), creatZoomLookup('y')(params.defaultizedYAxis));
|
|
292
|
+
return _extends({}, params, {
|
|
293
|
+
optionsLookup
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
useChartProZoom.getInitialState = params => {
|
|
297
|
+
return {
|
|
298
|
+
zoom: {
|
|
299
|
+
zoomData: params.initialZoom === undefined ? initializeZoomData(params.optionsLookup) : params.initialZoom,
|
|
300
|
+
isInteracting: false
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { createSelector, selectorChartRawXAxis, selectorChartRawYAxis } from '@mui/x-charts/internals';
|
|
3
|
+
import { creatZoomLookup } from "./creatZoomLookup.js";
|
|
4
|
+
export const selectorChartZoomState = state => state.zoom;
|
|
5
|
+
const selectorChartXZoomOptionsLookup = createSelector(selectorChartRawXAxis, creatZoomLookup('x'));
|
|
6
|
+
const selectorChartYZoomOptionsLookup = createSelector(selectorChartRawYAxis, creatZoomLookup('y'));
|
|
7
|
+
export const selectorChartZoomOptionsLookup = createSelector([selectorChartXZoomOptionsLookup, selectorChartYZoomOptionsLookup], (xLookup, yLookup) => _extends({}, xLookup, yLookup));
|
|
8
|
+
export const selectorChartZoomData = createSelector(selectorChartZoomState, zoom => zoom.zoomData);
|
|
9
|
+
export const selectorChartZoomIsInteracting = createSelector(selectorChartZoomState, zoom => zoom.isInteracting);
|
|
10
|
+
export const selectorChartZoomIsEnabled = createSelector(selectorChartZoomOptionsLookup, optionsLookup => Object.keys(optionsLookup).length > 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|