@mui/x-charts 9.3.0 → 9.5.0
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/BarElement.d.mts +3 -2
- package/BarChart/BarElement.d.ts +3 -2
- package/BarChart/BarLabel/BarLabelItem.d.mts +3 -2
- package/BarChart/BarLabel/BarLabelItem.d.ts +3 -2
- package/BarChart/seriesConfig/bar/extremums.js +7 -2
- package/BarChart/seriesConfig/bar/extremums.mjs +7 -2
- package/CHANGELOG.md +296 -0
- package/ChartsContainer/ChartsContainer.js +21 -0
- package/ChartsContainer/ChartsContainer.mjs +21 -0
- package/ChartsLabel/ChartsLabelMark.js +1 -21
- package/ChartsLabel/ChartsLabelMark.mjs +0 -20
- package/ChartsLegend/chartsLegend.types.d.mts +3 -2
- package/ChartsLegend/chartsLegend.types.d.ts +3 -2
- package/ChartsLegend/piecewiseColorLegendClasses.js +8 -2
- package/ChartsLegend/piecewiseColorLegendClasses.mjs +8 -2
- package/ChartsOverlay/ChartsOverlay.d.mts +5 -4
- package/ChartsOverlay/ChartsOverlay.d.ts +5 -4
- package/ChartsRadialAxisHighlight/index.d.mts +6 -1
- package/ChartsRadialAxisHighlight/index.d.ts +6 -1
- package/ChartsRadialAxisHighlight/index.js +9 -2
- package/ChartsRadialAxisHighlight/index.mjs +8 -1
- package/ChartsRadialDataProvider/ChartsRadialDataProvider.d.mts +1 -1
- package/ChartsRadialDataProvider/ChartsRadialDataProvider.d.ts +1 -1
- package/ChartsRadialDataProvider/ChartsRadialDataProvider.js +1 -1
- package/ChartsRadialDataProvider/ChartsRadialDataProvider.mjs +1 -1
- package/ChartsRadialDataProvider/index.d.mts +5 -0
- package/ChartsRadialDataProvider/index.d.ts +5 -0
- package/ChartsRadialDataProvider/index.js +12 -1
- package/ChartsRadialDataProvider/index.mjs +7 -0
- package/ChartsRadialGrid/index.d.mts +6 -1
- package/ChartsRadialGrid/index.d.ts +6 -1
- package/ChartsRadialGrid/index.js +8 -2
- package/ChartsRadialGrid/index.mjs +8 -1
- package/ChartsRadiusAxis/index.d.mts +6 -1
- package/ChartsRadiusAxis/index.d.ts +6 -1
- package/ChartsRadiusAxis/index.js +10 -2
- package/ChartsRadiusAxis/index.mjs +7 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.js +6 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.mjs +6 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +5 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.mjs +5 -0
- package/ChartsRotationAxis/index.d.mts +6 -1
- package/ChartsRotationAxis/index.d.ts +6 -1
- package/ChartsRotationAxis/index.js +10 -2
- package/ChartsRotationAxis/index.mjs +7 -1
- package/ChartsTooltip/ChartTooltip.types.d.mts +3 -2
- package/ChartsTooltip/ChartTooltip.types.d.ts +3 -2
- package/ChartsTooltip/ChartsTooltipContainer.js +11 -4
- package/ChartsTooltip/ChartsTooltipContainer.mjs +11 -4
- package/ChartsTooltip/useAxesTooltip.js +2 -2
- package/ChartsTooltip/useAxesTooltip.mjs +2 -2
- package/ChartsTooltip/useItemTooltip.js +2 -2
- package/ChartsTooltip/useItemTooltip.mjs +2 -2
- package/ChartsXAxis/useAxisTicksProps.d.mts +84 -3
- package/ChartsXAxis/useAxisTicksProps.d.ts +84 -3
- package/ChartsYAxis/useAxisTicksProps.d.mts +84 -3
- package/ChartsYAxis/useAxisTicksProps.d.ts +84 -3
- package/LineChart/AreaElement.d.mts +3 -2
- package/LineChart/AreaElement.d.ts +3 -2
- package/LineChart/AreaElement.js +1 -1
- package/LineChart/AreaElement.mjs +1 -1
- package/LineChart/CircleMarkElement.js +1 -1
- package/LineChart/CircleMarkElement.mjs +1 -1
- package/LineChart/LineElement.d.mts +3 -2
- package/LineChart/LineElement.d.ts +3 -2
- package/LineChart/LineElement.js +1 -1
- package/LineChart/LineElement.mjs +1 -1
- package/LineChart/LineHighlightPlot.d.mts +3 -2
- package/LineChart/LineHighlightPlot.d.ts +3 -2
- package/LineChart/LineHighlightPlot.js +65 -45
- package/LineChart/LineHighlightPlot.mjs +65 -45
- package/LineChart/MarkElement.js +1 -1
- package/LineChart/MarkElement.mjs +1 -1
- package/LineChart/MarkPlot.d.mts +3 -2
- package/LineChart/MarkPlot.d.ts +3 -2
- package/LineChart/seriesConfig/curveEvaluation.js +28 -14
- package/LineChart/seriesConfig/curveEvaluation.mjs +27 -14
- package/LineChart/seriesConfig/extremums.js +5 -1
- package/LineChart/seriesConfig/extremums.mjs +5 -1
- package/LineChart/useMarkPlotData.js +3 -1
- package/LineChart/useMarkPlotData.mjs +3 -1
- package/PieChart/PieArcLabelPlot.d.mts +3 -2
- package/PieChart/PieArcLabelPlot.d.ts +3 -2
- package/PieChart/PieArcPlot.d.mts +3 -2
- package/PieChart/PieArcPlot.d.ts +3 -2
- package/RadarChart/RadarAxis/RadarAxis.utils.d.mts +2 -2
- package/RadarChart/RadarAxis/RadarAxis.utils.d.ts +2 -2
- package/ScatterChart/BatchScatter.d.mts +2 -8
- package/ScatterChart/BatchScatter.d.ts +2 -8
- package/ScatterChart/BatchScatter.js +17 -12
- package/ScatterChart/BatchScatter.mjs +17 -12
- package/ScatterChart/FocusedScatterMark.js +2 -2
- package/ScatterChart/FocusedScatterMark.mjs +2 -2
- package/ScatterChart/HighlightedScatterMark.js +3 -3
- package/ScatterChart/HighlightedScatterMark.mjs +3 -3
- package/ScatterChart/Scatter.d.mts +5 -0
- package/ScatterChart/Scatter.d.ts +5 -0
- package/ScatterChart/Scatter.js +7 -2
- package/ScatterChart/Scatter.mjs +7 -2
- package/ScatterChart/ScatterChart.d.mts +2 -1
- package/ScatterChart/ScatterChart.d.ts +2 -1
- package/ScatterChart/ScatterChart.js +28 -3
- package/ScatterChart/ScatterChart.mjs +28 -3
- package/ScatterChart/ScatterChart.plugins.d.mts +2 -1
- package/ScatterChart/ScatterChart.plugins.d.ts +2 -1
- package/ScatterChart/ScatterChart.plugins.js +2 -1
- package/ScatterChart/ScatterChart.plugins.mjs +2 -1
- package/ScatterChart/ScatterMarker.types.d.mts +3 -2
- package/ScatterChart/ScatterMarker.types.d.ts +3 -2
- package/ScatterChart/ScatterPlot.d.mts +7 -4
- package/ScatterChart/ScatterPlot.d.ts +7 -4
- package/ScatterChart/ScatterPlot.js +31 -4
- package/ScatterChart/ScatterPlot.mjs +31 -4
- package/ScatterChart/async/ScatterAsync.d.mts +9 -0
- package/ScatterChart/async/ScatterAsync.d.ts +9 -0
- package/ScatterChart/async/ScatterAsync.js +71 -0
- package/ScatterChart/async/ScatterAsync.mjs +67 -0
- package/ScatterChart/async/ScatterAsyncBatch.d.mts +24 -0
- package/ScatterChart/async/ScatterAsyncBatch.d.ts +24 -0
- package/ScatterChart/async/ScatterAsyncBatch.js +112 -0
- package/ScatterChart/async/ScatterAsyncBatch.mjs +106 -0
- package/ScatterChart/async/scatterRenderData.selectors.d.mts +38 -0
- package/ScatterChart/async/scatterRenderData.selectors.d.ts +38 -0
- package/ScatterChart/async/scatterRenderData.selectors.js +93 -0
- package/ScatterChart/async/scatterRenderData.selectors.mjs +87 -0
- package/ScatterChart/seriesConfig/extremums.js +6 -0
- package/ScatterChart/seriesConfig/extremums.mjs +6 -0
- package/ScatterChart/seriesConfig/getColor.js +1 -1
- package/ScatterChart/seriesConfig/getColor.mjs +1 -1
- package/ScatterChart/seriesConfig/getMarkerSize.d.mts +18 -0
- package/ScatterChart/seriesConfig/getMarkerSize.d.ts +18 -0
- package/ScatterChart/seriesConfig/getMarkerSize.js +43 -0
- package/ScatterChart/seriesConfig/getMarkerSize.mjs +37 -0
- package/ScatterChart/seriesConfig/seriesProcessor.js +23 -8
- package/ScatterChart/seriesConfig/seriesProcessor.mjs +23 -8
- package/ScatterChart/useScatterItemPosition.d.mts +4 -0
- package/ScatterChart/useScatterItemPosition.d.ts +4 -0
- package/ScatterChart/useScatterItemPosition.js +9 -0
- package/ScatterChart/useScatterItemPosition.mjs +8 -0
- package/SparkLineChart/SparkLineChart.js +2 -1
- package/SparkLineChart/SparkLineChart.mjs +2 -1
- package/Toolbar/Toolbar.types.d.mts +3 -2
- package/Toolbar/Toolbar.types.d.ts +3 -2
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/internals/animation/animation.d.mts +1 -2
- package/internals/animation/animation.d.ts +1 -2
- package/internals/commonNextFocusItem.d.mts +10 -2
- package/internals/commonNextFocusItem.d.ts +10 -2
- package/internals/commonNextFocusItem.js +12 -4
- package/internals/commonNextFocusItem.mjs +12 -4
- package/internals/createCommonKeyboardFocusHandler.d.mts +1 -1
- package/internals/createCommonKeyboardFocusHandler.d.ts +1 -1
- package/internals/createCommonKeyboardFocusHandler.js +3 -3
- package/internals/createCommonKeyboardFocusHandler.mjs +3 -3
- package/internals/getSeriesColorFn.d.mts +5 -5
- package/internals/getSeriesColorFn.d.ts +5 -5
- package/internals/incompleteDatasetKeysError.d.mts +1 -0
- package/internals/incompleteDatasetKeysError.d.ts +1 -0
- package/internals/incompleteDatasetKeysError.js +11 -0
- package/internals/incompleteDatasetKeysError.mjs +4 -0
- package/internals/index.d.mts +3 -0
- package/internals/index.d.ts +3 -0
- package/internals/index.js +36 -0
- package/internals/index.mjs +3 -0
- package/internals/plugins/allPlugins.d.mts +4 -3
- package/internals/plugins/allPlugins.d.ts +4 -3
- package/internals/plugins/allPlugins.js +2 -1
- package/internals/plugins/allPlugins.mjs +2 -1
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.d.mts +12 -3
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.d.ts +12 -3
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +10 -1
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.mjs +10 -1
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.d.mts +15 -1
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.d.ts +15 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.js +3 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.mjs +4 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.js +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.mjs +3 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.mts +10 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.ts +10 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.js +18 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.mjs +16 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.js +27 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.mjs +27 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +1 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.mjs +1 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.mts +11 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +11 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +24 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.mjs +24 -5
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.mts +1 -1
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +46 -2
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.mjs +47 -2
- package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +46 -11
- package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.mjs +46 -11
- package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.types.d.mts +2 -1
- package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.types.d.ts +2 -1
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +3 -2
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.mjs +3 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.d.mts +4 -0
- package/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.d.ts +4 -0
- package/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.js +3 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.mjs +1 -0
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +5 -3
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.mjs +7 -5
- package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.js +17 -3
- package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.mjs +17 -3
- package/internals/plugins/featurePlugins/useProgressiveRendering/index.d.mts +3 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/index.d.ts +3 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/index.js +27 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/index.mjs +2 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.d.mts +13 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.d.ts +13 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.js +136 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.mjs +128 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.selectors.d.mts +42 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.selectors.d.ts +42 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.selectors.js +166 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.selectors.mjs +159 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.types.d.mts +34 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.types.d.ts +34 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.types.js +5 -0
- package/internals/plugins/featurePlugins/useProgressiveRendering/useProgressiveRendering.types.mjs +1 -0
- package/internals/scales/scaleBand.js +70 -43
- package/internals/scales/scaleBand.mjs +71 -44
- package/internals/sizeScale.d.mts +6 -0
- package/internals/sizeScale.d.ts +6 -0
- package/internals/sizeScale.js +46 -0
- package/internals/sizeScale.mjs +38 -0
- package/models/axis.d.mts +18 -12
- package/models/axis.d.ts +18 -12
- package/models/chartsSlotsComponentsProps.d.mts +25 -0
- package/models/chartsSlotsComponentsProps.d.ts +25 -0
- package/models/chartsSlotsComponentsProps.js +5 -0
- package/models/chartsSlotsComponentsProps.mjs +1 -0
- package/models/index.d.mts +1 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +11 -0
- package/models/index.mjs +1 -0
- package/models/seriesType/bar.d.mts +1 -1
- package/models/seriesType/bar.d.ts +1 -1
- package/models/seriesType/common.d.mts +4 -4
- package/models/seriesType/common.d.ts +4 -4
- package/models/seriesType/config.d.mts +3 -3
- package/models/seriesType/config.d.ts +3 -3
- package/models/seriesType/line.d.mts +6 -3
- package/models/seriesType/line.d.ts +6 -3
- package/models/seriesType/pie.d.mts +1 -1
- package/models/seriesType/pie.d.ts +1 -1
- package/models/seriesType/radar.d.mts +1 -1
- package/models/seriesType/radar.d.ts +1 -1
- package/models/seriesType/scatter.d.mts +35 -3
- package/models/seriesType/scatter.d.ts +35 -3
- package/models/sizeMapping.d.mts +64 -0
- package/models/sizeMapping.d.ts +64 -0
- package/models/sizeMapping.js +5 -0
- package/models/sizeMapping.mjs +1 -0
- package/models/slots/chartsBaseSlots.d.mts +6 -5
- package/models/slots/chartsBaseSlots.d.ts +6 -5
- package/models/z-axis.d.mts +10 -1
- package/models/z-axis.d.ts +10 -1
- package/package.json +5 -5
|
@@ -24,6 +24,8 @@ var _domain = require("./domain");
|
|
|
24
24
|
var _Flatbush = require("../../../Flatbush");
|
|
25
25
|
var _useChartSeriesConfig = require("../../corePlugins/useChartSeriesConfig");
|
|
26
26
|
var _useChartAxisExtrema = require("./useChartAxisExtrema.selectors");
|
|
27
|
+
var _useChartZAxis = require("../useChartZAxis");
|
|
28
|
+
var _getMarkerSize = _interopRequireDefault(require("../../../../ScatterChart/seriesConfig/getMarkerSize"));
|
|
27
29
|
const createZoomMap = zoom => {
|
|
28
30
|
const zoomItemMap = new Map();
|
|
29
31
|
zoom.forEach(zoomItem => {
|
|
@@ -257,29 +259,46 @@ const selectorChartDefaultYAxisId = exports.selectorChartDefaultYAxisId = (0, _s
|
|
|
257
259
|
const EMPTY_MAP = new Map();
|
|
258
260
|
const selectorChartSeriesEmptyFlatbushMap = () => EMPTY_MAP;
|
|
259
261
|
exports.selectorChartSeriesEmptyFlatbushMap = selectorChartSeriesEmptyFlatbushMap;
|
|
260
|
-
const selectorChartSeriesFlatbushMap = exports.selectorChartSeriesFlatbushMap = (0, _store.createSelectorMemoized)(_useChartSeries.selectorChartSeriesProcessed, selectorChartNormalizedXScales, selectorChartNormalizedYScales, selectorChartDefaultXAxisId, selectorChartDefaultYAxisId, function selectChartSeriesFlatbushMap(allSeries, xAxesScaleMap, yAxesScaleMap, defaultXAxisId, defaultYAxisId) {
|
|
262
|
+
const selectorChartSeriesFlatbushMap = exports.selectorChartSeriesFlatbushMap = (0, _store.createSelectorMemoized)(_useChartSeries.selectorChartSeriesProcessed, selectorChartNormalizedXScales, selectorChartNormalizedYScales, selectorChartDefaultXAxisId, selectorChartDefaultYAxisId, _useChartZAxis.selectorChartZAxis, function selectChartSeriesFlatbushMap(allSeries, xAxesScaleMap, yAxesScaleMap, defaultXAxisId, defaultYAxisId, zAxisState) {
|
|
261
263
|
// FIXME: Do we want to support non-scatter series here?
|
|
262
264
|
const validSeries = allSeries.scatter;
|
|
263
265
|
const flatbushMap = new Map();
|
|
264
266
|
if (!validSeries) {
|
|
265
267
|
return flatbushMap;
|
|
266
268
|
}
|
|
269
|
+
const zAxes = zAxisState?.axis ?? {};
|
|
270
|
+
const zAxisIds = zAxisState?.axisIds ?? [];
|
|
267
271
|
validSeries.seriesOrder.forEach(seriesId => {
|
|
272
|
+
const series = validSeries.series[seriesId];
|
|
268
273
|
const {
|
|
269
274
|
data,
|
|
270
275
|
xAxisId = defaultXAxisId,
|
|
271
276
|
yAxisId = defaultYAxisId
|
|
272
|
-
} =
|
|
277
|
+
} = series;
|
|
278
|
+
if (data.length === 0) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
273
281
|
const flatbush = new _Flatbush.Flatbush(data.length);
|
|
282
|
+
const sizeAxis = zAxes[series.sizeAxisId ?? zAxisIds[0]];
|
|
283
|
+
const isFixedSize = !sizeAxis || !sizeAxis.sizeScale;
|
|
284
|
+
const getItemRadius = isFixedSize ? series.markerSize ?? 0 : (0, _getMarkerSize.default)(series, sizeAxis);
|
|
285
|
+
let maxItemRadius = isFixedSize ? getItemRadius : 0;
|
|
274
286
|
const originalXScale = xAxesScaleMap[xAxisId];
|
|
275
287
|
const originalYScale = yAxesScaleMap[yAxisId];
|
|
276
|
-
for (
|
|
288
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
289
|
+
if (!isFixedSize) {
|
|
290
|
+
maxItemRadius = Math.max(maxItemRadius, getItemRadius(i));
|
|
291
|
+
}
|
|
277
292
|
// Add the points using a [0, 1] range so that we don't need to recreate the Flatbush structure when zooming.
|
|
278
293
|
// This doesn't happen in practice, though, because currently the scales depend on the drawing area.
|
|
279
|
-
flatbush.add(originalXScale(
|
|
294
|
+
flatbush.add(originalXScale(data[i].x), originalYScale(data[i].y));
|
|
280
295
|
}
|
|
281
296
|
flatbush.finish();
|
|
282
|
-
flatbushMap.set(seriesId,
|
|
297
|
+
flatbushMap.set(seriesId, {
|
|
298
|
+
flatbush,
|
|
299
|
+
getItemRadius,
|
|
300
|
+
maxItemRadius
|
|
301
|
+
});
|
|
283
302
|
});
|
|
284
303
|
return flatbushMap;
|
|
285
304
|
});
|
|
@@ -17,6 +17,8 @@ import { calculateFinalDomain, computeAxisDomainsMap } from "./domain.mjs";
|
|
|
17
17
|
import { Flatbush } from "../../../Flatbush.mjs";
|
|
18
18
|
import { selectorChartSeriesConfig } from "../../corePlugins/useChartSeriesConfig/index.mjs";
|
|
19
19
|
import { selectorChartXAxisExtrema, selectorChartYAxisExtrema } from "./useChartAxisExtrema.selectors.mjs";
|
|
20
|
+
import { selectorChartZAxis } from "../useChartZAxis/index.mjs";
|
|
21
|
+
import getMarkerSize from "../../../../ScatterChart/seriesConfig/getMarkerSize.mjs";
|
|
20
22
|
export const createZoomMap = zoom => {
|
|
21
23
|
const zoomItemMap = new Map();
|
|
22
24
|
zoom.forEach(zoomItem => {
|
|
@@ -248,29 +250,46 @@ export const selectorChartDefaultXAxisId = createSelector(selectorChartRawXAxis,
|
|
|
248
250
|
export const selectorChartDefaultYAxisId = createSelector(selectorChartRawYAxis, yAxes => yAxes[0].id);
|
|
249
251
|
const EMPTY_MAP = new Map();
|
|
250
252
|
export const selectorChartSeriesEmptyFlatbushMap = () => EMPTY_MAP;
|
|
251
|
-
export const selectorChartSeriesFlatbushMap = createSelectorMemoized(selectorChartSeriesProcessed, selectorChartNormalizedXScales, selectorChartNormalizedYScales, selectorChartDefaultXAxisId, selectorChartDefaultYAxisId, function selectChartSeriesFlatbushMap(allSeries, xAxesScaleMap, yAxesScaleMap, defaultXAxisId, defaultYAxisId) {
|
|
253
|
+
export const selectorChartSeriesFlatbushMap = createSelectorMemoized(selectorChartSeriesProcessed, selectorChartNormalizedXScales, selectorChartNormalizedYScales, selectorChartDefaultXAxisId, selectorChartDefaultYAxisId, selectorChartZAxis, function selectChartSeriesFlatbushMap(allSeries, xAxesScaleMap, yAxesScaleMap, defaultXAxisId, defaultYAxisId, zAxisState) {
|
|
252
254
|
// FIXME: Do we want to support non-scatter series here?
|
|
253
255
|
const validSeries = allSeries.scatter;
|
|
254
256
|
const flatbushMap = new Map();
|
|
255
257
|
if (!validSeries) {
|
|
256
258
|
return flatbushMap;
|
|
257
259
|
}
|
|
260
|
+
const zAxes = zAxisState?.axis ?? {};
|
|
261
|
+
const zAxisIds = zAxisState?.axisIds ?? [];
|
|
258
262
|
validSeries.seriesOrder.forEach(seriesId => {
|
|
263
|
+
const series = validSeries.series[seriesId];
|
|
259
264
|
const {
|
|
260
265
|
data,
|
|
261
266
|
xAxisId = defaultXAxisId,
|
|
262
267
|
yAxisId = defaultYAxisId
|
|
263
|
-
} =
|
|
268
|
+
} = series;
|
|
269
|
+
if (data.length === 0) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
264
272
|
const flatbush = new Flatbush(data.length);
|
|
273
|
+
const sizeAxis = zAxes[series.sizeAxisId ?? zAxisIds[0]];
|
|
274
|
+
const isFixedSize = !sizeAxis || !sizeAxis.sizeScale;
|
|
275
|
+
const getItemRadius = isFixedSize ? series.markerSize ?? 0 : getMarkerSize(series, sizeAxis);
|
|
276
|
+
let maxItemRadius = isFixedSize ? getItemRadius : 0;
|
|
265
277
|
const originalXScale = xAxesScaleMap[xAxisId];
|
|
266
278
|
const originalYScale = yAxesScaleMap[yAxisId];
|
|
267
|
-
for (
|
|
279
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
280
|
+
if (!isFixedSize) {
|
|
281
|
+
maxItemRadius = Math.max(maxItemRadius, getItemRadius(i));
|
|
282
|
+
}
|
|
268
283
|
// Add the points using a [0, 1] range so that we don't need to recreate the Flatbush structure when zooming.
|
|
269
284
|
// This doesn't happen in practice, though, because currently the scales depend on the drawing area.
|
|
270
|
-
flatbush.add(originalXScale(
|
|
285
|
+
flatbush.add(originalXScale(data[i].x), originalYScale(data[i].y));
|
|
271
286
|
}
|
|
272
287
|
flatbush.finish();
|
|
273
|
-
flatbushMap.set(seriesId,
|
|
288
|
+
flatbushMap.set(seriesId, {
|
|
289
|
+
flatbush,
|
|
290
|
+
getItemRadius,
|
|
291
|
+
maxItemRadius
|
|
292
|
+
});
|
|
274
293
|
});
|
|
275
294
|
return flatbushMap;
|
|
276
295
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ScatterValueType } from "../../../../models/seriesType/scatter.mjs";
|
|
2
2
|
import { type Flatbush } from "../../../Flatbush.mjs";
|
|
3
3
|
import { type D3Scale } from "../../../../models/axis.mjs";
|
|
4
|
-
export declare function findClosestPoints(flatbush: Flatbush, seriesData: readonly ScatterValueType[], xScale: D3Scale, yScale: D3Scale, xZoomStart: number, xZoomEnd: number, yZoomStart: number, yZoomEnd: number, svgPointX: number, svgPointY: number, maxRadius?: number, maxResults?: number): number[];
|
|
4
|
+
export declare function findClosestPoints(flatbush: Flatbush, seriesData: readonly ScatterValueType[], xScale: D3Scale, yScale: D3Scale, xZoomStart: number, xZoomEnd: number, yZoomStart: number, yZoomEnd: number, svgPointX: number, svgPointY: number, maxRadius?: number, maxResults?: number, getItemRadius?: number | ((dataIndex: number) => number)): number[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ScatterValueType } from "../../../../models/seriesType/scatter.js";
|
|
2
2
|
import { type Flatbush } from "../../../Flatbush.js";
|
|
3
3
|
import { type D3Scale } from "../../../../models/axis.js";
|
|
4
|
-
export declare function findClosestPoints(flatbush: Flatbush, seriesData: readonly ScatterValueType[], xScale: D3Scale, yScale: D3Scale, xZoomStart: number, xZoomEnd: number, yZoomStart: number, yZoomEnd: number, svgPointX: number, svgPointY: number, maxRadius?: number, maxResults?: number): number[];
|
|
4
|
+
export declare function findClosestPoints(flatbush: Flatbush, seriesData: readonly ScatterValueType[], xScale: D3Scale, yScale: D3Scale, xZoomStart: number, xZoomEnd: number, yZoomStart: number, yZoomEnd: number, svgPointX: number, svgPointY: number, maxRadius?: number, maxResults?: number, getItemRadius?: number | ((dataIndex: number) => number)): number[];
|
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.findClosestPoints = findClosestPoints;
|
|
7
7
|
var _scaleGuards = require("../../../scaleGuards");
|
|
8
|
-
|
|
8
|
+
// Arbitrary large number to be sure we don't pull the entire dataset from flatbush when radius is not fixed.
|
|
9
|
+
const LARGE_NUMBER = 50;
|
|
10
|
+
function findClosestPoints(flatbush, seriesData, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPointX, svgPointY, maxRadius = Infinity, maxResults = 1, getItemRadius = 0) {
|
|
9
11
|
const originalXScale = xScale.copy();
|
|
10
12
|
const originalYScale = yScale.copy();
|
|
11
13
|
originalXScale.range([0, 1]);
|
|
@@ -28,7 +30,49 @@ function findClosestPoints(flatbush, seriesData, xScale, yScale, xZoomStart, xZo
|
|
|
28
30
|
}
|
|
29
31
|
const pointX = originalXScale(invertScale(xScale, svgPointX, dataIndex => seriesData[dataIndex]?.x));
|
|
30
32
|
const pointY = originalYScale(invertScale(yScale, svgPointY, dataIndex => seriesData[dataIndex]?.y));
|
|
31
|
-
|
|
33
|
+
if (pointX === undefined || pointY === undefined) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const withFixRadius = typeof getItemRadius === 'number';
|
|
37
|
+
const maxRadiusSq = Number.isFinite(maxRadius) ? maxRadius * maxRadius : Infinity;
|
|
38
|
+
|
|
39
|
+
// Pull every candidate whose lower-bound (box) distance is within the hit threshold.
|
|
40
|
+
// Any unpulled point j has box-dist > maxRadius, hence center-dist ≥ box-dist > maxRadius,
|
|
41
|
+
// so it cannot be a hit. We re-rank by true edge distance below.
|
|
42
|
+
const candidates = flatbush.neighbors(pointX, pointY, withFixRadius ? maxResults : LARGE_NUMBER, maxRadiusSq, excludeIfOutsideDrawingArea, sqDistFn);
|
|
43
|
+
if (withFixRadius) {
|
|
44
|
+
// If radius is constant, we can skip the expensive edge-distance calculation and return candidates in box-distance order.
|
|
45
|
+
return candidates;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Re-rank by true (signed) edge distance. Negative values mean the cursor is inside
|
|
49
|
+
// the marker — those win over any outside marker, with deeper containment ranked first.
|
|
50
|
+
let ranked = [];
|
|
51
|
+
for (const i of candidates) {
|
|
52
|
+
const cx = originalXScale(seriesData[i].x);
|
|
53
|
+
const cy = originalYScale(seriesData[i].y);
|
|
54
|
+
const centerDistSq = sqDistFn(cx - pointX, cy - pointY);
|
|
55
|
+
// Preserve the existing hit-area semantics: hit means center distance ≤ maxRadius.
|
|
56
|
+
if (centerDistSq > maxRadiusSq) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const edge = Math.sqrt(centerDistSq) - getItemRadius(i);
|
|
60
|
+
ranked.push({
|
|
61
|
+
index: i,
|
|
62
|
+
edge,
|
|
63
|
+
centerDistSq
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
ranked.sort((a, b) => a.edge - b.edge);
|
|
67
|
+
|
|
68
|
+
// The pointer is inside multiple marks, we sort them by distance to the center. Priority is
|
|
69
|
+
// 1. marks that are under the pointer (negative edge distance) sorted by distance to the center
|
|
70
|
+
// 2. marks that are outside the pointer (positive edge distance) by distance to the edge
|
|
71
|
+
const splitIndex = ranked.findLastIndex(d => d.edge < 0);
|
|
72
|
+
if (splitIndex !== -1) {
|
|
73
|
+
ranked = [...ranked.slice(0, splitIndex + 1).sort((a, b) => a.centerDistSq - b.centerDistSq), ...ranked.slice(splitIndex + 1)];
|
|
74
|
+
}
|
|
75
|
+
return ranked.slice(0, Math.min(ranked.length, maxResults)).map(d => d.index);
|
|
32
76
|
}
|
|
33
77
|
function invertScale(scale, value, getDataPoint) {
|
|
34
78
|
if ((0, _scaleGuards.isOrdinalScale)(scale)) {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { isOrdinalScale } from "../../../scaleGuards.mjs";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
// Arbitrary large number to be sure we don't pull the entire dataset from flatbush when radius is not fixed.
|
|
4
|
+
const LARGE_NUMBER = 50;
|
|
5
|
+
export function findClosestPoints(flatbush, seriesData, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPointX, svgPointY, maxRadius = Infinity, maxResults = 1, getItemRadius = 0) {
|
|
3
6
|
const originalXScale = xScale.copy();
|
|
4
7
|
const originalYScale = yScale.copy();
|
|
5
8
|
originalXScale.range([0, 1]);
|
|
@@ -22,7 +25,49 @@ export function findClosestPoints(flatbush, seriesData, xScale, yScale, xZoomSta
|
|
|
22
25
|
}
|
|
23
26
|
const pointX = originalXScale(invertScale(xScale, svgPointX, dataIndex => seriesData[dataIndex]?.x));
|
|
24
27
|
const pointY = originalYScale(invertScale(yScale, svgPointY, dataIndex => seriesData[dataIndex]?.y));
|
|
25
|
-
|
|
28
|
+
if (pointX === undefined || pointY === undefined) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const withFixRadius = typeof getItemRadius === 'number';
|
|
32
|
+
const maxRadiusSq = Number.isFinite(maxRadius) ? maxRadius * maxRadius : Infinity;
|
|
33
|
+
|
|
34
|
+
// Pull every candidate whose lower-bound (box) distance is within the hit threshold.
|
|
35
|
+
// Any unpulled point j has box-dist > maxRadius, hence center-dist ≥ box-dist > maxRadius,
|
|
36
|
+
// so it cannot be a hit. We re-rank by true edge distance below.
|
|
37
|
+
const candidates = flatbush.neighbors(pointX, pointY, withFixRadius ? maxResults : LARGE_NUMBER, maxRadiusSq, excludeIfOutsideDrawingArea, sqDistFn);
|
|
38
|
+
if (withFixRadius) {
|
|
39
|
+
// If radius is constant, we can skip the expensive edge-distance calculation and return candidates in box-distance order.
|
|
40
|
+
return candidates;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Re-rank by true (signed) edge distance. Negative values mean the cursor is inside
|
|
44
|
+
// the marker — those win over any outside marker, with deeper containment ranked first.
|
|
45
|
+
let ranked = [];
|
|
46
|
+
for (const i of candidates) {
|
|
47
|
+
const cx = originalXScale(seriesData[i].x);
|
|
48
|
+
const cy = originalYScale(seriesData[i].y);
|
|
49
|
+
const centerDistSq = sqDistFn(cx - pointX, cy - pointY);
|
|
50
|
+
// Preserve the existing hit-area semantics: hit means center distance ≤ maxRadius.
|
|
51
|
+
if (centerDistSq > maxRadiusSq) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const edge = Math.sqrt(centerDistSq) - getItemRadius(i);
|
|
55
|
+
ranked.push({
|
|
56
|
+
index: i,
|
|
57
|
+
edge,
|
|
58
|
+
centerDistSq
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
ranked.sort((a, b) => a.edge - b.edge);
|
|
62
|
+
|
|
63
|
+
// The pointer is inside multiple marks, we sort them by distance to the center. Priority is
|
|
64
|
+
// 1. marks that are under the pointer (negative edge distance) sorted by distance to the center
|
|
65
|
+
// 2. marks that are outside the pointer (positive edge distance) by distance to the edge
|
|
66
|
+
const splitIndex = ranked.findLastIndex(d => d.edge < 0);
|
|
67
|
+
if (splitIndex !== -1) {
|
|
68
|
+
ranked = [...ranked.slice(0, splitIndex + 1).sort((a, b) => a.centerDistSq - b.centerDistSq), ...ranked.slice(splitIndex + 1)];
|
|
69
|
+
}
|
|
70
|
+
return ranked.slice(0, Math.min(ranked.length, maxResults)).map(d => d.index);
|
|
26
71
|
}
|
|
27
72
|
function invertScale(scale, value, getDataPoint) {
|
|
28
73
|
if (isOrdinalScale(scale)) {
|
|
@@ -15,6 +15,29 @@ var _getChartPoint = require("../../../getChartPoint");
|
|
|
15
15
|
var _useChartCartesianAxis = require("../useChartCartesianAxis");
|
|
16
16
|
var _useChartSeries = require("../../corePlugins/useChartSeries/useChartSeries.selectors");
|
|
17
17
|
var _findClosestPoints = require("./findClosestPoints");
|
|
18
|
+
/**
|
|
19
|
+
* Return `true` if the candidate point is closer to the pointer than the current closest point.
|
|
20
|
+
* By priority we prefer:
|
|
21
|
+
* 1. points that are under the pointer (negative edge distance) sorted by distance to the center.
|
|
22
|
+
* 2. points that are outside the pointer (positive edge distance) by distance to the edge.
|
|
23
|
+
*/
|
|
24
|
+
function isCloser(candidatePoint, currentClosestPoint) {
|
|
25
|
+
if (currentClosestPoint === undefined) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (candidatePoint.edgeDistance <= 0) {
|
|
29
|
+
if (currentClosestPoint.edgeDistance > 0) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const candidateDistance = candidatePoint.edgeDistance + candidatePoint.radius;
|
|
33
|
+
const currentDistance = currentClosestPoint.edgeDistance + currentClosestPoint.radius;
|
|
34
|
+
return candidateDistance < currentDistance;
|
|
35
|
+
}
|
|
36
|
+
if (currentClosestPoint.edgeDistance <= 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return candidatePoint.edgeDistance < currentClosestPoint.edgeDistance;
|
|
40
|
+
}
|
|
18
41
|
const useChartClosestPoint = ({
|
|
19
42
|
params,
|
|
20
43
|
store,
|
|
@@ -65,35 +88,47 @@ const useChartClosestPoint = ({
|
|
|
65
88
|
let closestPoint = undefined;
|
|
66
89
|
for (const seriesId of seriesOrder ?? []) {
|
|
67
90
|
const aSeries = (series ?? {})[seriesId];
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
91
|
+
const entry = flatbushMap.get(seriesId);
|
|
92
|
+
if (!entry || aSeries.hidden) {
|
|
70
93
|
continue;
|
|
71
94
|
}
|
|
95
|
+
const {
|
|
96
|
+
flatbush,
|
|
97
|
+
getItemRadius,
|
|
98
|
+
maxItemRadius
|
|
99
|
+
} = entry;
|
|
72
100
|
const xAxisId = aSeries.xAxisId ?? defaultXAxisId;
|
|
73
101
|
const yAxisId = aSeries.yAxisId ?? defaultYAxisId;
|
|
74
102
|
const xAxisZoom = (0, _useChartCartesianAxis.selectorChartAxisZoomData)(store.state, xAxisId);
|
|
75
103
|
const yAxisZoom = (0, _useChartCartesianAxis.selectorChartAxisZoomData)(store.state, yAxisId);
|
|
76
|
-
const maxRadius = resolvedHitAreaRadius === 'item' ?
|
|
104
|
+
const maxRadius = resolvedHitAreaRadius === 'item' ? maxItemRadius : resolvedHitAreaRadius;
|
|
77
105
|
const xZoomStart = (xAxisZoom?.start ?? 0) / 100;
|
|
78
106
|
const xZoomEnd = (xAxisZoom?.end ?? 100) / 100;
|
|
79
107
|
const yZoomStart = (yAxisZoom?.start ?? 0) / 100;
|
|
80
108
|
const yZoomEnd = (yAxisZoom?.end ?? 100) / 100;
|
|
81
109
|
const xScale = xAxis[xAxisId].scale;
|
|
82
110
|
const yScale = yAxis[yAxisId].scale;
|
|
83
|
-
const closestPointIndex = (0, _findClosestPoints.findClosestPoints)(flatbush, aSeries.data, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPoint.x, svgPoint.y, maxRadius)[0];
|
|
111
|
+
const closestPointIndex = (0, _findClosestPoints.findClosestPoints)(flatbush, aSeries.data, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPoint.x, svgPoint.y, maxRadius, 1, getItemRadius)[0];
|
|
84
112
|
if (closestPointIndex === undefined) {
|
|
85
113
|
continue;
|
|
86
114
|
}
|
|
87
115
|
const point = aSeries.data[closestPointIndex];
|
|
88
116
|
const scaledX = xScale(point.x);
|
|
89
117
|
const scaledY = yScale(point.y);
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
118
|
+
const centerDist = Math.hypot(scaledX - svgPoint.x, scaledY - svgPoint.y);
|
|
119
|
+
const closestPointRadius = typeof getItemRadius === 'number' ? getItemRadius : getItemRadius(closestPointIndex);
|
|
120
|
+
const edgeDistance = centerDist - closestPointRadius;
|
|
121
|
+
if (resolvedHitAreaRadius === 'item' && edgeDistance > 0) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const newPoint = {
|
|
125
|
+
dataIndex: closestPointIndex,
|
|
126
|
+
seriesId,
|
|
127
|
+
edgeDistance,
|
|
128
|
+
radius: closestPointRadius
|
|
129
|
+
};
|
|
130
|
+
if (isCloser(newPoint, closestPoint)) {
|
|
131
|
+
closestPoint = newPoint;
|
|
97
132
|
}
|
|
98
133
|
}
|
|
99
134
|
if (closestPoint === undefined) {
|
|
@@ -8,6 +8,29 @@ import { getChartPoint } from "../../../getChartPoint.mjs";
|
|
|
8
8
|
import { selectorChartAxisZoomData, selectorChartSeriesEmptyFlatbushMap, selectorChartSeriesFlatbushMap, selectorChartXAxis, selectorChartYAxis, selectorChartZoomIsInteracting } from "../useChartCartesianAxis/index.mjs";
|
|
9
9
|
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.mjs";
|
|
10
10
|
import { findClosestPoints } from "./findClosestPoints.mjs";
|
|
11
|
+
/**
|
|
12
|
+
* Return `true` if the candidate point is closer to the pointer than the current closest point.
|
|
13
|
+
* By priority we prefer:
|
|
14
|
+
* 1. points that are under the pointer (negative edge distance) sorted by distance to the center.
|
|
15
|
+
* 2. points that are outside the pointer (positive edge distance) by distance to the edge.
|
|
16
|
+
*/
|
|
17
|
+
function isCloser(candidatePoint, currentClosestPoint) {
|
|
18
|
+
if (currentClosestPoint === undefined) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (candidatePoint.edgeDistance <= 0) {
|
|
22
|
+
if (currentClosestPoint.edgeDistance > 0) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const candidateDistance = candidatePoint.edgeDistance + candidatePoint.radius;
|
|
26
|
+
const currentDistance = currentClosestPoint.edgeDistance + currentClosestPoint.radius;
|
|
27
|
+
return candidateDistance < currentDistance;
|
|
28
|
+
}
|
|
29
|
+
if (currentClosestPoint.edgeDistance <= 0) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return candidatePoint.edgeDistance < currentClosestPoint.edgeDistance;
|
|
33
|
+
}
|
|
11
34
|
export const useChartClosestPoint = ({
|
|
12
35
|
params,
|
|
13
36
|
store,
|
|
@@ -58,35 +81,47 @@ export const useChartClosestPoint = ({
|
|
|
58
81
|
let closestPoint = undefined;
|
|
59
82
|
for (const seriesId of seriesOrder ?? []) {
|
|
60
83
|
const aSeries = (series ?? {})[seriesId];
|
|
61
|
-
const
|
|
62
|
-
if (!
|
|
84
|
+
const entry = flatbushMap.get(seriesId);
|
|
85
|
+
if (!entry || aSeries.hidden) {
|
|
63
86
|
continue;
|
|
64
87
|
}
|
|
88
|
+
const {
|
|
89
|
+
flatbush,
|
|
90
|
+
getItemRadius,
|
|
91
|
+
maxItemRadius
|
|
92
|
+
} = entry;
|
|
65
93
|
const xAxisId = aSeries.xAxisId ?? defaultXAxisId;
|
|
66
94
|
const yAxisId = aSeries.yAxisId ?? defaultYAxisId;
|
|
67
95
|
const xAxisZoom = selectorChartAxisZoomData(store.state, xAxisId);
|
|
68
96
|
const yAxisZoom = selectorChartAxisZoomData(store.state, yAxisId);
|
|
69
|
-
const maxRadius = resolvedHitAreaRadius === 'item' ?
|
|
97
|
+
const maxRadius = resolvedHitAreaRadius === 'item' ? maxItemRadius : resolvedHitAreaRadius;
|
|
70
98
|
const xZoomStart = (xAxisZoom?.start ?? 0) / 100;
|
|
71
99
|
const xZoomEnd = (xAxisZoom?.end ?? 100) / 100;
|
|
72
100
|
const yZoomStart = (yAxisZoom?.start ?? 0) / 100;
|
|
73
101
|
const yZoomEnd = (yAxisZoom?.end ?? 100) / 100;
|
|
74
102
|
const xScale = xAxis[xAxisId].scale;
|
|
75
103
|
const yScale = yAxis[yAxisId].scale;
|
|
76
|
-
const closestPointIndex = findClosestPoints(flatbush, aSeries.data, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPoint.x, svgPoint.y, maxRadius)[0];
|
|
104
|
+
const closestPointIndex = findClosestPoints(flatbush, aSeries.data, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPoint.x, svgPoint.y, maxRadius, 1, getItemRadius)[0];
|
|
77
105
|
if (closestPointIndex === undefined) {
|
|
78
106
|
continue;
|
|
79
107
|
}
|
|
80
108
|
const point = aSeries.data[closestPointIndex];
|
|
81
109
|
const scaledX = xScale(point.x);
|
|
82
110
|
const scaledY = yScale(point.y);
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
111
|
+
const centerDist = Math.hypot(scaledX - svgPoint.x, scaledY - svgPoint.y);
|
|
112
|
+
const closestPointRadius = typeof getItemRadius === 'number' ? getItemRadius : getItemRadius(closestPointIndex);
|
|
113
|
+
const edgeDistance = centerDist - closestPointRadius;
|
|
114
|
+
if (resolvedHitAreaRadius === 'item' && edgeDistance > 0) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const newPoint = {
|
|
118
|
+
dataIndex: closestPointIndex,
|
|
119
|
+
seriesId,
|
|
120
|
+
edgeDistance,
|
|
121
|
+
radius: closestPointRadius
|
|
122
|
+
};
|
|
123
|
+
if (isCloser(newPoint, closestPoint)) {
|
|
124
|
+
closestPoint = newPoint;
|
|
90
125
|
}
|
|
91
126
|
}
|
|
92
127
|
if (closestPoint === undefined) {
|
package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.types.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ import { type UseChartCartesianAxisSignature } from "../useChartCartesianAxis/in
|
|
|
6
6
|
import { type UseChartHighlightSignature } from "../useChartHighlight/index.mjs";
|
|
7
7
|
import { type UseChartInteractionSignature } from "../useChartInteraction/index.mjs";
|
|
8
8
|
import { type UseChartTooltipSignature } from "../useChartTooltip/index.mjs";
|
|
9
|
+
import { type UseChartZAxisSignature } from "../useChartZAxis/index.mjs";
|
|
9
10
|
export interface UseChartVoronoiInstance {
|
|
10
11
|
/**
|
|
11
12
|
* Enable the voronoi computation.
|
|
@@ -51,5 +52,5 @@ export type UseChartClosestPointSignature<SeriesType extends ChartSeriesType = C
|
|
|
51
52
|
params: UseChartVoronoiParameters;
|
|
52
53
|
defaultizedParams: UseChartVoronoiDefaultizedParameters;
|
|
53
54
|
dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
|
|
54
|
-
optionalDependencies: [UseChartInteractionSignature, UseChartHighlightSignature<SeriesType>, UseChartTooltipSignature];
|
|
55
|
+
optionalDependencies: [UseChartInteractionSignature, UseChartHighlightSignature<SeriesType>, UseChartTooltipSignature, UseChartZAxisSignature];
|
|
55
56
|
}>;
|
package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { type UseChartCartesianAxisSignature } from "../useChartCartesianAxis/in
|
|
|
6
6
|
import { type UseChartHighlightSignature } from "../useChartHighlight/index.js";
|
|
7
7
|
import { type UseChartInteractionSignature } from "../useChartInteraction/index.js";
|
|
8
8
|
import { type UseChartTooltipSignature } from "../useChartTooltip/index.js";
|
|
9
|
+
import { type UseChartZAxisSignature } from "../useChartZAxis/index.js";
|
|
9
10
|
export interface UseChartVoronoiInstance {
|
|
10
11
|
/**
|
|
11
12
|
* Enable the voronoi computation.
|
|
@@ -51,5 +52,5 @@ export type UseChartClosestPointSignature<SeriesType extends ChartSeriesType = C
|
|
|
51
52
|
params: UseChartVoronoiParameters;
|
|
52
53
|
defaultizedParams: UseChartVoronoiDefaultizedParameters;
|
|
53
54
|
dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
|
|
54
|
-
optionalDependencies: [UseChartInteractionSignature, UseChartHighlightSignature<SeriesType>, UseChartTooltipSignature];
|
|
55
|
+
optionalDependencies: [UseChartInteractionSignature, UseChartHighlightSignature<SeriesType>, UseChartTooltipSignature, UseChartZAxisSignature];
|
|
55
56
|
}>;
|
|
@@ -12,6 +12,7 @@ var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallb
|
|
|
12
12
|
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
13
13
|
var _fastObjectShallowCompare = require("@mui/x-internals/fastObjectShallowCompare");
|
|
14
14
|
var _useChartSeries = require("../../corePlugins/useChartSeries/useChartSeries");
|
|
15
|
+
var _cleanIdentifier = require("../../corePlugins/useChartSeriesConfig/utils/cleanIdentifier");
|
|
15
16
|
const useChartHighlight = ({
|
|
16
17
|
store,
|
|
17
18
|
params,
|
|
@@ -86,9 +87,9 @@ const useChartHighlight = ({
|
|
|
86
87
|
exports.useChartHighlight = useChartHighlight;
|
|
87
88
|
useChartHighlight.getInitialState = (params, currentState) => ({
|
|
88
89
|
highlight: {
|
|
89
|
-
item: params.highlightedItem == null ? params.highlightedItem : (0, _useChartSeries.createIdentifierWithType)(currentState)(
|
|
90
|
+
item: params.highlightedItem == null ? params.highlightedItem : (0, _cleanIdentifier.cleanIdentifier)(currentState.seriesConfig.config, (0, _useChartSeries.createIdentifierWithType)(currentState)(
|
|
90
91
|
// Need some as because the generic SeriesType can't be propagated to plugins methods.
|
|
91
|
-
params.highlightedItem),
|
|
92
|
+
params.highlightedItem)),
|
|
92
93
|
lastUpdate: 'pointer',
|
|
93
94
|
isControlled: params.highlightedItem !== undefined
|
|
94
95
|
}
|
|
@@ -5,6 +5,7 @@ import useEventCallback from '@mui/utils/useEventCallback';
|
|
|
5
5
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
6
6
|
import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
|
|
7
7
|
import { createIdentifierWithType } from "../../corePlugins/useChartSeries/useChartSeries.mjs";
|
|
8
|
+
import { cleanIdentifier } from "../../corePlugins/useChartSeriesConfig/utils/cleanIdentifier.mjs";
|
|
8
9
|
export const useChartHighlight = ({
|
|
9
10
|
store,
|
|
10
11
|
params,
|
|
@@ -78,9 +79,9 @@ export const useChartHighlight = ({
|
|
|
78
79
|
};
|
|
79
80
|
useChartHighlight.getInitialState = (params, currentState) => ({
|
|
80
81
|
highlight: {
|
|
81
|
-
item: params.highlightedItem == null ? params.highlightedItem : createIdentifierWithType(currentState)(
|
|
82
|
+
item: params.highlightedItem == null ? params.highlightedItem : cleanIdentifier(currentState.seriesConfig.config, createIdentifierWithType(currentState)(
|
|
82
83
|
// Need some as because the generic SeriesType can't be propagated to plugins methods.
|
|
83
|
-
params.highlightedItem),
|
|
84
|
+
params.highlightedItem)),
|
|
84
85
|
lastUpdate: 'pointer',
|
|
85
86
|
isControlled: params.highlightedItem !== undefined
|
|
86
87
|
}
|
|
@@ -2,6 +2,10 @@ export declare const generateSvg2rotation: (center: {
|
|
|
2
2
|
cx: number;
|
|
3
3
|
cy: number;
|
|
4
4
|
}) => (x: number, y: number) => number;
|
|
5
|
+
export declare const generateSvg2radius: (center: {
|
|
6
|
+
cx: number;
|
|
7
|
+
cy: number;
|
|
8
|
+
}) => (x: number, y: number) => number;
|
|
5
9
|
export declare const generateSvg2polar: (center: {
|
|
6
10
|
cx: number;
|
|
7
11
|
cy: number;
|
|
@@ -2,6 +2,10 @@ export declare const generateSvg2rotation: (center: {
|
|
|
2
2
|
cx: number;
|
|
3
3
|
cy: number;
|
|
4
4
|
}) => (x: number, y: number) => number;
|
|
5
|
+
export declare const generateSvg2radius: (center: {
|
|
6
|
+
cx: number;
|
|
7
|
+
cy: number;
|
|
8
|
+
}) => (x: number, y: number) => number;
|
|
5
9
|
export declare const generateSvg2polar: (center: {
|
|
6
10
|
cx: number;
|
|
7
11
|
cy: number;
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.generateSvg2rotation = exports.generateSvg2polar = exports.generatePolar2svg = void 0;
|
|
6
|
+
exports.generateSvg2rotation = exports.generateSvg2radius = exports.generateSvg2polar = exports.generatePolar2svg = void 0;
|
|
7
7
|
const generateSvg2rotation = center => (x, y) => Math.atan2(x - center.cx, center.cy - y);
|
|
8
8
|
exports.generateSvg2rotation = generateSvg2rotation;
|
|
9
|
+
const generateSvg2radius = center => (x, y) => Math.sqrt((x - center.cx) ** 2 + (center.cy - y) ** 2);
|
|
10
|
+
exports.generateSvg2radius = generateSvg2radius;
|
|
9
11
|
const generateSvg2polar = center => (x, y) => {
|
|
10
12
|
const angle = Math.atan2(x - center.cx, center.cy - y);
|
|
11
13
|
return [Math.sqrt((x - center.cx) ** 2 + (center.cy - y) ** 2), angle];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const generateSvg2rotation = center => (x, y) => Math.atan2(x - center.cx, center.cy - y);
|
|
2
|
+
export const generateSvg2radius = center => (x, y) => Math.sqrt((x - center.cx) ** 2 + (center.cy - y) ** 2);
|
|
2
3
|
export const generateSvg2polar = center => (x, y) => {
|
|
3
4
|
const angle = Math.atan2(x - center.cx, center.cy - y);
|
|
4
5
|
return [Math.sqrt((x - center.cx) ** 2 + (center.cy - y) ** 2), angle];
|
|
@@ -19,6 +19,7 @@ var _coordinateTransformation = require("./coordinateTransformation");
|
|
|
19
19
|
var _getAxisIndex = require("./getAxisIndex");
|
|
20
20
|
var _useChartSeries = require("../../corePlugins/useChartSeries");
|
|
21
21
|
var _checkHasInteractionPlugin = require("../useChartInteraction/checkHasInteractionPlugin");
|
|
22
|
+
var _isPolar = require("../../../isPolar");
|
|
22
23
|
const useChartPolarAxis = ({
|
|
23
24
|
params,
|
|
24
25
|
store,
|
|
@@ -178,9 +179,10 @@ const useChartPolarAxis = ({
|
|
|
178
179
|
const svgPoint = (0, _getChartPoint.getChartPoint)(element, event.detail.srcEvent);
|
|
179
180
|
const rotation = (0, _coordinateTransformation.generateSvg2rotation)(center)(svgPoint.x, svgPoint.y);
|
|
180
181
|
const rotationIndex = (0, _getAxisIndex.getRotationAxisIndex)(rotationAxisWithScale[usedRotationAxisId], rotation);
|
|
182
|
+
const radius = (0, _coordinateTransformation.generateSvg2radius)(center)(svgPoint.x, svgPoint.y);
|
|
183
|
+
const radiusIndex = (0, _getAxisIndex.getRadiusAxisIndex)(radiusAxisWithScale[usedRadiusAxisId], radius);
|
|
181
184
|
isRotationAxis = rotationIndex !== -1;
|
|
182
|
-
dataIndex = isRotationAxis ? rotationIndex :
|
|
183
|
-
|
|
185
|
+
dataIndex = isRotationAxis ? rotationIndex : radiusIndex;
|
|
184
186
|
const USED_AXIS_ID = isRotationAxis ? usedRotationAxisId : usedRadiusAxisId;
|
|
185
187
|
if (dataIndex == null || dataIndex === -1) {
|
|
186
188
|
return;
|
|
@@ -189,7 +191,7 @@ const useChartPolarAxis = ({
|
|
|
189
191
|
// The .data exist because otherwise the dataIndex would be null or -1.
|
|
190
192
|
const axisValue = (isRotationAxis ? rotationAxisWithScale : radiusAxisWithScale)[USED_AXIS_ID].data[dataIndex];
|
|
191
193
|
const seriesValues = {};
|
|
192
|
-
Object.keys(processedSeries).filter(
|
|
194
|
+
Object.keys(processedSeries).filter(_isPolar.isPolarSeriesType).forEach(seriesType => {
|
|
193
195
|
processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
194
196
|
const seriesItem = processedSeries[seriesType].series[seriesId];
|
|
195
197
|
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
@@ -8,10 +8,11 @@ import { defaultizeAxis } from "./defaultizeAxis.mjs";
|
|
|
8
8
|
import { selectorChartsInteractionIsInitialized } from "../useChartInteraction/index.mjs";
|
|
9
9
|
import { selectorChartPolarCenter, selectorChartRadiusAxis, selectorChartRotationAxis } from "./useChartPolarAxis.selectors.mjs";
|
|
10
10
|
import { getChartPoint } from "../../../getChartPoint.mjs";
|
|
11
|
-
import { generatePolar2svg, generateSvg2polar, generateSvg2rotation } from "./coordinateTransformation.mjs";
|
|
12
|
-
import { getRotationAxisIndex } from "./getAxisIndex.mjs";
|
|
11
|
+
import { generatePolar2svg, generateSvg2polar, generateSvg2radius, generateSvg2rotation } from "./coordinateTransformation.mjs";
|
|
12
|
+
import { getRadiusAxisIndex, getRotationAxisIndex } from "./getAxisIndex.mjs";
|
|
13
13
|
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.mjs";
|
|
14
14
|
import { checkHasInteractionPlugin } from "../useChartInteraction/checkHasInteractionPlugin.mjs";
|
|
15
|
+
import { isPolarSeriesType } from "../../../isPolar.mjs";
|
|
15
16
|
export const useChartPolarAxis = ({
|
|
16
17
|
params,
|
|
17
18
|
store,
|
|
@@ -171,9 +172,10 @@ export const useChartPolarAxis = ({
|
|
|
171
172
|
const svgPoint = getChartPoint(element, event.detail.srcEvent);
|
|
172
173
|
const rotation = generateSvg2rotation(center)(svgPoint.x, svgPoint.y);
|
|
173
174
|
const rotationIndex = getRotationAxisIndex(rotationAxisWithScale[usedRotationAxisId], rotation);
|
|
175
|
+
const radius = generateSvg2radius(center)(svgPoint.x, svgPoint.y);
|
|
176
|
+
const radiusIndex = getRadiusAxisIndex(radiusAxisWithScale[usedRadiusAxisId], radius);
|
|
174
177
|
isRotationAxis = rotationIndex !== -1;
|
|
175
|
-
dataIndex = isRotationAxis ? rotationIndex :
|
|
176
|
-
|
|
178
|
+
dataIndex = isRotationAxis ? rotationIndex : radiusIndex;
|
|
177
179
|
const USED_AXIS_ID = isRotationAxis ? usedRotationAxisId : usedRadiusAxisId;
|
|
178
180
|
if (dataIndex == null || dataIndex === -1) {
|
|
179
181
|
return;
|
|
@@ -182,7 +184,7 @@ export const useChartPolarAxis = ({
|
|
|
182
184
|
// The .data exist because otherwise the dataIndex would be null or -1.
|
|
183
185
|
const axisValue = (isRotationAxis ? rotationAxisWithScale : radiusAxisWithScale)[USED_AXIS_ID].data[dataIndex];
|
|
184
186
|
const seriesValues = {};
|
|
185
|
-
Object.keys(processedSeries).filter(
|
|
187
|
+
Object.keys(processedSeries).filter(isPolarSeriesType).forEach(seriesType => {
|
|
186
188
|
processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
187
189
|
const seriesItem = processedSeries[seriesType].series[seriesId];
|
|
188
190
|
seriesValues[seriesId] = seriesItem.data[dataIndex];
|