@mui/x-charts 7.0.0-alpha.3 → 7.0.0-alpha.4
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/CHANGELOG.md +123 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
- package/ChartsVoronoiHandler/index.d.ts +1 -0
- package/ChartsVoronoiHandler/index.js +16 -0
- package/ChartsVoronoiHandler/package.json +6 -0
- package/ScatterChart/Scatter.js +14 -5
- package/ScatterChart/ScatterChart.d.ts +7 -1
- package/ScatterChart/ScatterChart.js +18 -1
- package/SparkLineChart/SparkLineChart.js +1 -0
- package/context/InteractionProvider.d.ts +10 -0
- package/context/InteractionProvider.js +21 -1
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
- package/esm/ChartsVoronoiHandler/index.js +1 -0
- package/esm/ScatterChart/Scatter.js +14 -5
- package/esm/ScatterChart/ScatterChart.js +18 -1
- package/esm/SparkLineChart/SparkLineChart.js +1 -0
- package/esm/context/InteractionProvider.js +21 -1
- package/esm/hooks/useAxisEvents.js +20 -27
- package/esm/hooks/useInteractionItemProps.js +4 -1
- package/esm/index.js +1 -0
- package/esm/internals/utils.js +11 -0
- package/hooks/useAxisEvents.js +20 -27
- package/hooks/useInteractionItemProps.d.ts +2 -2
- package/hooks/useInteractionItemProps.js +4 -1
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +1 -0
- package/internals/utils.d.ts +6 -0
- package/internals/utils.js +12 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
- package/legacy/ChartsVoronoiHandler/index.js +1 -0
- package/legacy/ScatterChart/Scatter.js +17 -6
- package/legacy/ScatterChart/ScatterChart.js +18 -1
- package/legacy/SparkLineChart/SparkLineChart.js +1 -0
- package/legacy/context/InteractionProvider.js +21 -1
- package/legacy/hooks/useAxisEvents.js +20 -27
- package/legacy/hooks/useInteractionItemProps.js +6 -1
- package/legacy/index.js +2 -1
- package/legacy/internals/utils.js +11 -0
- package/models/seriesType/scatter.d.ts +5 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
- package/modern/ChartsVoronoiHandler/index.js +1 -0
- package/modern/ScatterChart/Scatter.js +14 -5
- package/modern/ScatterChart/ScatterChart.js +18 -1
- package/modern/SparkLineChart/SparkLineChart.js +1 -0
- package/modern/context/InteractionProvider.js +21 -1
- package/modern/hooks/useAxisEvents.js +20 -27
- package/modern/hooks/useInteractionItemProps.js +4 -1
- package/modern/index.js +2 -1
- package/modern/internals/utils.js +11 -0
- package/package.json +6 -4
|
@@ -23,10 +23,16 @@ function Scatter(props) {
|
|
|
23
23
|
color,
|
|
24
24
|
markerSize
|
|
25
25
|
} = props;
|
|
26
|
+
const highlightScope = React.useMemo(() => _extends({
|
|
27
|
+
highlighted: 'item',
|
|
28
|
+
faded: 'global'
|
|
29
|
+
}, series.highlightScope), [series.highlightScope]);
|
|
26
30
|
const {
|
|
27
|
-
item
|
|
31
|
+
item,
|
|
32
|
+
useVoronoiInteraction
|
|
28
33
|
} = React.useContext(InteractionContext);
|
|
29
|
-
const
|
|
34
|
+
const skipInteractionHandlers = useVoronoiInteraction || series.disableHover;
|
|
35
|
+
const getInteractionItemProps = useInteractionItemProps(highlightScope, skipInteractionHandlers);
|
|
30
36
|
const cleanData = React.useMemo(() => {
|
|
31
37
|
const getXPosition = getValueToPositionMapper(xScale);
|
|
32
38
|
const getYPosition = getValueToPositionMapper(yScale);
|
|
@@ -48,22 +54,24 @@ function Scatter(props) {
|
|
|
48
54
|
dataIndex: i
|
|
49
55
|
};
|
|
50
56
|
if (isInRange) {
|
|
57
|
+
const isHighlighted = getIsHighlighted(item, pointCtx, highlightScope);
|
|
51
58
|
temp.push({
|
|
52
59
|
x,
|
|
53
60
|
y,
|
|
54
|
-
|
|
61
|
+
isHighlighted,
|
|
62
|
+
isFaded: !isHighlighted && getIsFaded(item, pointCtx, highlightScope),
|
|
55
63
|
interactionProps: getInteractionItemProps(pointCtx),
|
|
56
64
|
id: scatterPoint.id
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
return temp;
|
|
61
|
-
}, [
|
|
69
|
+
}, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps]);
|
|
62
70
|
return /*#__PURE__*/_jsx("g", {
|
|
63
71
|
children: cleanData.map(dataPoint => /*#__PURE__*/_jsx("circle", _extends({
|
|
64
72
|
cx: 0,
|
|
65
73
|
cy: 0,
|
|
66
|
-
r: markerSize,
|
|
74
|
+
r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
|
|
67
75
|
transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
|
|
68
76
|
fill: color,
|
|
69
77
|
opacity: dataPoint.isFaded && 0.3 || 1
|
|
@@ -84,6 +92,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
|
|
|
84
92
|
x: PropTypes.number.isRequired,
|
|
85
93
|
y: PropTypes.number.isRequired
|
|
86
94
|
})).isRequired,
|
|
95
|
+
disableHover: PropTypes.bool,
|
|
87
96
|
highlightScope: PropTypes.shape({
|
|
88
97
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
89
98
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -7,6 +7,7 @@ import { ChartsAxis } from '../ChartsAxis';
|
|
|
7
7
|
import { ChartsTooltip } from '../ChartsTooltip';
|
|
8
8
|
import { ChartsLegend } from '../ChartsLegend';
|
|
9
9
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
10
|
+
import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
13
|
/**
|
|
@@ -26,6 +27,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
|
|
|
26
27
|
series,
|
|
27
28
|
tooltip,
|
|
28
29
|
axisHighlight,
|
|
30
|
+
voronoiMaxRadius,
|
|
31
|
+
disableVoronoi,
|
|
29
32
|
legend,
|
|
30
33
|
width,
|
|
31
34
|
height,
|
|
@@ -52,7 +55,9 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
|
|
|
52
55
|
xAxis: xAxis,
|
|
53
56
|
yAxis: yAxis,
|
|
54
57
|
sx: sx,
|
|
55
|
-
children: [/*#__PURE__*/_jsx(
|
|
58
|
+
children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
|
|
59
|
+
voronoiMaxRadius: voronoiMaxRadius
|
|
60
|
+
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
56
61
|
topAxis: topAxis,
|
|
57
62
|
leftAxis: leftAxis,
|
|
58
63
|
rightAxis: rightAxis,
|
|
@@ -126,6 +131,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
126
131
|
* @default false
|
|
127
132
|
*/
|
|
128
133
|
disableAxisListener: PropTypes.bool,
|
|
134
|
+
/**
|
|
135
|
+
* If true, the interaction will not use the Voronoi cell and fall back to hover events.
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
disableVoronoi: PropTypes.bool,
|
|
129
139
|
/**
|
|
130
140
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
131
141
|
* @default undefined
|
|
@@ -218,6 +228,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
218
228
|
x: PropTypes.number.isRequired,
|
|
219
229
|
y: PropTypes.number.isRequired
|
|
220
230
|
})).isRequired,
|
|
231
|
+
disableHover: PropTypes.bool,
|
|
221
232
|
highlightScope: PropTypes.shape({
|
|
222
233
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
223
234
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -283,6 +294,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
283
294
|
x: PropTypes.number,
|
|
284
295
|
y: PropTypes.number
|
|
285
296
|
}),
|
|
297
|
+
/**
|
|
298
|
+
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
299
|
+
* If `undefined`, the radius is assumed to be infinite.
|
|
300
|
+
* @default undefined
|
|
301
|
+
*/
|
|
302
|
+
voronoiMaxRadius: PropTypes.number,
|
|
286
303
|
/**
|
|
287
304
|
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
288
305
|
* @default undefined
|
|
@@ -78,6 +78,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
78
78
|
sx: sx,
|
|
79
79
|
disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
80
80
|
children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
|
|
81
|
+
skipAnimation: true,
|
|
81
82
|
slots: slots,
|
|
82
83
|
slotProps: slotProps,
|
|
83
84
|
sx: {
|
|
@@ -7,6 +7,7 @@ export const InteractionContext = /*#__PURE__*/React.createContext({
|
|
|
7
7
|
x: null,
|
|
8
8
|
y: null
|
|
9
9
|
},
|
|
10
|
+
useVoronoiInteraction: false,
|
|
10
11
|
dispatch: () => null
|
|
11
12
|
});
|
|
12
13
|
const dataReducer = (prevState, action) => {
|
|
@@ -15,6 +16,21 @@ const dataReducer = (prevState, action) => {
|
|
|
15
16
|
return _extends({}, prevState, {
|
|
16
17
|
item: action.data
|
|
17
18
|
});
|
|
19
|
+
case 'exitChart':
|
|
20
|
+
if (prevState.item === null && prevState.axis.x === null && prevState.axis.y === null) {
|
|
21
|
+
return prevState;
|
|
22
|
+
}
|
|
23
|
+
return _extends({}, prevState, {
|
|
24
|
+
axis: {
|
|
25
|
+
x: null,
|
|
26
|
+
y: null
|
|
27
|
+
},
|
|
28
|
+
item: null
|
|
29
|
+
});
|
|
30
|
+
case 'updateVoronoiUsage':
|
|
31
|
+
return _extends({}, prevState, {
|
|
32
|
+
useVoronoiInteraction: action.useVoronoiInteraction
|
|
33
|
+
});
|
|
18
34
|
case 'leaveItem':
|
|
19
35
|
if (prevState.item === null || Object.keys(action.data).some(key => action.data[key] !== prevState.item[key])) {
|
|
20
36
|
// The item is already something else
|
|
@@ -24,6 +40,9 @@ const dataReducer = (prevState, action) => {
|
|
|
24
40
|
item: null
|
|
25
41
|
});
|
|
26
42
|
case 'updateAxis':
|
|
43
|
+
if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) {
|
|
44
|
+
return prevState;
|
|
45
|
+
}
|
|
27
46
|
return _extends({}, prevState, {
|
|
28
47
|
axis: action.data
|
|
29
48
|
});
|
|
@@ -39,7 +58,8 @@ export function InteractionProvider({
|
|
|
39
58
|
axis: {
|
|
40
59
|
x: null,
|
|
41
60
|
y: null
|
|
42
|
-
}
|
|
61
|
+
},
|
|
62
|
+
useVoronoiInteraction: false
|
|
43
63
|
});
|
|
44
64
|
const value = React.useMemo(() => _extends({}, data, {
|
|
45
65
|
dispatch
|
|
@@ -3,6 +3,10 @@ import { InteractionContext } from '../context/InteractionProvider';
|
|
|
3
3
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
4
4
|
import { SVGContext, DrawingContext } from '../context/DrawingProvider';
|
|
5
5
|
import { isBandScale } from '../internals/isBandScale';
|
|
6
|
+
import { getSVGPoint } from '../internals/utils';
|
|
7
|
+
function getAsANumber(value) {
|
|
8
|
+
return value instanceof Date ? value.getTime() : value;
|
|
9
|
+
}
|
|
6
10
|
export const useAxisEvents = disableAxisListener => {
|
|
7
11
|
const svgRef = React.useContext(SVGContext);
|
|
8
12
|
const {
|
|
@@ -48,17 +52,18 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
48
52
|
value
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const valueAsNumber = getAsANumber(value);
|
|
56
|
+
const closestIndex = axisData?.findIndex((pointValue, index) => {
|
|
57
|
+
const v = getAsANumber(pointValue);
|
|
58
|
+
if (v > valueAsNumber) {
|
|
59
|
+
if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
|
|
55
60
|
return true;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
|
-
if (v <=
|
|
63
|
+
if (v <= valueAsNumber) {
|
|
59
64
|
if (index === axisData.length - 1 ||
|
|
60
65
|
// @ts-ignore
|
|
61
|
-
Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
|
|
66
|
+
Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
|
|
62
67
|
return true;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
@@ -84,37 +89,25 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
84
89
|
y: -1
|
|
85
90
|
};
|
|
86
91
|
dispatch({
|
|
87
|
-
type: '
|
|
88
|
-
data: {
|
|
89
|
-
x: null,
|
|
90
|
-
y: null
|
|
91
|
-
}
|
|
92
|
+
type: 'exitChart'
|
|
92
93
|
});
|
|
93
94
|
};
|
|
94
95
|
const handleMouseMove = event => {
|
|
95
|
-
|
|
96
|
-
const pt = svgRef.current.createSVGPoint();
|
|
97
|
-
pt.x = event.clientX;
|
|
98
|
-
pt.y = event.clientY;
|
|
99
|
-
const svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
|
|
96
|
+
const svgPoint = getSVGPoint(svgRef.current, event);
|
|
100
97
|
mousePosition.current = {
|
|
101
|
-
x:
|
|
102
|
-
y:
|
|
98
|
+
x: svgPoint.x,
|
|
99
|
+
y: svgPoint.y
|
|
103
100
|
};
|
|
104
|
-
const outsideX =
|
|
105
|
-
const outsideY =
|
|
101
|
+
const outsideX = svgPoint.x < left || svgPoint.x > left + width;
|
|
102
|
+
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
106
103
|
if (outsideX || outsideY) {
|
|
107
104
|
dispatch({
|
|
108
|
-
type: '
|
|
109
|
-
data: {
|
|
110
|
-
x: null,
|
|
111
|
-
y: null
|
|
112
|
-
}
|
|
105
|
+
type: 'exitChart'
|
|
113
106
|
});
|
|
114
107
|
return;
|
|
115
108
|
}
|
|
116
|
-
const newStateX = getUpdate(xAxis[usedXAxis],
|
|
117
|
-
const newStateY = getUpdate(yAxis[usedYAxis],
|
|
109
|
+
const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
|
|
110
|
+
const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
|
|
118
111
|
dispatch({
|
|
119
112
|
type: 'updateAxis',
|
|
120
113
|
data: {
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
3
|
import { HighlighContext } from '../context/HighlightProvider';
|
|
4
|
-
export const useInteractionItemProps = scope => {
|
|
4
|
+
export const useInteractionItemProps = (scope, skip) => {
|
|
5
5
|
const {
|
|
6
6
|
dispatch: dispatchInteraction
|
|
7
7
|
} = React.useContext(InteractionContext);
|
|
8
8
|
const {
|
|
9
9
|
dispatch: dispatchHighlight
|
|
10
10
|
} = React.useContext(HighlighContext);
|
|
11
|
+
if (skip) {
|
|
12
|
+
return () => ({});
|
|
13
|
+
}
|
|
11
14
|
const getInteractionItemProps = data => {
|
|
12
15
|
const onMouseEnter = () => {
|
|
13
16
|
dispatchInteraction({
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v7.0.0-alpha.
|
|
2
|
+
* @mui/x-charts v7.0.0-alpha.4
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -18,6 +18,7 @@ export * from './ChartsYAxis';
|
|
|
18
18
|
export * from './ChartsTooltip';
|
|
19
19
|
export * from './ChartsLegend';
|
|
20
20
|
export * from './ChartsAxisHighlight';
|
|
21
|
+
export * from './ChartsVoronoiHandler';
|
|
21
22
|
export * from './BarChart';
|
|
22
23
|
export * from './LineChart';
|
|
23
24
|
export * from './PieChart';
|
|
@@ -2,4 +2,15 @@
|
|
|
2
2
|
export function getSymbol(shape) {
|
|
3
3
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Transform mouse event position to corrdinates inside the SVG.
|
|
8
|
+
* @param svg The SVG element
|
|
9
|
+
* @param event The mouseEvent to transform
|
|
10
|
+
*/
|
|
11
|
+
export function getSVGPoint(svg, event) {
|
|
12
|
+
const pt = svg.createSVGPoint();
|
|
13
|
+
pt.x = event.clientX;
|
|
14
|
+
pt.y = event.clientY;
|
|
15
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
5
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.4",
|
|
4
4
|
"description": "The community edition of the charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -28,13 +28,15 @@
|
|
|
28
28
|
"directory": "packages/x-charts"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@babel/runtime": "^7.23.
|
|
32
|
-
"@mui/base": "^5.0.0-beta.
|
|
33
|
-
"@mui/system": "^5.14.
|
|
31
|
+
"@babel/runtime": "^7.23.5",
|
|
32
|
+
"@mui/base": "^5.0.0-beta.26",
|
|
33
|
+
"@mui/system": "^5.14.20",
|
|
34
|
+
"@mui/utils": "^5.14.20",
|
|
34
35
|
"@react-spring/rafz": "^9.7.3",
|
|
35
36
|
"@react-spring/web": "^9.7.3",
|
|
36
37
|
"clsx": "^2.0.0",
|
|
37
38
|
"d3-color": "^3.1.0",
|
|
39
|
+
"d3-delaunay": "^6.0.4",
|
|
38
40
|
"d3-scale": "^4.0.2",
|
|
39
41
|
"d3-shape": "^3.2.0",
|
|
40
42
|
"prop-types": "^15.8.1"
|