@mui/x-charts 9.3.0 → 9.4.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 +196 -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/ChartsReferenceLine/ChartsXReferenceLine.js +6 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.mjs +6 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +5 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.mjs +5 -0
- package/ChartsTooltip/ChartTooltip.types.d.mts +3 -2
- package/ChartsTooltip/ChartTooltip.types.d.ts +3 -2
- 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/LineElement.d.mts +3 -2
- package/LineChart/LineElement.d.ts +3 -2
- 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/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 +21 -0
- package/ScatterChart/ScatterChart.mjs +21 -0
- package/ScatterChart/ScatterMarker.types.d.mts +3 -2
- package/ScatterChart/ScatterMarker.types.d.ts +3 -2
- package/ScatterChart/ScatterPlot.d.mts +3 -2
- package/ScatterChart/ScatterPlot.d.ts +3 -2
- package/ScatterChart/ScatterPlot.js +6 -1
- package/ScatterChart/ScatterPlot.mjs +6 -1
- 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/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/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 +2 -0
- package/internals/index.d.ts +2 -0
- package/internals/index.js +24 -0
- package/internals/index.mjs +2 -0
- 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/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/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/line.d.mts +5 -2
- package/models/seriesType/line.d.ts +5 -2
- package/models/seriesType/scatter.d.mts +34 -2
- package/models/seriesType/scatter.d.ts +34 -2
- 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 +6 -6
|
@@ -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];
|
|
@@ -11,6 +11,7 @@ var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/form
|
|
|
11
11
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
12
|
var React = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _colorScale = require("../../../colorScale");
|
|
14
|
+
var _sizeScale = require("../../../sizeScale");
|
|
14
15
|
function addDefaultId(axisConfig, defaultId) {
|
|
15
16
|
if (axisConfig.id !== undefined) {
|
|
16
17
|
return axisConfig;
|
|
@@ -32,6 +33,19 @@ function processColorMap(axisConfig) {
|
|
|
32
33
|
}, axisConfig.colorMap) : axisConfig.colorMap)
|
|
33
34
|
});
|
|
34
35
|
}
|
|
36
|
+
function processSizeMap(axisConfig) {
|
|
37
|
+
if (!axisConfig.sizeMap) {
|
|
38
|
+
return axisConfig;
|
|
39
|
+
}
|
|
40
|
+
return (0, _extends2.default)({}, axisConfig, {
|
|
41
|
+
sizeScale: axisConfig.sizeMap.type === 'ordinal' ? (0, _sizeScale.getOrdinalSizeScale)((0, _extends2.default)({
|
|
42
|
+
values: axisConfig.data
|
|
43
|
+
}, axisConfig.sizeMap)) : (0, _sizeScale.getSizeScale)(axisConfig.sizeMap.type === 'continuous' ? (0, _extends2.default)({
|
|
44
|
+
min: axisConfig.min,
|
|
45
|
+
max: axisConfig.max
|
|
46
|
+
}, axisConfig.sizeMap) : axisConfig.sizeMap)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
35
49
|
function getZAxisState(zAxis, dataset) {
|
|
36
50
|
if (!zAxis || zAxis.length === 0) {
|
|
37
51
|
return {
|
|
@@ -45,16 +59,16 @@ function getZAxisState(zAxis, dataset) {
|
|
|
45
59
|
const dataKey = axisConfig.dataKey;
|
|
46
60
|
const defaultizedId = axisConfig.id ?? `defaultized-z-axis-${index}`;
|
|
47
61
|
if (axisConfig.data !== undefined || dataKey === undefined && !axisConfig.valueGetter) {
|
|
48
|
-
zAxisLookup[defaultizedId] = processColorMap(addDefaultId(axisConfig, defaultizedId));
|
|
62
|
+
zAxisLookup[defaultizedId] = processSizeMap(processColorMap(addDefaultId(axisConfig, defaultizedId)));
|
|
49
63
|
axisIds.push(defaultizedId);
|
|
50
64
|
return;
|
|
51
65
|
}
|
|
52
66
|
if (dataset === undefined) {
|
|
53
67
|
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Charts: The z-axis uses `dataKey` or `valueGetter` but no `dataset` is provided. ' + 'When using dataKey or valueGetter, a dataset must be provided to retrieve the axis data. ' + 'Either provide a dataset prop or use the data property directly on the z-axis.' : (0, _formatErrorMessage2.default)(41));
|
|
54
68
|
}
|
|
55
|
-
zAxisLookup[defaultizedId] = processColorMap(addDefaultId((0, _extends2.default)({}, axisConfig, {
|
|
69
|
+
zAxisLookup[defaultizedId] = processSizeMap(processColorMap(addDefaultId((0, _extends2.default)({}, axisConfig, {
|
|
56
70
|
data: axisConfig.valueGetter ? dataset.map(d => axisConfig.valueGetter(d)) : dataset.map(d => d[dataKey])
|
|
57
|
-
}), defaultizedId));
|
|
71
|
+
}), defaultizedId)));
|
|
58
72
|
axisIds.push(defaultizedId);
|
|
59
73
|
});
|
|
60
74
|
return {
|
|
@@ -4,6 +4,7 @@ import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
|
|
|
4
4
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { getColorScale, getOrdinalColorScale } from "../../../colorScale.mjs";
|
|
7
|
+
import { getSizeScale, getOrdinalSizeScale } from "../../../sizeScale.mjs";
|
|
7
8
|
function addDefaultId(axisConfig, defaultId) {
|
|
8
9
|
if (axisConfig.id !== undefined) {
|
|
9
10
|
return axisConfig;
|
|
@@ -25,6 +26,19 @@ function processColorMap(axisConfig) {
|
|
|
25
26
|
}, axisConfig.colorMap) : axisConfig.colorMap)
|
|
26
27
|
});
|
|
27
28
|
}
|
|
29
|
+
function processSizeMap(axisConfig) {
|
|
30
|
+
if (!axisConfig.sizeMap) {
|
|
31
|
+
return axisConfig;
|
|
32
|
+
}
|
|
33
|
+
return _extends({}, axisConfig, {
|
|
34
|
+
sizeScale: axisConfig.sizeMap.type === 'ordinal' ? getOrdinalSizeScale(_extends({
|
|
35
|
+
values: axisConfig.data
|
|
36
|
+
}, axisConfig.sizeMap)) : getSizeScale(axisConfig.sizeMap.type === 'continuous' ? _extends({
|
|
37
|
+
min: axisConfig.min,
|
|
38
|
+
max: axisConfig.max
|
|
39
|
+
}, axisConfig.sizeMap) : axisConfig.sizeMap)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
28
42
|
function getZAxisState(zAxis, dataset) {
|
|
29
43
|
if (!zAxis || zAxis.length === 0) {
|
|
30
44
|
return {
|
|
@@ -38,16 +52,16 @@ function getZAxisState(zAxis, dataset) {
|
|
|
38
52
|
const dataKey = axisConfig.dataKey;
|
|
39
53
|
const defaultizedId = axisConfig.id ?? `defaultized-z-axis-${index}`;
|
|
40
54
|
if (axisConfig.data !== undefined || dataKey === undefined && !axisConfig.valueGetter) {
|
|
41
|
-
zAxisLookup[defaultizedId] = processColorMap(addDefaultId(axisConfig, defaultizedId));
|
|
55
|
+
zAxisLookup[defaultizedId] = processSizeMap(processColorMap(addDefaultId(axisConfig, defaultizedId)));
|
|
42
56
|
axisIds.push(defaultizedId);
|
|
43
57
|
return;
|
|
44
58
|
}
|
|
45
59
|
if (dataset === undefined) {
|
|
46
60
|
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Charts: The z-axis uses `dataKey` or `valueGetter` but no `dataset` is provided. ' + 'When using dataKey or valueGetter, a dataset must be provided to retrieve the axis data. ' + 'Either provide a dataset prop or use the data property directly on the z-axis.' : _formatErrorMessage(41));
|
|
47
61
|
}
|
|
48
|
-
zAxisLookup[defaultizedId] = processColorMap(addDefaultId(_extends({}, axisConfig, {
|
|
62
|
+
zAxisLookup[defaultizedId] = processSizeMap(processColorMap(addDefaultId(_extends({}, axisConfig, {
|
|
49
63
|
data: axisConfig.valueGetter ? dataset.map(d => axisConfig.valueGetter(d)) : dataset.map(d => d[dataKey])
|
|
50
|
-
}), defaultizedId));
|
|
64
|
+
}), defaultizedId)));
|
|
51
65
|
axisIds.push(defaultizedId);
|
|
52
66
|
});
|
|
53
67
|
return {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ScaleOrdinal, type ScaleThreshold, type ScaleSequential } from '@mui/x-charts-vendor/d3-scale';
|
|
2
|
+
import { type ContinuousSizeConfig, type PiecewiseSizeConfig, type OrdinalSizeConfig } from "../models/sizeMapping.mjs";
|
|
3
|
+
export declare function getSequentialSizeScale<Value extends number | Date>(config: ContinuousSizeConfig<Value> | PiecewiseSizeConfig<Value>): ScaleThreshold<Value, number, never> | ScaleSequential<number, never>;
|
|
4
|
+
export declare function getOrdinalSizeScale(config: OrdinalSizeConfig): ScaleOrdinal<number | Date | string, number, number | null>;
|
|
5
|
+
export declare function getSizeScale(config: OrdinalSizeConfig): ScaleOrdinal<number | Date | string, number, number | null>;
|
|
6
|
+
export declare function getSizeScale(config: ContinuousSizeConfig | PiecewiseSizeConfig): ScaleThreshold<number | Date, number | null> | ScaleSequential<number, number | null>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ScaleOrdinal, type ScaleThreshold, type ScaleSequential } from '@mui/x-charts-vendor/d3-scale';
|
|
2
|
+
import { type ContinuousSizeConfig, type PiecewiseSizeConfig, type OrdinalSizeConfig } from "../models/sizeMapping.js";
|
|
3
|
+
export declare function getSequentialSizeScale<Value extends number | Date>(config: ContinuousSizeConfig<Value> | PiecewiseSizeConfig<Value>): ScaleThreshold<Value, number, never> | ScaleSequential<number, never>;
|
|
4
|
+
export declare function getOrdinalSizeScale(config: OrdinalSizeConfig): ScaleOrdinal<number | Date | string, number, number | null>;
|
|
5
|
+
export declare function getSizeScale(config: OrdinalSizeConfig): ScaleOrdinal<number | Date | string, number, number | null>;
|
|
6
|
+
export declare function getSizeScale(config: ContinuousSizeConfig | PiecewiseSizeConfig): ScaleThreshold<number | Date, number | null> | ScaleSequential<number, number | null>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getOrdinalSizeScale = getOrdinalSizeScale;
|
|
7
|
+
exports.getSequentialSizeScale = getSequentialSizeScale;
|
|
8
|
+
exports.getSizeScale = getSizeScale;
|
|
9
|
+
var _d3Scale = require("@mui/x-charts-vendor/d3-scale");
|
|
10
|
+
const isFunctionInterpolator = config => {
|
|
11
|
+
return typeof config.size === 'function';
|
|
12
|
+
};
|
|
13
|
+
function getClampedSize(sizes) {
|
|
14
|
+
const [minSize, maxSize] = sizes;
|
|
15
|
+
return t => {
|
|
16
|
+
const clampedT = Math.max(Math.min(t, 1), 0);
|
|
17
|
+
return minSize + clampedT * (maxSize - minSize);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function getSequentialSizeScale(config) {
|
|
21
|
+
if (config.type === 'piecewise') {
|
|
22
|
+
return (0, _d3Scale.scaleThreshold)(config.thresholds, config.sizes);
|
|
23
|
+
}
|
|
24
|
+
if (isFunctionInterpolator(config)) {
|
|
25
|
+
return (0, _d3Scale.scaleSequential)([config.min ?? 0, config.max ?? 100], config.size);
|
|
26
|
+
}
|
|
27
|
+
const interpolator = config.interpolator ?? 'sqrt';
|
|
28
|
+
switch (interpolator) {
|
|
29
|
+
case 'log':
|
|
30
|
+
return (0, _d3Scale.scaleSequentialLog)([config.min ?? 0, config.max ?? 100], getClampedSize(config.size));
|
|
31
|
+
case 'linear':
|
|
32
|
+
return (0, _d3Scale.scaleSequential)([config.min ?? 0, config.max ?? 100], getClampedSize(config.size));
|
|
33
|
+
case 'sqrt':
|
|
34
|
+
default:
|
|
35
|
+
return (0, _d3Scale.scaleSequentialSqrt)([config.min ?? 0, config.max ?? 100], getClampedSize(config.size));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function getOrdinalSizeScale(config) {
|
|
39
|
+
if (config.values) {
|
|
40
|
+
return (0, _d3Scale.scaleOrdinal)(config.values, config.sizes).unknown(config.unknownSize ?? null);
|
|
41
|
+
}
|
|
42
|
+
return (0, _d3Scale.scaleOrdinal)(config.sizes.map((_, index) => index), config.sizes).unknown(config.unknownSize ?? null);
|
|
43
|
+
}
|
|
44
|
+
function getSizeScale(config) {
|
|
45
|
+
return config.type === 'ordinal' ? getOrdinalSizeScale(config) : getSequentialSizeScale(config);
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { scaleOrdinal, scaleThreshold, scaleSequential, scaleSequentialSqrt, scaleSequentialLog } from '@mui/x-charts-vendor/d3-scale';
|
|
2
|
+
const isFunctionInterpolator = config => {
|
|
3
|
+
return typeof config.size === 'function';
|
|
4
|
+
};
|
|
5
|
+
function getClampedSize(sizes) {
|
|
6
|
+
const [minSize, maxSize] = sizes;
|
|
7
|
+
return t => {
|
|
8
|
+
const clampedT = Math.max(Math.min(t, 1), 0);
|
|
9
|
+
return minSize + clampedT * (maxSize - minSize);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function getSequentialSizeScale(config) {
|
|
13
|
+
if (config.type === 'piecewise') {
|
|
14
|
+
return scaleThreshold(config.thresholds, config.sizes);
|
|
15
|
+
}
|
|
16
|
+
if (isFunctionInterpolator(config)) {
|
|
17
|
+
return scaleSequential([config.min ?? 0, config.max ?? 100], config.size);
|
|
18
|
+
}
|
|
19
|
+
const interpolator = config.interpolator ?? 'sqrt';
|
|
20
|
+
switch (interpolator) {
|
|
21
|
+
case 'log':
|
|
22
|
+
return scaleSequentialLog([config.min ?? 0, config.max ?? 100], getClampedSize(config.size));
|
|
23
|
+
case 'linear':
|
|
24
|
+
return scaleSequential([config.min ?? 0, config.max ?? 100], getClampedSize(config.size));
|
|
25
|
+
case 'sqrt':
|
|
26
|
+
default:
|
|
27
|
+
return scaleSequentialSqrt([config.min ?? 0, config.max ?? 100], getClampedSize(config.size));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function getOrdinalSizeScale(config) {
|
|
31
|
+
if (config.values) {
|
|
32
|
+
return scaleOrdinal(config.values, config.sizes).unknown(config.unknownSize ?? null);
|
|
33
|
+
}
|
|
34
|
+
return scaleOrdinal(config.sizes.map((_, index) => index), config.sizes).unknown(config.unknownSize ?? null);
|
|
35
|
+
}
|
|
36
|
+
export function getSizeScale(config) {
|
|
37
|
+
return config.type === 'ordinal' ? getOrdinalSizeScale(config) : getSequentialSizeScale(config);
|
|
38
|
+
}
|