@mui/x-charts 8.14.0 → 8.14.1
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/BarChart/useBarPlotData.js +20 -33
- package/CHANGELOG.md +95 -0
- package/Gauge/Gauge.js +2 -9
- package/Gauge/GaugeReferenceArc.d.ts +4 -1
- package/Gauge/GaugeReferenceArc.js +12 -3
- package/Gauge/GaugeValueArc.d.ts +4 -1
- package/Gauge/GaugeValueArc.js +16 -8
- package/Gauge/GaugeValueText.js +3 -1
- package/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
- package/esm/BarChart/useBarPlotData.js +20 -33
- package/esm/Gauge/Gauge.js +2 -9
- package/esm/Gauge/GaugeReferenceArc.d.ts +4 -1
- package/esm/Gauge/GaugeReferenceArc.js +11 -2
- package/esm/Gauge/GaugeValueArc.d.ts +4 -1
- package/esm/Gauge/GaugeValueArc.js +16 -8
- package/esm/Gauge/GaugeValueText.js +3 -1
- package/esm/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
- package/esm/index.js +1 -1
- package/esm/internals/Flatbush.bench.d.ts +1 -0
- package/esm/internals/Flatbush.bench.js +42 -0
- package/esm/internals/Flatbush.d.ts +63 -0
- package/esm/internals/Flatbush.js +468 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +41 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +33 -0
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +40 -81
- package/esm/models/seriesType/scatter.d.ts +2 -0
- package/esm/themeAugmentation/components.d.ts +3 -0
- package/esm/themeAugmentation/overrides.d.ts +2 -0
- package/index.js +1 -1
- package/internals/Flatbush.bench.d.ts +1 -0
- package/internals/Flatbush.bench.js +44 -0
- package/internals/Flatbush.d.ts +63 -0
- package/internals/Flatbush.js +477 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +43 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +39 -0
- package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +39 -80
- package/models/seriesType/scatter.d.ts +2 -0
- package/package.json +5 -4
- package/themeAugmentation/components.d.ts +3 -0
- package/themeAugmentation/overrides.d.ts +2 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
|
|
2
3
|
import { selectorChartDrawingArea } from "../../corePlugins/useChartDimensions/index.js";
|
|
3
4
|
import { selectorChartSeriesConfig, selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
|
|
4
5
|
import { createSelector } from "../../utils/selectors.js";
|
|
@@ -14,6 +15,7 @@ import { isOrdinalScale } from "../../../scaleGuards.js";
|
|
|
14
15
|
import { zoomScaleRange } from "./zoom.js";
|
|
15
16
|
import { getAxisExtrema } from "./getAxisExtrema.js";
|
|
16
17
|
import { calculateFinalDomain, calculateInitialDomainAndTickNumber } from "./domain.js";
|
|
18
|
+
import { Flatbush } from "../../../Flatbush.js";
|
|
17
19
|
export const createZoomMap = zoom => {
|
|
18
20
|
const zoomItemMap = new Map();
|
|
19
21
|
zoom.forEach(zoomItem => {
|
|
@@ -29,6 +31,7 @@ const selectorChartZoomState = state => state.zoom;
|
|
|
29
31
|
|
|
30
32
|
export const selectorChartZoomIsInteracting = createSelector([selectorChartZoomState], zoom => zoom?.isInteracting);
|
|
31
33
|
export const selectorChartZoomMap = createSelector([selectorChartZoomState], zoom => zoom?.zoomData && createZoomMap(zoom?.zoomData));
|
|
34
|
+
export const selectorChartAxisZoomData = createSelector([selectorChartZoomMap, (_, axisId) => axisId], (zoomMap, axisId) => zoomMap?.get(axisId));
|
|
32
35
|
export const selectorChartZoomOptionsLookup = createSelector([selectorChartRawXAxis, selectorChartRawYAxis], (xAxis, yAxis) => _extends({}, createZoomLookup('x')(xAxis), createZoomLookup('y')(yAxis)));
|
|
33
36
|
export const selectorChartAxisZoomOptionsLookup = createSelector([selectorChartZoomOptionsLookup, (_, axisId) => axisId], (axisLookup, axisId) => axisLookup[axisId]);
|
|
34
37
|
export const selectorDefaultXAxisTickNumber = createSelector([selectorChartDrawingArea], function selectorDefaultXAxisTickNumber(drawingArea) {
|
|
@@ -125,6 +128,10 @@ export const selectorChartFilteredXDomains = createSelector([selectorChartRawXAx
|
|
|
125
128
|
filteredDomains[axis.id] = calculateFinalDomain(axis, 'x', axisIndex, formattedSeries, axisExtrema, rawTickNumber, preferStrictDomainInLineCharts);
|
|
126
129
|
});
|
|
127
130
|
return filteredDomains;
|
|
131
|
+
}, {
|
|
132
|
+
memoizeOptions: {
|
|
133
|
+
resultEqualityCheck: (a, b) => isDeepEqual(a, b)
|
|
134
|
+
}
|
|
128
135
|
});
|
|
129
136
|
export const selectorChartFilteredYDomains = createSelector([selectorChartRawYAxis, selectorChartSeriesProcessed, selectorChartSeriesConfig, selectorChartZoomMap, selectorChartZoomOptionsLookup, selectorChartZoomAxisFilters, selectorPreferStrictDomainInLineCharts, selectorChartYDomains], (axes, formattedSeries, seriesConfig, zoomMap, zoomOptions, getFilters, preferStrictDomainInLineCharts, domains) => {
|
|
130
137
|
const filteredDomains = {};
|
|
@@ -147,6 +154,10 @@ export const selectorChartFilteredYDomains = createSelector([selectorChartRawYAx
|
|
|
147
154
|
filteredDomains[axis.id] = calculateFinalDomain(axis, 'y', axisIndex, formattedSeries, axisExtrema, rawTickNumber, preferStrictDomainInLineCharts);
|
|
148
155
|
});
|
|
149
156
|
return filteredDomains;
|
|
157
|
+
}, {
|
|
158
|
+
memoizeOptions: {
|
|
159
|
+
resultEqualityCheck: (a, b) => isDeepEqual(a, b)
|
|
160
|
+
}
|
|
150
161
|
});
|
|
151
162
|
export const selectorChartNormalizedXScales = createSelector([selectorChartRawXAxis, selectorChartFilteredXDomains], function selectorChartNormalizedXScales(axes, filteredDomains) {
|
|
152
163
|
const scales = {};
|
|
@@ -227,4 +238,34 @@ export const selectorChartRawAxis = createSelector([selectorChartRawXAxis, selec
|
|
|
227
238
|
return undefined;
|
|
228
239
|
}
|
|
229
240
|
return axis;
|
|
241
|
+
});
|
|
242
|
+
export const selectorChartDefaultXAxisId = createSelector([selectorChartRawXAxis], xAxes => xAxes[0].id);
|
|
243
|
+
export const selectorChartDefaultYAxisId = createSelector([selectorChartRawYAxis], yAxes => yAxes[0].id);
|
|
244
|
+
const EMPTY_MAP = new Map();
|
|
245
|
+
export const selectorChartSeriesEmptyFlatbushMap = () => EMPTY_MAP;
|
|
246
|
+
export const selectorChartSeriesFlatbushMap = createSelector([selectorChartSeriesProcessed, selectorChartNormalizedXScales, selectorChartNormalizedYScales, selectorChartDefaultXAxisId, selectorChartDefaultYAxisId], function selectChartSeriesFlatbushMap(allSeries, xAxesScaleMap, yAxesScaleMap, defaultXAxisId, defaultYAxisId) {
|
|
247
|
+
// FIXME: Do we want to support non-scatter series here?
|
|
248
|
+
const validSeries = allSeries.scatter;
|
|
249
|
+
const flatbushMap = new Map();
|
|
250
|
+
if (!validSeries) {
|
|
251
|
+
return flatbushMap;
|
|
252
|
+
}
|
|
253
|
+
validSeries.seriesOrder.forEach(seriesId => {
|
|
254
|
+
const {
|
|
255
|
+
data,
|
|
256
|
+
xAxisId = defaultXAxisId,
|
|
257
|
+
yAxisId = defaultYAxisId
|
|
258
|
+
} = validSeries.series[seriesId];
|
|
259
|
+
const flatbush = new Flatbush(data.length);
|
|
260
|
+
const originalXScale = xAxesScaleMap[xAxisId];
|
|
261
|
+
const originalYScale = yAxesScaleMap[yAxisId];
|
|
262
|
+
for (const datum of data) {
|
|
263
|
+
// Add the points using a [0, 1] range so that we don't need to recreate the Flatbush structure when zooming.
|
|
264
|
+
// This doesn't happen in practice, though, because currently the scales depend on the drawing area.
|
|
265
|
+
flatbush.add(originalXScale(datum.x), originalYScale(datum.y));
|
|
266
|
+
}
|
|
267
|
+
flatbush.finish();
|
|
268
|
+
flatbushMap.set(seriesId, flatbush);
|
|
269
|
+
});
|
|
270
|
+
return flatbushMap;
|
|
230
271
|
});
|
|
@@ -34,7 +34,10 @@ export const selectorChartAxisInteraction = createSelector([selectorChartsIntera
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
function valueGetter(value, axes, indexes, ids = axes.axisIds[0]) {
|
|
37
|
-
return Array.isArray(ids) ? ids.map((id, axisIndex) =>
|
|
37
|
+
return Array.isArray(ids) ? ids.map((id, axisIndex) => {
|
|
38
|
+
const axis = axes.axis[id];
|
|
39
|
+
return getAxisValue(axis.scale, axis.data, value, indexes[axisIndex]);
|
|
40
|
+
}) : getAxisValue(axes.axis[ids].scale, axes.axis[ids].data, value, indexes);
|
|
38
41
|
}
|
|
39
42
|
export const selectorChartsInteractionXAxisValue = createSelector([selectorChartsInteractionPointerX, selectorChartXAxis, selectorChartsInteractionXAxisIndex, optionalGetAxisId], (x, xAxes, xIndex, id) => {
|
|
40
43
|
if (x === null || xAxes.axisIds.length === 0) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ChartDrawingArea } from "../../../../hooks/useDrawingArea.js";
|
|
2
|
+
import { ScatterValueType } from "../../../../models/seriesType/scatter.js";
|
|
3
|
+
import { Flatbush } from "../../../Flatbush.js";
|
|
4
|
+
import { D3Scale } from "../../../../models/axis.js";
|
|
5
|
+
export declare function findClosestPoints(flatbush: Flatbush, drawingArea: Pick<ChartDrawingArea, 'top' | 'left' | 'width' | 'height'>, seriesData: readonly ScatterValueType[], xScale: D3Scale, yScale: D3Scale, xZoomStart: number, xZoomEnd: number, yZoomStart: number, yZoomEnd: number, svgPointX: number, svgPointY: number, maxRadius?: number, maxResults?: number): number[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isOrdinalScale } from "../../../scaleGuards.js";
|
|
2
|
+
export function findClosestPoints(flatbush, drawingArea, seriesData, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPointX, svgPointY, maxRadius = Infinity, maxResults = 1) {
|
|
3
|
+
const originalXScale = xScale.copy();
|
|
4
|
+
const originalYScale = yScale.copy();
|
|
5
|
+
originalXScale.range([0, 1]);
|
|
6
|
+
originalYScale.range([0, 1]);
|
|
7
|
+
const excludeIfOutsideDrawingArea = function excludeIfOutsideDrawingArea(index) {
|
|
8
|
+
const x = originalXScale(seriesData[index].x);
|
|
9
|
+
const y = originalYScale(seriesData[index].y);
|
|
10
|
+
return x >= xZoomStart && x <= xZoomEnd && y >= yZoomStart && y <= yZoomEnd;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// We need to convert the distance from the original range [0, 1] to the current drawing area
|
|
14
|
+
// so the comparison is done on pixels instead of normalized values.
|
|
15
|
+
// fx and fy are the factors to convert the distance from [0, 1] to the current drawing area.
|
|
16
|
+
const fx = xScale.range()[1] - xScale.range()[0];
|
|
17
|
+
const fy = yScale.range()[1] - yScale.range()[0];
|
|
18
|
+
const fxSq = fx * fx;
|
|
19
|
+
const fySq = fy * fy;
|
|
20
|
+
function sqDistFn(dx, dy) {
|
|
21
|
+
return fxSq * dx * dx + fySq * dy * dy;
|
|
22
|
+
}
|
|
23
|
+
const pointX = originalXScale(invertScale(xScale, svgPointX, dataIndex => seriesData[dataIndex].x));
|
|
24
|
+
const pointY = originalYScale(invertScale(yScale, svgPointY, dataIndex => seriesData[dataIndex].y));
|
|
25
|
+
return flatbush.neighbors(pointX, pointY, maxResults, maxRadius != null ? maxRadius * maxRadius : Infinity, excludeIfOutsideDrawingArea, sqDistFn);
|
|
26
|
+
}
|
|
27
|
+
function invertScale(scale, value, getDataPoint) {
|
|
28
|
+
if (isOrdinalScale(scale)) {
|
|
29
|
+
const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
|
|
30
|
+
return getDataPoint(dataIndex);
|
|
31
|
+
}
|
|
32
|
+
return scale.invert(value);
|
|
33
|
+
}
|
|
@@ -4,13 +4,12 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
6
6
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
7
|
-
import { Delaunay } from '@mui/x-charts-vendor/d3-delaunay';
|
|
8
|
-
import { getValueToPositionMapper } from "../../../../hooks/useScale.js";
|
|
9
7
|
import { getSVGPoint } from "../../../getSVGPoint.js";
|
|
10
8
|
import { useSelector } from "../../../store/useSelector.js";
|
|
11
|
-
import { selectorChartXAxis, selectorChartYAxis, selectorChartZoomIsInteracting } from "../useChartCartesianAxis/index.js";
|
|
9
|
+
import { selectorChartAxisZoomData, selectorChartSeriesEmptyFlatbushMap, selectorChartSeriesFlatbushMap, selectorChartXAxis, selectorChartYAxis, selectorChartZoomIsInteracting } from "../useChartCartesianAxis/index.js";
|
|
12
10
|
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
|
|
13
11
|
import { selectorChartDrawingArea } from "../../corePlugins/useChartDimensions/index.js";
|
|
12
|
+
import { findClosestPoints } from "./findClosestPoints.js";
|
|
14
13
|
export const useChartClosestPoint = ({
|
|
15
14
|
svgRef,
|
|
16
15
|
params,
|
|
@@ -36,9 +35,7 @@ export const useChartClosestPoint = ({
|
|
|
36
35
|
series,
|
|
37
36
|
seriesOrder
|
|
38
37
|
} = useSelector(store, selectorChartSeriesProcessed)?.scatter ?? {};
|
|
39
|
-
const
|
|
40
|
-
const delauneyRef = React.useRef(undefined);
|
|
41
|
-
const lastFind = React.useRef(undefined);
|
|
38
|
+
const flatbushMap = useSelector(store, zoomIsInteracting ? selectorChartSeriesEmptyFlatbushMap : selectorChartSeriesFlatbushMap);
|
|
42
39
|
const defaultXAxisId = xAxisIds[0];
|
|
43
40
|
const defaultYAxisId = yAxisIds[0];
|
|
44
41
|
useEnhancedEffect(() => {
|
|
@@ -48,52 +45,6 @@ export const useChartClosestPoint = ({
|
|
|
48
45
|
}
|
|
49
46
|
}));
|
|
50
47
|
}, [store, disableVoronoi]);
|
|
51
|
-
useEnhancedEffect(() => {
|
|
52
|
-
// This effect generate and store the Delaunay object that's used to map coordinate to closest point.
|
|
53
|
-
|
|
54
|
-
if (zoomIsInteracting || seriesOrder === undefined || series === undefined || disableVoronoi) {
|
|
55
|
-
// If there is no scatter chart series
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
voronoiRef.current = {};
|
|
59
|
-
let points = [];
|
|
60
|
-
seriesOrder.forEach(seriesId => {
|
|
61
|
-
const {
|
|
62
|
-
data,
|
|
63
|
-
xAxisId,
|
|
64
|
-
yAxisId
|
|
65
|
-
} = series[seriesId];
|
|
66
|
-
const xScale = xAxis[xAxisId ?? defaultXAxisId].scale;
|
|
67
|
-
const yScale = yAxis[yAxisId ?? defaultYAxisId].scale;
|
|
68
|
-
const getXPosition = getValueToPositionMapper(xScale);
|
|
69
|
-
const getYPosition = getValueToPositionMapper(yScale);
|
|
70
|
-
const seriesPoints = [];
|
|
71
|
-
const seriesIndexes = [];
|
|
72
|
-
for (let dataIndex = 0; dataIndex < data.length; dataIndex += 1) {
|
|
73
|
-
const {
|
|
74
|
-
x,
|
|
75
|
-
y
|
|
76
|
-
} = data[dataIndex];
|
|
77
|
-
const pointX = getXPosition(x);
|
|
78
|
-
const pointY = getYPosition(y);
|
|
79
|
-
if (instance.isPointInside(pointX, pointY)) {
|
|
80
|
-
seriesPoints.push(pointX);
|
|
81
|
-
seriesPoints.push(pointY);
|
|
82
|
-
seriesIndexes.push(dataIndex);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
voronoiRef.current[seriesId] = {
|
|
86
|
-
seriesId,
|
|
87
|
-
seriesIndexes,
|
|
88
|
-
startIndex: points.length,
|
|
89
|
-
endIndex: points.length + seriesPoints.length,
|
|
90
|
-
markerSize: series[seriesId].markerSize
|
|
91
|
-
};
|
|
92
|
-
points = points.concat(seriesPoints);
|
|
93
|
-
});
|
|
94
|
-
delauneyRef.current = new Delaunay(points);
|
|
95
|
-
lastFind.current = undefined;
|
|
96
|
-
}, [zoomIsInteracting, defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis, drawingArea, instance, disableVoronoi]);
|
|
97
48
|
React.useEffect(() => {
|
|
98
49
|
if (svgRef.current === null || disableVoronoi) {
|
|
99
50
|
return undefined;
|
|
@@ -103,40 +54,48 @@ export const useChartClosestPoint = ({
|
|
|
103
54
|
// Get mouse coordinate in global SVG space
|
|
104
55
|
const svgPoint = getSVGPoint(element, event);
|
|
105
56
|
if (!instance.isPointInside(svgPoint.x, svgPoint.y)) {
|
|
106
|
-
lastFind.current = undefined;
|
|
107
57
|
return 'outside-chart';
|
|
108
58
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
59
|
+
let closestPoint = undefined;
|
|
60
|
+
for (const seriesId of seriesOrder ?? []) {
|
|
61
|
+
const aSeries = (series ?? {})[seriesId];
|
|
62
|
+
const flatbush = flatbushMap.get(seriesId);
|
|
63
|
+
if (!flatbush) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const xAxisId = aSeries.xAxisId ?? defaultXAxisId;
|
|
67
|
+
const yAxisId = aSeries.yAxisId ?? defaultYAxisId;
|
|
68
|
+
const xAxisZoom = selectorChartAxisZoomData(store.getSnapshot(), xAxisId);
|
|
69
|
+
const yAxisZoom = selectorChartAxisZoomData(store.getSnapshot(), yAxisId);
|
|
70
|
+
const maxRadius = voronoiMaxRadius === 'item' ? aSeries.markerSize : voronoiMaxRadius;
|
|
71
|
+
const xZoomStart = (xAxisZoom?.start ?? 0) / 100;
|
|
72
|
+
const xZoomEnd = (xAxisZoom?.end ?? 100) / 100;
|
|
73
|
+
const yZoomStart = (yAxisZoom?.start ?? 0) / 100;
|
|
74
|
+
const yZoomEnd = (yAxisZoom?.end ?? 100) / 100;
|
|
75
|
+
const xScale = xAxis[xAxisId].scale;
|
|
76
|
+
const yScale = yAxis[yAxisId].scale;
|
|
77
|
+
const closestPointIndex = findClosestPoints(flatbush, drawingArea, aSeries.data, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPoint.x, svgPoint.y, maxRadius)[0];
|
|
78
|
+
if (closestPointIndex === undefined) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const point = aSeries.data[closestPointIndex];
|
|
82
|
+
const scaledX = xScale(point.x);
|
|
83
|
+
const scaledY = yScale(point.y);
|
|
84
|
+
const distSq = (scaledX - svgPoint.x) ** 2 + (scaledY - svgPoint.y) ** 2;
|
|
85
|
+
if (closestPoint === undefined || distSq < closestPoint.distanceSq) {
|
|
86
|
+
closestPoint = {
|
|
87
|
+
dataIndex: closestPointIndex,
|
|
88
|
+
seriesId,
|
|
89
|
+
distanceSq: distSq
|
|
90
|
+
};
|
|
91
|
+
}
|
|
115
92
|
}
|
|
116
|
-
|
|
117
|
-
const closestSeries = Object.values(voronoiRef.current).find(value => {
|
|
118
|
-
return 2 * closestPointIndex >= value.startIndex && 2 * closestPointIndex < value.endIndex;
|
|
119
|
-
});
|
|
120
|
-
if (closestSeries === undefined) {
|
|
93
|
+
if (closestPoint === undefined) {
|
|
121
94
|
return 'no-point-found';
|
|
122
95
|
}
|
|
123
|
-
|
|
124
|
-
// The point index in the series with id=closestSeries.seriesId.
|
|
125
|
-
const seriesPointIndex = (2 * closestPointIndex - voronoiRef.current[closestSeries.seriesId].startIndex) / 2;
|
|
126
|
-
const dataIndex = voronoiRef.current[closestSeries.seriesId].seriesIndexes[seriesPointIndex];
|
|
127
|
-
const maxRadius = voronoiMaxRadius === 'item' ? closestSeries.markerSize : voronoiMaxRadius;
|
|
128
|
-
if (maxRadius !== undefined) {
|
|
129
|
-
const pointX = delauneyRef.current.points[2 * closestPointIndex];
|
|
130
|
-
const pointY = delauneyRef.current.points[2 * closestPointIndex + 1];
|
|
131
|
-
const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
|
|
132
|
-
if (dist2 > maxRadius ** 2) {
|
|
133
|
-
// The closest point is too far to be considered.
|
|
134
|
-
return 'outside-voronoi-max-radius';
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
96
|
return {
|
|
138
|
-
seriesId:
|
|
139
|
-
dataIndex
|
|
97
|
+
seriesId: closestPoint.seriesId,
|
|
98
|
+
dataIndex: closestPoint.dataIndex
|
|
140
99
|
};
|
|
141
100
|
}
|
|
142
101
|
|
|
@@ -211,7 +170,7 @@ export const useChartClosestPoint = ({
|
|
|
211
170
|
pressHandler.cleanup();
|
|
212
171
|
pressEndHandler.cleanup();
|
|
213
172
|
};
|
|
214
|
-
}, [svgRef, yAxis, xAxis, voronoiMaxRadius, onItemClick, disableVoronoi, drawingArea, instance]);
|
|
173
|
+
}, [svgRef, yAxis, xAxis, voronoiMaxRadius, onItemClick, disableVoronoi, drawingArea, instance, seriesOrder, series, flatbushMap, defaultXAxisId, defaultYAxisId, store]);
|
|
215
174
|
|
|
216
175
|
// Instance implementation
|
|
217
176
|
const enableVoronoiCallback = useEventCallback(() => {
|
|
@@ -23,6 +23,8 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType | n
|
|
|
23
23
|
/**
|
|
24
24
|
* If true, the interaction will not use element hover for this series.
|
|
25
25
|
* @default false
|
|
26
|
+
* @deprecated This prop will be removed in a future version because it is ambiguous. You can select what to disable
|
|
27
|
+
* on hover by disabling the highlight or the tooltip separately.
|
|
26
28
|
*/
|
|
27
29
|
disableHover?: boolean;
|
|
28
30
|
/**
|
|
@@ -62,6 +62,9 @@ export interface ChartsComponents<Theme = unknown> {
|
|
|
62
62
|
defaultProps?: ComponentsProps['MuiScatterChart'];
|
|
63
63
|
};
|
|
64
64
|
MuiScatter?: {};
|
|
65
|
+
MuiGauge?: {
|
|
66
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiGauge'];
|
|
67
|
+
};
|
|
65
68
|
}
|
|
66
69
|
declare module '@mui/material/styles' {
|
|
67
70
|
interface Components<Theme = unknown> extends ChartsComponents<Theme> {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GaugeClassKey } from "../Gauge/index.js";
|
|
1
2
|
import { BarLabelClassKey } from "../BarChart/index.js";
|
|
2
3
|
import { BarElementClassKey } from "../BarChart/barElementClasses.js";
|
|
3
4
|
import { ChartsAxisHighlightClassKey } from "../ChartsAxisHighlight/index.js";
|
|
@@ -18,6 +19,7 @@ export interface ChartsComponentNameToClassKey {
|
|
|
18
19
|
MuiAreaElement: AreaElementClassKey;
|
|
19
20
|
MuiLineElement: LineElementClassKey;
|
|
20
21
|
MuiMarkElement: MarkElementClassKey;
|
|
22
|
+
MuiGauge: GaugeClassKey;
|
|
21
23
|
}
|
|
22
24
|
declare module '@mui/material/styles' {
|
|
23
25
|
interface ComponentNameToClassKey extends ChartsComponentNameToClassKey {}
|
package/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _Flatbush = require("./Flatbush");
|
|
5
|
+
const data = [],
|
|
6
|
+
n = 1_000_000;
|
|
7
|
+
|
|
8
|
+
// Generate and position the datapoints in a tangent wave pattern
|
|
9
|
+
for (let i = 0; i < n; i += 1) {
|
|
10
|
+
const theta = Math.random() * 2 * Math.PI;
|
|
11
|
+
const radius = Math.pow(Math.random(), 2) * 100;
|
|
12
|
+
const waveDeviation = (Math.random() - 0.5) * 70;
|
|
13
|
+
const waveValue = Math.tan(theta) * waveDeviation;
|
|
14
|
+
data.push({
|
|
15
|
+
x: 50 + (radius + waveValue) * Math.cos(theta),
|
|
16
|
+
y: 50 + (radius + waveValue) * Math.sin(theta)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const flatbush1M = new _Flatbush.Flatbush(data.length);
|
|
20
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
21
|
+
flatbush1M.add(data[i].x, data[i].y);
|
|
22
|
+
}
|
|
23
|
+
flatbush1M.finish();
|
|
24
|
+
(0, _vitest.describe)('Flatbush benchmarks', () => {
|
|
25
|
+
(0, _vitest.describe)('add + finish', () => {
|
|
26
|
+
(0, _vitest.bench)('add 1M points + finish', () => {
|
|
27
|
+
const flatbush = new _Flatbush.Flatbush(data.length);
|
|
28
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
29
|
+
flatbush.add(data[i].x, data[i].y);
|
|
30
|
+
}
|
|
31
|
+
flatbush.finish();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
(0, _vitest.describe)('search 1M points', () => {
|
|
35
|
+
(0, _vitest.bench)('search 1M points', () => {
|
|
36
|
+
flatbush1M.search(0.4, 0.4, 0.6, 0.6);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
(0, _vitest.describe)('neighbors 1M points', () => {
|
|
40
|
+
(0, _vitest.bench)('neighbors 1M points', () => {
|
|
41
|
+
flatbush1M.neighbors(0.5, 0.5, 1, 0.04, undefined);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import FlatQueue from 'flatqueue';
|
|
2
|
+
type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
|
3
|
+
export declare class Flatbush {
|
|
4
|
+
_queue: FlatQueue<number>;
|
|
5
|
+
_boxes: TypedArrayConstructor;
|
|
6
|
+
_indices: Uint16Array | Uint32Array;
|
|
7
|
+
data: ArrayBufferLike;
|
|
8
|
+
numItems: number;
|
|
9
|
+
nodeSize: number;
|
|
10
|
+
_levelBounds: number[];
|
|
11
|
+
byteOffset: number;
|
|
12
|
+
/**
|
|
13
|
+
* Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.
|
|
14
|
+
* @param {ArrayBufferLike} data
|
|
15
|
+
* @param {number} [byteOffset=0] byte offset to the start of the Flatbush buffer in the referenced ArrayBuffer.
|
|
16
|
+
* @returns {Flatbush} index
|
|
17
|
+
*/
|
|
18
|
+
static from(data: any, byteOffset?: number): Flatbush;
|
|
19
|
+
/**
|
|
20
|
+
* Create a Flatbush index that will hold a given number of items.
|
|
21
|
+
* @param {number} numItems
|
|
22
|
+
* @param {number} [nodeSize=16] Size of the tree node (16 by default).
|
|
23
|
+
* @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
|
|
24
|
+
* @param {ArrayBufferConstructor | SharedArrayBufferConstructor} [ArrayBufferType=ArrayBuffer] The array buffer type used to store data (`ArrayBuffer` by default).
|
|
25
|
+
* @param {ArrayBufferLike} [data] (Only used internally)
|
|
26
|
+
* @param {number} [byteOffset=0] (Only used internally)
|
|
27
|
+
*/
|
|
28
|
+
constructor(numItems: number, nodeSize?: number, ArrayType?: TypedArrayConstructor, ArrayBufferType?: ArrayBufferConstructor | SharedArrayBufferConstructor, data?: ArrayBufferLike, byteOffset?: number);
|
|
29
|
+
/**
|
|
30
|
+
* Add a given rectangle to the index.
|
|
31
|
+
* @param {number} minX
|
|
32
|
+
* @param {number} minY
|
|
33
|
+
* @param {number} maxX
|
|
34
|
+
* @param {number} maxY
|
|
35
|
+
* @returns {number} A zero-based, incremental number that represents the newly added rectangle.
|
|
36
|
+
*/
|
|
37
|
+
add(minX: any, minY: any, maxX?: any, maxY?: any): number;
|
|
38
|
+
/** Perform indexing of the added rectangles. */
|
|
39
|
+
finish(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Search the index by a bounding box.
|
|
42
|
+
* @param {number} minX
|
|
43
|
+
* @param {number} minY
|
|
44
|
+
* @param {number} maxX
|
|
45
|
+
* @param {number} maxY
|
|
46
|
+
* @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
|
|
47
|
+
* @returns {number[]} An array containing the index, the x coordinate and the y coordinate of the points intersecting or touching the given bounding box.
|
|
48
|
+
*/
|
|
49
|
+
search(minX: number, minY: number, maxX: number, maxY: number, filterFn?: (index: number) => boolean): number[];
|
|
50
|
+
/**
|
|
51
|
+
* Search items in order of distance from the given point.
|
|
52
|
+
* @param x
|
|
53
|
+
* @param y
|
|
54
|
+
* @param [maxResults=Infinity]
|
|
55
|
+
* @param maxDistSq
|
|
56
|
+
* @param [filterFn] An optional function for filtering the results.
|
|
57
|
+
* @param [sqDistFn] An optional function to calculate squared distance from the point to the item.
|
|
58
|
+
* @returns {number[]} An array of indices of items found.
|
|
59
|
+
*/
|
|
60
|
+
neighbors(x: any, y: any, maxResults?: number, maxDistSq?: number, filterFn?: (index: number) => boolean, sqDistFn?: typeof sqDist): number[];
|
|
61
|
+
}
|
|
62
|
+
declare function sqDist(dx: number, dy: number): number;
|
|
63
|
+
export {};
|