@mui/x-charts-pro 8.0.0-alpha.1 → 8.0.0-alpha.10
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 +72 -31
- package/CHANGELOG.md +1903 -231
- package/ChartContainerPro/ChartContainerPro.d.ts +33 -4
- package/ChartContainerPro/ChartContainerPro.js +55 -37
- package/ChartContainerPro/useChartContainerProProps.d.ts +6 -5
- package/ChartContainerPro/useChartContainerProProps.js +11 -7
- package/ChartDataProviderPro/ChartDataProviderPro.d.ts +37 -0
- package/{context/ChartDataProviderPro → ChartDataProviderPro}/ChartDataProviderPro.js +70 -80
- package/{context → ChartDataProviderPro}/package.json +1 -1
- package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +8 -0
- package/ChartDataProviderPro/useChartDataProviderProProps.js +15 -0
- package/Heatmap/Heatmap.js +31 -8
- 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 +78 -51
- package/README.md +1 -1
- package/ScatterChartPro/ScatterChartPro.d.ts +2 -2
- package/ScatterChartPro/ScatterChartPro.js +49 -33
- 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 -1
- package/index.js +5 -5
- 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 +72 -31
- package/modern/ChartContainerPro/ChartContainerPro.js +55 -37
- package/modern/ChartContainerPro/useChartContainerProProps.js +11 -7
- package/modern/{context/ChartDataProviderPro → ChartDataProviderPro}/ChartDataProviderPro.js +70 -80
- package/modern/ChartDataProviderPro/useChartDataProviderProProps.js +15 -0
- package/modern/Heatmap/Heatmap.js +31 -8
- 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 +78 -51
- package/modern/ScatterChartPro/ScatterChartPro.js +49 -33
- 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 -5
- 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 +71 -30
- package/node/ChartContainerPro/ChartContainerPro.js +54 -36
- package/node/ChartContainerPro/useChartContainerProProps.js +11 -7
- package/node/{context/ChartDataProviderPro → ChartDataProviderPro}/ChartDataProviderPro.js +67 -77
- package/node/ChartDataProviderPro/useChartDataProviderProProps.js +21 -0
- package/node/Heatmap/Heatmap.js +31 -8
- 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 +77 -50
- package/node/ScatterChartPro/ScatterChartPro.js +48 -32
- 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 -12
- 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/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/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/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,22 @@
|
|
|
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
21
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
22
|
/**
|
|
23
23
|
* Demos:
|
|
@@ -35,13 +35,14 @@ const ScatterChartPro = /*#__PURE__*/React.forwardRef(function ScatterChartPro(i
|
|
|
35
35
|
name: 'MuiScatterChartPro'
|
|
36
36
|
});
|
|
37
37
|
const {
|
|
38
|
-
|
|
39
|
-
onZoomChange
|
|
38
|
+
initialZoom,
|
|
39
|
+
onZoomChange,
|
|
40
|
+
apiRef
|
|
40
41
|
} = props,
|
|
41
42
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
42
43
|
const {
|
|
44
|
+
chartsWrapperProps,
|
|
43
45
|
chartContainerProps,
|
|
44
|
-
zAxisProps,
|
|
45
46
|
voronoiHandlerProps,
|
|
46
47
|
chartsAxisProps,
|
|
47
48
|
gridProps,
|
|
@@ -51,17 +52,25 @@ const ScatterChartPro = /*#__PURE__*/React.forwardRef(function ScatterChartPro(i
|
|
|
51
52
|
axisHighlightProps,
|
|
52
53
|
children
|
|
53
54
|
} = useScatterChartProps(other);
|
|
55
|
+
const {
|
|
56
|
+
chartDataProviderProProps,
|
|
57
|
+
chartsSurfaceProps
|
|
58
|
+
} = useChartContainerProProps(_extends({}, chartContainerProps, {
|
|
59
|
+
initialZoom,
|
|
60
|
+
onZoomChange,
|
|
61
|
+
apiRef
|
|
62
|
+
}), ref);
|
|
54
63
|
const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
|
|
55
|
-
return /*#__PURE__*/_jsx(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
64
|
+
return /*#__PURE__*/_jsx(ChartDataProviderPro, _extends({}, chartDataProviderProProps, {
|
|
65
|
+
children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
|
|
66
|
+
children: [!props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
|
|
67
|
+
children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx("g", {
|
|
68
|
+
"data-drawing-container": true,
|
|
69
|
+
children: /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps))
|
|
70
|
+
}), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props?.slotProps?.tooltip, {
|
|
71
|
+
trigger: "item"
|
|
72
|
+
})), children]
|
|
73
|
+
}))]
|
|
65
74
|
}))
|
|
66
75
|
}));
|
|
67
76
|
});
|
|
@@ -70,6 +79,11 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
70
79
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
71
80
|
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
72
81
|
// ----------------------------------------------------------------------
|
|
82
|
+
apiRef: PropTypes.shape({
|
|
83
|
+
current: PropTypes.shape({
|
|
84
|
+
setZoomData: PropTypes.func.isRequired
|
|
85
|
+
})
|
|
86
|
+
}),
|
|
73
87
|
/**
|
|
74
88
|
* The configuration of axes highlight.
|
|
75
89
|
* @see See {@link https://mui.com/x/react-charts/highlighting/ highlighting docs} for more details.
|
|
@@ -124,12 +138,26 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
124
138
|
*/
|
|
125
139
|
hideLegend: PropTypes.bool,
|
|
126
140
|
/**
|
|
127
|
-
* The
|
|
141
|
+
* The highlighted item.
|
|
142
|
+
* Used when the highlight is controlled.
|
|
128
143
|
*/
|
|
129
144
|
highlightedItem: PropTypes.shape({
|
|
130
145
|
dataIndex: PropTypes.number,
|
|
131
|
-
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
146
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired
|
|
132
147
|
}),
|
|
148
|
+
/**
|
|
149
|
+
* This prop is used to help implement the accessibility logic.
|
|
150
|
+
* If you don't provide this prop. It falls back to a randomly generated id.
|
|
151
|
+
*/
|
|
152
|
+
id: PropTypes.string,
|
|
153
|
+
/**
|
|
154
|
+
* The list of zoom data related to each axis.
|
|
155
|
+
*/
|
|
156
|
+
initialZoom: PropTypes.arrayOf(PropTypes.shape({
|
|
157
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
158
|
+
end: PropTypes.number.isRequired,
|
|
159
|
+
start: PropTypes.number.isRequired
|
|
160
|
+
})),
|
|
133
161
|
/**
|
|
134
162
|
* Indicate which axis to display the left of the charts.
|
|
135
163
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -145,7 +173,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
145
173
|
* The margin between the SVG and the drawing area.
|
|
146
174
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
147
175
|
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
148
|
-
* @default object Depends on the charts type.
|
|
149
176
|
*/
|
|
150
177
|
margin: PropTypes.shape({
|
|
151
178
|
bottom: PropTypes.number,
|
|
@@ -198,6 +225,7 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
198
225
|
*/
|
|
199
226
|
slots: PropTypes.object,
|
|
200
227
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
228
|
+
theme: PropTypes.oneOf(['dark', 'light']),
|
|
201
229
|
title: PropTypes.string,
|
|
202
230
|
/**
|
|
203
231
|
* Indicate which axis to display the top of the charts.
|
|
@@ -245,7 +273,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
245
273
|
hideTooltip: PropTypes.bool,
|
|
246
274
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
247
275
|
label: PropTypes.string,
|
|
248
|
-
labelFontSize: PropTypes.number,
|
|
249
276
|
labelStyle: PropTypes.object,
|
|
250
277
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
251
278
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
@@ -256,7 +283,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
256
283
|
slots: PropTypes.object,
|
|
257
284
|
stroke: PropTypes.string,
|
|
258
285
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
259
|
-
tickFontSize: PropTypes.number,
|
|
260
286
|
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
261
287
|
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
262
288
|
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
@@ -308,7 +334,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
308
334
|
hideTooltip: PropTypes.bool,
|
|
309
335
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
310
336
|
label: PropTypes.string,
|
|
311
|
-
labelFontSize: PropTypes.number,
|
|
312
337
|
labelStyle: PropTypes.object,
|
|
313
338
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
314
339
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
@@ -319,7 +344,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
319
344
|
slots: PropTypes.object,
|
|
320
345
|
stroke: PropTypes.string,
|
|
321
346
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
322
|
-
tickFontSize: PropTypes.number,
|
|
323
347
|
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
324
348
|
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
325
349
|
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
@@ -364,14 +388,6 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
364
388
|
id: PropTypes.string,
|
|
365
389
|
max: PropTypes.number,
|
|
366
390
|
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
391
|
}))
|
|
376
392
|
} : void 0;
|
|
377
393
|
export { ScatterChartPro };
|
package/hooks/index.d.ts
CHANGED
package/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";
|
package/hooks/useSeries.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ProcessedSeries } from '@mui/x-charts/internals';
|
|
1
2
|
/**
|
|
2
3
|
* Get access to the internal state of heatmap series.
|
|
3
4
|
* The returned object contains:
|
|
@@ -5,7 +6,4 @@
|
|
|
5
6
|
* - seriesOrder: the array of series ids.
|
|
6
7
|
* @returns { series: Record<SeriesId, DefaultizedHeatmapSeriesType>; seriesOrder: SeriesId[]; } | undefined heatmapSeries
|
|
7
8
|
*/
|
|
8
|
-
export declare function useHeatmapSeries():
|
|
9
|
-
series: Record<import("@mui/x-charts/internals").SeriesId, import("../models").DefaultizedHeatmapSeriesType>;
|
|
10
|
-
seriesOrder: import("@mui/x-charts/internals").SeriesId[];
|
|
11
|
-
} | undefined;
|
|
9
|
+
export declare function useHeatmapSeries(): ProcessedSeries['heatmap'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIsZoomInteracting';
|
|
@@ -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/index.d.ts
CHANGED
|
@@ -22,9 +22,11 @@ export * from '@mui/x-charts/ScatterChart';
|
|
|
22
22
|
export * from '@mui/x-charts/SparkLineChart';
|
|
23
23
|
export * from '@mui/x-charts/Gauge';
|
|
24
24
|
export * from '@mui/x-charts/ChartsSurface';
|
|
25
|
+
export * from '@mui/x-charts/ChartDataProvider';
|
|
26
|
+
export * from '@mui/x-charts/ChartsLabel';
|
|
25
27
|
export * from './Heatmap';
|
|
26
28
|
export * from './ChartContainerPro';
|
|
29
|
+
export * from './ChartDataProviderPro';
|
|
27
30
|
export * from './ScatterChartPro';
|
|
28
31
|
export * from './BarChartPro';
|
|
29
32
|
export * from './LineChartPro';
|
|
30
|
-
export * from './context';
|
package/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.10
|
|
3
3
|
*
|
|
4
4
|
* @license MUI X Commercial
|
|
5
5
|
* This source code is licensed under the commercial license found in the
|
|
@@ -32,13 +32,13 @@ export * from '@mui/x-charts/ScatterChart';
|
|
|
32
32
|
export * from '@mui/x-charts/SparkLineChart';
|
|
33
33
|
export * from '@mui/x-charts/Gauge';
|
|
34
34
|
export * from '@mui/x-charts/ChartsSurface';
|
|
35
|
+
export * from '@mui/x-charts/ChartDataProvider';
|
|
36
|
+
export * from '@mui/x-charts/ChartsLabel';
|
|
35
37
|
|
|
36
38
|
// Pro components
|
|
37
39
|
export * from "./Heatmap/index.js";
|
|
38
40
|
export * from "./ChartContainerPro/index.js";
|
|
41
|
+
export * from "./ChartDataProviderPro/index.js";
|
|
39
42
|
export * from "./ScatterChartPro/index.js";
|
|
40
43
|
export * from "./BarChartPro/index.js";
|
|
41
|
-
export * from "./LineChartPro/index.js";
|
|
42
|
-
|
|
43
|
-
// Pro context
|
|
44
|
-
export * from "./context/index.js";
|
|
44
|
+
export * from "./LineChartPro/index.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ChartSeriesType, ConvertSignaturesIntoPlugins, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartZAxisSignature, UseChartHighlightSignature } from '@mui/x-charts/internals';
|
|
2
|
+
import { UseChartProZoomSignature } from './useChartProZoom';
|
|
3
|
+
export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [
|
|
4
|
+
UseChartZAxisSignature,
|
|
5
|
+
UseChartCartesianAxisSignature<TSeries>,
|
|
6
|
+
UseChartInteractionSignature,
|
|
7
|
+
UseChartHighlightSignature,
|
|
8
|
+
UseChartProZoomSignature
|
|
9
|
+
];
|
|
10
|
+
export type AllPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<AllPluginSignatures<TSeries>>;
|
|
11
|
+
export declare const ALL_PLUGINS: (import("@mui/x-charts/internals").ChartPlugin<UseChartProZoomSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartZAxisSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartInteractionSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartHighlightSignature> | import("@mui/x-charts/internals").ChartPlugin<UseChartCartesianAxisSignature<keyof import("@mui/x-charts/internals").ChartsSeriesConfig>>)[];
|
|
@@ -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,3 @@
|
|
|
1
|
+
import { AxisId, DefaultizedZoomOptions } from '@mui/x-charts/internals';
|
|
2
|
+
import { AxisConfig, ChartsXAxisProps, ChartsYAxisProps, ScaleName } from '@mui/x-charts/models';
|
|
3
|
+
export declare const creatZoomLookup: (axisDirection: "x" | "y") => (axes: AxisConfig<ScaleName, any, ChartsXAxisProps | ChartsYAxisProps>[]) => Record<AxisId, DefaultizedZoomOptions>;
|
|
@@ -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
|
+
};
|