@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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,89 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 7.0.0-alpha.4
|
|
7
|
+
|
|
8
|
+
_Dec 8, 2023_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 11 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🚀 The scatter charts now use voronoi to trigger items
|
|
13
|
+
|
|
14
|
+
Users needed to hover the item to highlight the scatter item or show the tooltip.
|
|
15
|
+
Now they can interact with data by triggering the closest element. See the [docs page](https://next.mui.com/x/react-charts/scatter/#interaction) for more info.
|
|
16
|
+
|
|
17
|
+
- 📚 Add [Pickers FAQ page](https://next.mui.com/x/react-date-pickers/faq/)
|
|
18
|
+
- 🎉 The Data Grid Header filters feature is now stable
|
|
19
|
+
- 🌍 Improve Danish (da-DK) locale on Data Grid
|
|
20
|
+
- 🐞 Bugfixes
|
|
21
|
+
|
|
22
|
+
### Data Grid
|
|
23
|
+
|
|
24
|
+
#### Breaking changes
|
|
25
|
+
|
|
26
|
+
- The header filters feature is now stable. `unstable_` prefix is removed from prop `headerFilters` and related exports.
|
|
27
|
+
See [migration docs](https://next.mui.com/x/migration/migration-data-grid-v6/#filtering) for more details.
|
|
28
|
+
|
|
29
|
+
- The `GridColDef['type']` has been narrowed down to only accept the built-in column types.
|
|
30
|
+
TypeScript users need to use the `GridColDef` interface when defining columns:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
// 🛑 `type` is inferred as `string` and is too wide
|
|
34
|
+
const columns = [{ type: 'number', field: 'id' }];
|
|
35
|
+
<DataGrid columns={columns} />;
|
|
36
|
+
|
|
37
|
+
// ✅ `type` is `'number'`
|
|
38
|
+
const columns: GridColDef[] = [{ type: 'number', field: 'id' }];
|
|
39
|
+
<DataGrid columns={columns} />;
|
|
40
|
+
|
|
41
|
+
// ✅ Alternalively, `as const` can be used to narrow down the type
|
|
42
|
+
const columns = [{ type: 'number' as const, field: 'id' }];
|
|
43
|
+
<DataGrid columns={columns} />;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### `@mui/x-data-grid@7.0.0-alpha.4`
|
|
47
|
+
|
|
48
|
+
- [DataGrid] Added a guard for reorder cells (#11159) @michelengelen
|
|
49
|
+
- [DataGrid] Narrow down `GridColDef['type']` (#11270) @cherniavskii
|
|
50
|
+
- [l10n] Improve Danish (da-DK) locale (#11304) @goibon
|
|
51
|
+
|
|
52
|
+
#### `@mui/x-data-grid-pro@7.0.0-alpha.4` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
53
|
+
|
|
54
|
+
Same changes as in `@mui/x-data-grid@7.0.0-alpha.4`, plus:
|
|
55
|
+
|
|
56
|
+
- [DataGridPro] Make header filters feature stable (#11243) @MBilalShafi
|
|
57
|
+
|
|
58
|
+
#### `@mui/x-data-grid-premium@7.0.0-alpha.4` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
59
|
+
|
|
60
|
+
Same changes as in `@mui/x-data-grid-pro@7.0.0-alpha.4`.
|
|
61
|
+
|
|
62
|
+
### Date Pickers
|
|
63
|
+
|
|
64
|
+
#### `@mui/x-date-pickers@7.0.0-alpha.4`
|
|
65
|
+
|
|
66
|
+
- [fields] Rework `PickersTextField` (#11258) @flaviendelangle
|
|
67
|
+
- [pickers] Fix `MultiSectionDigitalClock` issues (#11305) @LukasTy
|
|
68
|
+
- [pickers] Fix views height consistency (#11337) @LukasTy
|
|
69
|
+
|
|
70
|
+
#### `@mui/x-date-pickers-pro@7.0.0-alpha.4` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
71
|
+
|
|
72
|
+
Same changes as in `@mui/x-date-pickers@7.0.0-alpha.4`.
|
|
73
|
+
|
|
74
|
+
### Charts / `@mui/x-charts@7.0.0-alpha.4`
|
|
75
|
+
|
|
76
|
+
- [charts] Remove animation on sparkline (#11311) @oliviertassinari
|
|
77
|
+
- [charts] Use voronoi cells to trigger interaction with scatter items (#10981) @alexfauquette
|
|
78
|
+
- [charts] Add `@mui/utils` as a dependency (#11351) @michelengelen
|
|
79
|
+
|
|
80
|
+
### Docs
|
|
81
|
+
|
|
82
|
+
- [docs] Add FAQ page (#11271) @noraleonte
|
|
83
|
+
- [docs] Add a doc section on how to override the start of the week with each adapter (#11223) @flaviendelangle
|
|
84
|
+
- [docs] Added params to `onPaginationModelChange` docs (#10191) @JFBenzs
|
|
85
|
+
- [docs] Fix typo (#11324) @cadam11
|
|
86
|
+
- [docs] Improve `DemoContainer` styling coverage (#11315) @LukasTy
|
|
87
|
+
- [docs] General revision of the Charts docs (#11249) @danilo-leal
|
|
88
|
+
|
|
6
89
|
## 7.0.0-alpha.3
|
|
7
90
|
|
|
8
91
|
_Dec 4, 2023_
|
|
@@ -866,6 +949,46 @@ Here is an example of the renaming for the `<ChartsTooltip />` component.
|
|
|
866
949
|
- [core] Update release instructions as per v7 configuration (#10962) @MBilalShafi
|
|
867
950
|
- [license] Correctly throw errors (#10924) @oliviertassinari
|
|
868
951
|
|
|
952
|
+
## 6.18.4
|
|
953
|
+
|
|
954
|
+
_Dec 8, 2023_
|
|
955
|
+
|
|
956
|
+
We'd like to offer a big thanks to the 6 contributors who made this release possible. Here are some highlights ✨:
|
|
957
|
+
|
|
958
|
+
- 📚 Add [Pickers FAQ page](https://mui.com/x/react-date-pickers/faq/)
|
|
959
|
+
- 🌍 Improve Danish (da-DK) locale on Data Grid
|
|
960
|
+
- 🐞 Bugfixes
|
|
961
|
+
|
|
962
|
+
### Data Grid
|
|
963
|
+
|
|
964
|
+
#### `@mui/x-data-grid@6.18.4`
|
|
965
|
+
|
|
966
|
+
- [DataGrid] Fix cell slot style override (#11215) @oliviertassinari
|
|
967
|
+
- [l10n] Improve Danish (da-DK) locale (#11346) @goibon
|
|
968
|
+
|
|
969
|
+
#### `@mui/x-data-grid-pro@6.18.4` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
970
|
+
|
|
971
|
+
Same changes as in `@mui/x-data-grid@6.18.4`.
|
|
972
|
+
|
|
973
|
+
#### `@mui/x-data-grid-premium@6.18.4` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
974
|
+
|
|
975
|
+
Same changes as in `@mui/x-data-grid-pro@6.18.4`.
|
|
976
|
+
|
|
977
|
+
### Date Pickers
|
|
978
|
+
|
|
979
|
+
#### `@mui/x-date-pickers@6.18.4`
|
|
980
|
+
|
|
981
|
+
- [pickers] Fix `MultiSectionDigitalClock` issues (#11308) @LukasTy
|
|
982
|
+
|
|
983
|
+
#### `@mui/x-date-pickers-pro@6.18.4` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
984
|
+
|
|
985
|
+
Same changes as in `@mui/x-date-pickers@6.18.4`.
|
|
986
|
+
|
|
987
|
+
### Docs
|
|
988
|
+
|
|
989
|
+
- [docs] Fix typo (#11323) @cadam11
|
|
990
|
+
- [docs] Add FAQ page (#11347) @noraleonte
|
|
991
|
+
|
|
869
992
|
## 6.18.3
|
|
870
993
|
|
|
871
994
|
_Dec 4, 2023_
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ChartsVoronoiHandlerProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
5
|
+
* If `undefined`, the radius is assumed to be infinite.
|
|
6
|
+
* @default undefined
|
|
7
|
+
*/
|
|
8
|
+
voronoiMaxRadius?: number | undefined;
|
|
9
|
+
};
|
|
10
|
+
declare function ChartsVoronoiHandler(props: ChartsVoronoiHandlerProps): React.JSX.Element;
|
|
11
|
+
declare namespace ChartsVoronoiHandler {
|
|
12
|
+
var propTypes: any;
|
|
13
|
+
}
|
|
14
|
+
export { ChartsVoronoiHandler };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ChartsVoronoiHandler = ChartsVoronoiHandler;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _d3Delaunay = require("d3-delaunay");
|
|
11
|
+
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
12
|
+
var _InteractionProvider = require("../context/InteractionProvider");
|
|
13
|
+
var _CartesianContextProvider = require("../context/CartesianContextProvider");
|
|
14
|
+
var _DrawingProvider = require("../context/DrawingProvider");
|
|
15
|
+
var _SeriesContextProvider = require("../context/SeriesContextProvider");
|
|
16
|
+
var _useScale = require("../hooks/useScale");
|
|
17
|
+
var _utils = require("../internals/utils");
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
|
+
function ChartsVoronoiHandler(props) {
|
|
22
|
+
const {
|
|
23
|
+
voronoiMaxRadius
|
|
24
|
+
} = props;
|
|
25
|
+
const svgRef = React.useContext(_DrawingProvider.SVGContext);
|
|
26
|
+
const {
|
|
27
|
+
width,
|
|
28
|
+
height,
|
|
29
|
+
top,
|
|
30
|
+
left
|
|
31
|
+
} = React.useContext(_DrawingProvider.DrawingContext);
|
|
32
|
+
const {
|
|
33
|
+
xAxis,
|
|
34
|
+
yAxis,
|
|
35
|
+
xAxisIds,
|
|
36
|
+
yAxisIds
|
|
37
|
+
} = React.useContext(_CartesianContextProvider.CartesianContext);
|
|
38
|
+
const {
|
|
39
|
+
dispatch
|
|
40
|
+
} = React.useContext(_InteractionProvider.InteractionContext);
|
|
41
|
+
const {
|
|
42
|
+
series,
|
|
43
|
+
seriesOrder
|
|
44
|
+
} = React.useContext(_SeriesContextProvider.SeriesContext).scatter ?? {};
|
|
45
|
+
const voronoiRef = React.useRef({});
|
|
46
|
+
const defaultXAxisId = xAxisIds[0];
|
|
47
|
+
const defaultYAxisId = yAxisIds[0];
|
|
48
|
+
(0, _useEnhancedEffect.default)(() => {
|
|
49
|
+
dispatch({
|
|
50
|
+
type: 'updateVoronoiUsage',
|
|
51
|
+
useVoronoiInteraction: true
|
|
52
|
+
});
|
|
53
|
+
return () => {
|
|
54
|
+
dispatch({
|
|
55
|
+
type: 'updateVoronoiUsage',
|
|
56
|
+
useVoronoiInteraction: false
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}, [dispatch]);
|
|
60
|
+
(0, _useEnhancedEffect.default)(() => {
|
|
61
|
+
if (seriesOrder === undefined || series === undefined) {
|
|
62
|
+
// If there is no scatter chart series
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
voronoiRef.current = {};
|
|
66
|
+
let points = [];
|
|
67
|
+
seriesOrder.forEach(seriesId => {
|
|
68
|
+
const {
|
|
69
|
+
data,
|
|
70
|
+
xAxisKey,
|
|
71
|
+
yAxisKey
|
|
72
|
+
} = series[seriesId];
|
|
73
|
+
const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
|
|
74
|
+
const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
|
|
75
|
+
const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
|
|
76
|
+
const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
|
|
77
|
+
const seriesPoints = data.flatMap(({
|
|
78
|
+
x,
|
|
79
|
+
y
|
|
80
|
+
}) => [getXPosition(x), getYPosition(y)]);
|
|
81
|
+
voronoiRef.current[seriesId] = {
|
|
82
|
+
startIndex: points.length,
|
|
83
|
+
endIndex: points.length + seriesPoints.length
|
|
84
|
+
};
|
|
85
|
+
points = points.concat(seriesPoints);
|
|
86
|
+
});
|
|
87
|
+
voronoiRef.current.delauney = new _d3Delaunay.Delaunay(points);
|
|
88
|
+
}, [defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis]);
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
const element = svgRef.current;
|
|
91
|
+
if (element === null) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const handleMouseOut = () => {
|
|
95
|
+
dispatch({
|
|
96
|
+
type: 'exitChart'
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
|
|
101
|
+
const handleMouseMove = event => {
|
|
102
|
+
// Get mouse coordinate in global SVG space
|
|
103
|
+
const svgPoint = (0, _utils.getSVGPoint)(svgRef.current, event);
|
|
104
|
+
const outsideX = svgPoint.x < left || svgPoint.x > left + width;
|
|
105
|
+
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
106
|
+
if (outsideX || outsideY) {
|
|
107
|
+
dispatch({
|
|
108
|
+
type: 'exitChart'
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (!voronoiRef.current.delauney) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const closestPointIndex = voronoiRef.current.delauney?.find(svgPoint.x, svgPoint.y);
|
|
116
|
+
if (closestPointIndex !== undefined) {
|
|
117
|
+
const seriesId = Object.keys(voronoiRef.current).find(id => {
|
|
118
|
+
if (id === 'delauney') {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
|
|
122
|
+
});
|
|
123
|
+
if (seriesId === undefined) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
|
|
127
|
+
if (voronoiMaxRadius !== undefined) {
|
|
128
|
+
const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
|
|
129
|
+
const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
|
|
130
|
+
const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
|
|
131
|
+
if (dist2 > voronoiMaxRadius ** 2) {
|
|
132
|
+
// The closest point is too far to be considered.
|
|
133
|
+
dispatch({
|
|
134
|
+
type: 'leaveItem',
|
|
135
|
+
data: {
|
|
136
|
+
type: 'scatter',
|
|
137
|
+
seriesId,
|
|
138
|
+
dataIndex
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
dispatch({
|
|
145
|
+
type: 'enterItem',
|
|
146
|
+
data: {
|
|
147
|
+
type: 'scatter',
|
|
148
|
+
seriesId,
|
|
149
|
+
dataIndex
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
element.addEventListener('mouseout', handleMouseOut);
|
|
155
|
+
element.addEventListener('mousemove', handleMouseMove);
|
|
156
|
+
return () => {
|
|
157
|
+
element.removeEventListener('mouseout', handleMouseOut);
|
|
158
|
+
element.removeEventListener('mousemove', handleMouseMove);
|
|
159
|
+
};
|
|
160
|
+
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
|
|
161
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {}); // Workaround to fix docs scripts
|
|
162
|
+
}
|
|
163
|
+
process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
|
|
164
|
+
// ----------------------------- Warning --------------------------------
|
|
165
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
166
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
167
|
+
// ----------------------------------------------------------------------
|
|
168
|
+
/**
|
|
169
|
+
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
170
|
+
* If `undefined`, the radius is assumed to be infinite.
|
|
171
|
+
* @default undefined
|
|
172
|
+
*/
|
|
173
|
+
voronoiMaxRadius: _propTypes.default.number
|
|
174
|
+
} : void 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChartsVoronoiHandler';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _ChartsVoronoiHandler = require("./ChartsVoronoiHandler");
|
|
7
|
+
Object.keys(_ChartsVoronoiHandler).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _ChartsVoronoiHandler[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _ChartsVoronoiHandler[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
package/ScatterChart/Scatter.js
CHANGED
|
@@ -32,10 +32,16 @@ function Scatter(props) {
|
|
|
32
32
|
color,
|
|
33
33
|
markerSize
|
|
34
34
|
} = props;
|
|
35
|
+
const highlightScope = React.useMemo(() => (0, _extends2.default)({
|
|
36
|
+
highlighted: 'item',
|
|
37
|
+
faded: 'global'
|
|
38
|
+
}, series.highlightScope), [series.highlightScope]);
|
|
35
39
|
const {
|
|
36
|
-
item
|
|
40
|
+
item,
|
|
41
|
+
useVoronoiInteraction
|
|
37
42
|
} = React.useContext(_InteractionProvider.InteractionContext);
|
|
38
|
-
const
|
|
43
|
+
const skipInteractionHandlers = useVoronoiInteraction || series.disableHover;
|
|
44
|
+
const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope, skipInteractionHandlers);
|
|
39
45
|
const cleanData = React.useMemo(() => {
|
|
40
46
|
const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
|
|
41
47
|
const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
|
|
@@ -57,22 +63,24 @@ function Scatter(props) {
|
|
|
57
63
|
dataIndex: i
|
|
58
64
|
};
|
|
59
65
|
if (isInRange) {
|
|
66
|
+
const isHighlighted = (0, _useInteractionItemProps.getIsHighlighted)(item, pointCtx, highlightScope);
|
|
60
67
|
temp.push({
|
|
61
68
|
x,
|
|
62
69
|
y,
|
|
63
|
-
|
|
70
|
+
isHighlighted,
|
|
71
|
+
isFaded: !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, pointCtx, highlightScope),
|
|
64
72
|
interactionProps: getInteractionItemProps(pointCtx),
|
|
65
73
|
id: scatterPoint.id
|
|
66
74
|
});
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
return temp;
|
|
70
|
-
}, [
|
|
78
|
+
}, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps]);
|
|
71
79
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
72
80
|
children: cleanData.map(dataPoint => /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", (0, _extends2.default)({
|
|
73
81
|
cx: 0,
|
|
74
82
|
cy: 0,
|
|
75
|
-
r: markerSize,
|
|
83
|
+
r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
|
|
76
84
|
transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
|
|
77
85
|
fill: color,
|
|
78
86
|
opacity: dataPoint.isFaded && 0.3 || 1
|
|
@@ -93,6 +101,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
|
|
|
93
101
|
x: _propTypes.default.number.isRequired,
|
|
94
102
|
y: _propTypes.default.number.isRequired
|
|
95
103
|
})).isRequired,
|
|
104
|
+
disableHover: _propTypes.default.bool,
|
|
96
105
|
highlightScope: _propTypes.default.shape({
|
|
97
106
|
faded: _propTypes.default.oneOf(['global', 'none', 'series']),
|
|
98
107
|
highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
|
|
@@ -8,14 +8,20 @@ import { ChartsTooltipProps, ChartsTooltipSlotProps, ChartsTooltipSlots } from '
|
|
|
8
8
|
import { ChartsLegendProps, ChartsLegendSlotProps, ChartsLegendSlots } from '../ChartsLegend';
|
|
9
9
|
import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
|
|
10
10
|
import { ChartsAxisSlots, ChartsAxisSlotProps } from '../models/axis';
|
|
11
|
+
import { ChartsVoronoiHandlerProps } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
|
|
11
12
|
export interface ScatterChartSlots extends ChartsAxisSlots, ScatterPlotSlots, ChartsLegendSlots, ChartsTooltipSlots {
|
|
12
13
|
}
|
|
13
14
|
export interface ScatterChartSlotProps extends ChartsAxisSlotProps, ScatterPlotSlotProps, ChartsLegendSlotProps, ChartsTooltipSlotProps {
|
|
14
15
|
}
|
|
15
|
-
export interface ScatterChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'
|
|
16
|
+
export interface ScatterChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, ChartsVoronoiHandlerProps {
|
|
16
17
|
series: MakeOptional<ScatterSeriesType, 'type'>[];
|
|
17
18
|
tooltip?: ChartsTooltipProps;
|
|
18
19
|
axisHighlight?: ChartsAxisHighlightProps;
|
|
20
|
+
/**
|
|
21
|
+
* If true, the interaction will not use the Voronoi cell and fall back to hover events.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disableVoronoi?: boolean;
|
|
19
25
|
/**
|
|
20
26
|
* @deprecated Consider using `slotProps.legend` instead.
|
|
21
27
|
*/
|
|
@@ -14,6 +14,7 @@ var _ChartsAxis = require("../ChartsAxis");
|
|
|
14
14
|
var _ChartsTooltip = require("../ChartsTooltip");
|
|
15
15
|
var _ChartsLegend = require("../ChartsLegend");
|
|
16
16
|
var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
|
|
17
|
+
var _ChartsVoronoiHandler = require("../ChartsVoronoiHandler/ChartsVoronoiHandler");
|
|
17
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
19
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -34,6 +35,8 @@ const ScatterChart = exports.ScatterChart = /*#__PURE__*/React.forwardRef(functi
|
|
|
34
35
|
series,
|
|
35
36
|
tooltip,
|
|
36
37
|
axisHighlight,
|
|
38
|
+
voronoiMaxRadius,
|
|
39
|
+
disableVoronoi,
|
|
37
40
|
legend,
|
|
38
41
|
width,
|
|
39
42
|
height,
|
|
@@ -60,7 +63,9 @@ const ScatterChart = exports.ScatterChart = /*#__PURE__*/React.forwardRef(functi
|
|
|
60
63
|
xAxis: xAxis,
|
|
61
64
|
yAxis: yAxis,
|
|
62
65
|
sx: sx,
|
|
63
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
66
|
+
children: [!disableVoronoi && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsVoronoiHandler.ChartsVoronoiHandler, {
|
|
67
|
+
voronoiMaxRadius: voronoiMaxRadius
|
|
68
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, {
|
|
64
69
|
topAxis: topAxis,
|
|
65
70
|
leftAxis: leftAxis,
|
|
66
71
|
rightAxis: rightAxis,
|
|
@@ -134,6 +139,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
134
139
|
* @default false
|
|
135
140
|
*/
|
|
136
141
|
disableAxisListener: _propTypes.default.bool,
|
|
142
|
+
/**
|
|
143
|
+
* If true, the interaction will not use the Voronoi cell and fall back to hover events.
|
|
144
|
+
* @default false
|
|
145
|
+
*/
|
|
146
|
+
disableVoronoi: _propTypes.default.bool,
|
|
137
147
|
/**
|
|
138
148
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
139
149
|
* @default undefined
|
|
@@ -226,6 +236,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
226
236
|
x: _propTypes.default.number.isRequired,
|
|
227
237
|
y: _propTypes.default.number.isRequired
|
|
228
238
|
})).isRequired,
|
|
239
|
+
disableHover: _propTypes.default.bool,
|
|
229
240
|
highlightScope: _propTypes.default.shape({
|
|
230
241
|
faded: _propTypes.default.oneOf(['global', 'none', 'series']),
|
|
231
242
|
highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
|
|
@@ -291,6 +302,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
291
302
|
x: _propTypes.default.number,
|
|
292
303
|
y: _propTypes.default.number
|
|
293
304
|
}),
|
|
305
|
+
/**
|
|
306
|
+
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
307
|
+
* If `undefined`, the radius is assumed to be infinite.
|
|
308
|
+
* @default undefined
|
|
309
|
+
*/
|
|
310
|
+
voronoiMaxRadius: _propTypes.default.number,
|
|
294
311
|
/**
|
|
295
312
|
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
296
313
|
* @default undefined
|
|
@@ -86,6 +86,7 @@ const SparkLineChart = exports.SparkLineChart = /*#__PURE__*/React.forwardRef(fu
|
|
|
86
86
|
sx: sx,
|
|
87
87
|
disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
88
88
|
children: [plotType === 'bar' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarChart.BarPlot, {
|
|
89
|
+
skipAnimation: true,
|
|
89
90
|
slots: slots,
|
|
90
91
|
slotProps: slotProps,
|
|
91
92
|
sx: {
|
|
@@ -20,6 +20,11 @@ type InteractionActions<T extends ChartSeriesType = ChartSeriesType> = {
|
|
|
20
20
|
} | {
|
|
21
21
|
type: 'leaveItem';
|
|
22
22
|
data: ItemInteractionData<T>;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'exitChart';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'updateVoronoiUsage';
|
|
27
|
+
useVoronoiInteraction: boolean;
|
|
23
28
|
} | {
|
|
24
29
|
type: 'updateAxis';
|
|
25
30
|
data: AxisInteractionData;
|
|
@@ -33,6 +38,11 @@ type InteractionState = {
|
|
|
33
38
|
* The x- and y-axes currently interacting.
|
|
34
39
|
*/
|
|
35
40
|
axis: AxisInteractionData;
|
|
41
|
+
/**
|
|
42
|
+
* Set to `true` when `VoronoiHandler` is active.
|
|
43
|
+
* Used to prevent collision with mouseEnter events.
|
|
44
|
+
*/
|
|
45
|
+
useVoronoiInteraction: boolean;
|
|
36
46
|
dispatch: React.Dispatch<InteractionActions>;
|
|
37
47
|
};
|
|
38
48
|
export declare const InteractionContext: React.Context<InteractionState>;
|
|
@@ -17,6 +17,7 @@ const InteractionContext = exports.InteractionContext = /*#__PURE__*/React.creat
|
|
|
17
17
|
x: null,
|
|
18
18
|
y: null
|
|
19
19
|
},
|
|
20
|
+
useVoronoiInteraction: false,
|
|
20
21
|
dispatch: () => null
|
|
21
22
|
});
|
|
22
23
|
const dataReducer = (prevState, action) => {
|
|
@@ -25,6 +26,21 @@ const dataReducer = (prevState, action) => {
|
|
|
25
26
|
return (0, _extends2.default)({}, prevState, {
|
|
26
27
|
item: action.data
|
|
27
28
|
});
|
|
29
|
+
case 'exitChart':
|
|
30
|
+
if (prevState.item === null && prevState.axis.x === null && prevState.axis.y === null) {
|
|
31
|
+
return prevState;
|
|
32
|
+
}
|
|
33
|
+
return (0, _extends2.default)({}, prevState, {
|
|
34
|
+
axis: {
|
|
35
|
+
x: null,
|
|
36
|
+
y: null
|
|
37
|
+
},
|
|
38
|
+
item: null
|
|
39
|
+
});
|
|
40
|
+
case 'updateVoronoiUsage':
|
|
41
|
+
return (0, _extends2.default)({}, prevState, {
|
|
42
|
+
useVoronoiInteraction: action.useVoronoiInteraction
|
|
43
|
+
});
|
|
28
44
|
case 'leaveItem':
|
|
29
45
|
if (prevState.item === null || Object.keys(action.data).some(key => action.data[key] !== prevState.item[key])) {
|
|
30
46
|
// The item is already something else
|
|
@@ -34,6 +50,9 @@ const dataReducer = (prevState, action) => {
|
|
|
34
50
|
item: null
|
|
35
51
|
});
|
|
36
52
|
case 'updateAxis':
|
|
53
|
+
if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) {
|
|
54
|
+
return prevState;
|
|
55
|
+
}
|
|
37
56
|
return (0, _extends2.default)({}, prevState, {
|
|
38
57
|
axis: action.data
|
|
39
58
|
});
|
|
@@ -49,7 +68,8 @@ function InteractionProvider({
|
|
|
49
68
|
axis: {
|
|
50
69
|
x: null,
|
|
51
70
|
y: null
|
|
52
|
-
}
|
|
71
|
+
},
|
|
72
|
+
useVoronoiInteraction: false
|
|
53
73
|
});
|
|
54
74
|
const value = React.useMemo(() => (0, _extends2.default)({}, data, {
|
|
55
75
|
dispatch
|