@mui/x-charts 8.17.0 → 8.19.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.
Files changed (134) hide show
  1. package/BarChart/BarLabel/BarLabel.d.ts +7 -1
  2. package/BarChart/BarLabel/BarLabel.js +41 -4
  3. package/BarChart/BarLabel/BarLabelItem.d.ts +6 -0
  4. package/BarChart/BarLabel/BarLabelItem.js +4 -2
  5. package/BarChart/BarLabel/BarLabelPlot.js +2 -3
  6. package/BarChart/BarPlot.js +5 -0
  7. package/BarChart/seriesConfig/bar/seriesProcessor.js +15 -9
  8. package/BarChart/types.d.ts +1 -0
  9. package/BarChart/useBarPlotData.js +3 -2
  10. package/CHANGELOG.md +213 -0
  11. package/ChartsSurface/ChartsSurface.js +5 -2
  12. package/LineChart/seriesConfig/seriesProcessor.js +15 -10
  13. package/PieChart/PieArcPlot.js +5 -3
  14. package/esm/BarChart/BarLabel/BarLabel.d.ts +7 -1
  15. package/esm/BarChart/BarLabel/BarLabel.js +41 -4
  16. package/esm/BarChart/BarLabel/BarLabelItem.d.ts +6 -0
  17. package/esm/BarChart/BarLabel/BarLabelItem.js +4 -2
  18. package/esm/BarChart/BarLabel/BarLabelPlot.js +2 -2
  19. package/esm/BarChart/BarPlot.js +5 -0
  20. package/esm/BarChart/seriesConfig/bar/seriesProcessor.js +15 -9
  21. package/esm/BarChart/types.d.ts +1 -0
  22. package/esm/BarChart/useBarPlotData.js +3 -2
  23. package/esm/ChartsSurface/ChartsSurface.js +5 -2
  24. package/esm/LineChart/seriesConfig/seriesProcessor.js +15 -10
  25. package/esm/PieChart/PieArcPlot.js +5 -3
  26. package/esm/hooks/animation/useAnimateBarLabel.d.ts +1 -1
  27. package/esm/hooks/animation/useAnimateBarLabel.js +61 -12
  28. package/esm/hooks/useAxis.d.ts +116 -16
  29. package/esm/hooks/useAxis.js +122 -18
  30. package/esm/hooks/useBarSeries.js +3 -5
  31. package/esm/hooks/useLineSeries.js +3 -5
  32. package/esm/hooks/usePieSeries.js +3 -5
  33. package/esm/hooks/useRadarSeries.js +3 -5
  34. package/esm/hooks/useScale.d.ts +25 -6
  35. package/esm/hooks/useScale.js +29 -8
  36. package/esm/hooks/useScatterSeries.js +3 -5
  37. package/esm/index.d.ts +2 -1
  38. package/esm/index.js +2 -1
  39. package/esm/internals/domUtils.js +30 -14
  40. package/esm/internals/getScale.d.ts +2 -1
  41. package/esm/internals/index.d.ts +1 -1
  42. package/esm/internals/index.js +1 -1
  43. package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.js +2 -2
  44. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js +5 -6
  45. package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +2 -2
  46. package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.js +2 -2
  47. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +4 -1
  48. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +3 -1
  49. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +1 -1
  50. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +4 -4
  51. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +1 -1
  52. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +15 -15
  53. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +1 -1
  54. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +5 -5
  55. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +3 -0
  56. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +11 -11
  57. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +5 -6
  58. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +7 -8
  59. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +2 -2
  60. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.selectors.js +2 -2
  61. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +11 -12
  62. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +8 -8
  63. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +4 -4
  64. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -11
  65. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.js +6 -6
  66. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +7 -8
  67. package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.js +2 -2
  68. package/esm/internals/plugins/utils/selectors.d.ts +1 -14
  69. package/esm/internals/plugins/utils/selectors.js +1 -5
  70. package/esm/internals/seriesSelectorOfType.d.ts +20 -0
  71. package/esm/internals/seriesSelectorOfType.js +38 -0
  72. package/esm/models/seriesType/bar.d.ts +7 -0
  73. package/esm/models/seriesType/config.d.ts +2 -2
  74. package/esm/utils/index.d.ts +4 -0
  75. package/esm/utils/index.js +5 -0
  76. package/esm/utils/niceDomain.d.ts +20 -0
  77. package/esm/utils/niceDomain.js +24 -0
  78. package/hooks/animation/useAnimateBarLabel.d.ts +1 -1
  79. package/hooks/animation/useAnimateBarLabel.js +61 -12
  80. package/hooks/useAxis.d.ts +116 -16
  81. package/hooks/useAxis.js +122 -18
  82. package/hooks/useBarSeries.js +3 -6
  83. package/hooks/useLineSeries.js +3 -6
  84. package/hooks/usePieSeries.js +3 -6
  85. package/hooks/useRadarSeries.js +3 -6
  86. package/hooks/useScale.d.ts +25 -6
  87. package/hooks/useScale.js +29 -8
  88. package/hooks/useScatterSeries.js +3 -6
  89. package/index.d.ts +2 -1
  90. package/index.js +13 -1
  91. package/internals/domUtils.js +30 -14
  92. package/internals/getScale.d.ts +2 -1
  93. package/internals/index.d.ts +1 -1
  94. package/internals/index.js +4 -4
  95. package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.js +2 -2
  96. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js +4 -5
  97. package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +2 -2
  98. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.js +2 -2
  99. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +4 -1
  100. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +3 -1
  101. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +1 -1
  102. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +4 -4
  103. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +1 -1
  104. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +15 -15
  105. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +1 -1
  106. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +5 -5
  107. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +3 -0
  108. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +11 -11
  109. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +4 -5
  110. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +6 -7
  111. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +2 -2
  112. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.selectors.js +2 -2
  113. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -11
  114. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +8 -8
  115. package/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +4 -4
  116. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -11
  117. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.js +6 -6
  118. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +6 -7
  119. package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.js +2 -2
  120. package/internals/plugins/utils/selectors.d.ts +1 -14
  121. package/internals/plugins/utils/selectors.js +1 -8
  122. package/internals/seriesSelectorOfType.d.ts +20 -0
  123. package/internals/seriesSelectorOfType.js +46 -0
  124. package/models/seriesType/bar.d.ts +7 -0
  125. package/models/seriesType/config.d.ts +2 -2
  126. package/package.json +5 -5
  127. package/utils/index.d.ts +4 -0
  128. package/utils/index.js +16 -0
  129. package/utils/niceDomain.d.ts +20 -0
  130. package/utils/niceDomain.js +29 -0
  131. package/esm/internals/createSeriesSelectorOfType.d.ts +0 -4
  132. package/esm/internals/createSeriesSelectorOfType.js +0 -45
  133. package/internals/createSeriesSelectorOfType.d.ts +0 -4
  134. package/internals/createSeriesSelectorOfType.js +0 -53
@@ -7,12 +7,17 @@ import { useStore } from "../internals/store/useStore.js";
7
7
  /**
8
8
  * Get all the x-axes.
9
9
  *
10
- * - `xAxis` is an object with the shape `{ [axisId]: axis }`.
11
- * - `xAxisIds` is an array of axis IDs.
10
+ * Returns all X axes configured in the chart along with their IDs.
11
+ * This is useful when you need to iterate over multiple axes or access all axis configurations at once.
12
12
  *
13
- * If access to a specific X axis is needed, use the `useXAxis` hook instead.
13
+ * @returns An object containing:
14
+ * - `xAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
15
+ * - `xAxisIds`: An array of all X axis IDs in the chart
14
16
  *
15
- * @returns `{ xAxis, xAxisIds }` - The x-axes and their IDs.
17
+ * @example
18
+ * const { xAxis, xAxisIds } = useXAxes();
19
+ *
20
+ * @see `useXAxis` for accessing a single X axis
16
21
  */
17
22
  export function useXAxes() {
18
23
  const store = useStore();
@@ -29,12 +34,17 @@ export function useXAxes() {
29
34
  /**
30
35
  * Get all the y-axes.
31
36
  *
32
- * - `yAxis` is an object with the shape `{ [axisId]: axis }`.
33
- * - `yAxisIds` is an array of axis IDs.
37
+ * Returns all Y axes configured in the chart along with their IDs.
38
+ * This is useful when you need to iterate over multiple axes or access all axis configurations at once.
39
+ *
40
+ * @returns An object containing:
41
+ * - `yAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
42
+ * - `yAxisIds`: An array of all Y axis IDs in the chart
34
43
  *
35
- * If access to a specific Y axis is needed, use the `useYAxis` hook instead.
44
+ * @example
45
+ * const { yAxis, yAxisIds } = useYAxes();
36
46
  *
37
- * @returns `{ yAxis, yAxisIds }` - The y-axes and their IDs.
47
+ * @see `useYAxis` for accessing a single Y axis
38
48
  */
39
49
  export function useYAxes() {
40
50
  const store = useStore();
@@ -49,9 +59,20 @@ export function useYAxes() {
49
59
  }
50
60
 
51
61
  /**
52
- * Get the X axis.
53
- * @param {AxisId | undefined} axisId - If provided returns the x axis with axisId, else returns the values for the default x axis.
54
- * @returns The X axis.
62
+ * Get a specific X axis or the default X axis.
63
+ *
64
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
65
+ * - A string or number matching the axis ID defined in the chart's `xAxis` prop
66
+ * - Undefined to get the default (first) X axis
67
+ * @returns The configuration for a single X axis.
68
+ *
69
+ * @example
70
+ * // Get the default X axis
71
+ * const xAxis = useXAxis();
72
+ *
73
+ * @example
74
+ * // Get a specific X axis by string ID
75
+ * const xAxis = useXAxis('revenue');
55
76
  */
56
77
  export function useXAxis(axisId) {
57
78
  const store = useStore();
@@ -64,9 +85,20 @@ export function useXAxis(axisId) {
64
85
  }
65
86
 
66
87
  /**
67
- * Get the Y axis.
68
- * @param {AxisId | undefined} axisId - If provided returns the y axis with axisId, else returns the values for the default y axis.
69
- * @returns The Y axis.
88
+ * Get a specific Y axis or the default Y axis.
89
+ *
90
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
91
+ * - A string or number matching the axis ID defined in the chart's `yAxis` prop
92
+ * - Undefined to get the default (first) Y axis
93
+ * @returns The configuration for a single Y axis.
94
+ *
95
+ * @example
96
+ * // Get the default Y axis
97
+ * const yAxis = useYAxis();
98
+ *
99
+ * @example
100
+ * // Get a specific Y axis by string ID
101
+ * const yAxis = useYAxis('temperature');
70
102
  */
71
103
  export function useYAxis(axisId) {
72
104
  const store = useStore();
@@ -77,6 +109,22 @@ export function useYAxis(axisId) {
77
109
  const id = axisId ?? yAxisIds[0];
78
110
  return yAxis[id];
79
111
  }
112
+
113
+ /**
114
+ * Get all the rotation axes for polar charts.
115
+ *
116
+ * Returns all rotation axes configured in polar charts along with their IDs.
117
+ * Rotation axes are used in charts like `RadarChart` to define angular positioning.
118
+ *
119
+ * @returns An object containing:
120
+ * - `rotationAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
121
+ * - `rotationAxisIds`: An array of all rotation axis IDs in the chart
122
+ *
123
+ * @example
124
+ * const { rotationAxis, rotationAxisIds } = useRotationAxes();
125
+ *
126
+ * @see `useRotationAxis` for accessing a single rotation axis
127
+ */
80
128
  export function useRotationAxes() {
81
129
  const store = useStore();
82
130
  const {
@@ -88,6 +136,22 @@ export function useRotationAxes() {
88
136
  rotationAxisIds
89
137
  };
90
138
  }
139
+
140
+ /**
141
+ * Get all the radius axes for polar charts.
142
+ *
143
+ * Returns all radial axes configured in polar charts along with their IDs.
144
+ * Radius axes are used in charts like `RadarChart` to define radial positioning and scaling.
145
+ *
146
+ * @returns An object containing:
147
+ * - `radiusAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
148
+ * - `radiusAxisIds`: An array of all radius axis IDs in the chart
149
+ *
150
+ * @example
151
+ * const { radiusAxis, radiusAxisIds } = useRadiusAxes();
152
+ *
153
+ * @see `useRadiusAxis` for accessing a single radius axis
154
+ */
91
155
  export function useRadiusAxes() {
92
156
  const store = useStore();
93
157
  const {
@@ -99,21 +163,61 @@ export function useRadiusAxes() {
99
163
  radiusAxisIds
100
164
  };
101
165
  }
102
- export function useRotationAxis(identifier) {
166
+
167
+ /**
168
+ * Get a specific rotation axis or the default rotation axis for polar charts.
169
+ *
170
+ * Returns the configuration and scale for a rotation axis in polar charts.
171
+ * The rotation axis controls the angular positioning of data points around the circle.
172
+ *
173
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
174
+ * - A string or number matching the axis ID defined in the chart's rotation axis configuration
175
+ * - Undefined to get the default (first) rotation axis
176
+ * @returns The rotation axis configuration, or undefined if not found
177
+ *
178
+ * @example
179
+ * // Get the default rotation axis
180
+ * const rotationAxis = useRotationAxis();
181
+ *
182
+ * @example
183
+ * // Get a specific rotation axis by string ID
184
+ * const rotationAxis = useRotationAxis('categories');
185
+ */
186
+ export function useRotationAxis(axisId) {
103
187
  const store = useStore();
104
188
  const {
105
189
  axis: rotationAxis,
106
190
  axisIds: rotationAxisIds
107
191
  } = useSelector(store, selectorChartRotationAxis);
108
- const id = typeof identifier === 'string' ? identifier : rotationAxisIds[identifier ?? 0];
192
+ const id = axisId ?? rotationAxisIds[0];
109
193
  return rotationAxis[id];
110
194
  }
111
- export function useRadiusAxis(identifier) {
195
+
196
+ /**
197
+ * Get a specific radius axis or the default radius axis for polar charts.
198
+ *
199
+ * Returns the configuration and scale for a radial axis in polar charts.
200
+ * The radius axis controls the radial distance of data points from the center of the circle.
201
+ *
202
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
203
+ * - A string or number matching the axis ID defined in the chart's radius axis configuration
204
+ * - Undefined to get the default (first) radius axis
205
+ * @returns The radius axis configuration, or undefined if not found
206
+ *
207
+ * @example
208
+ * // Get the default radius axis
209
+ * const radiusAxis = useRadiusAxis();
210
+ *
211
+ * @example
212
+ * // Get a specific radius axis by string ID
213
+ * const radiusAxis = useRadiusAxis('magnitude');
214
+ */
215
+ export function useRadiusAxis(axisId) {
112
216
  const store = useStore();
113
217
  const {
114
218
  axis: radiusAxis,
115
219
  axisIds: radiusAxisIds
116
220
  } = useSelector(store, selectorChartRadiusAxis);
117
- const id = typeof identifier === 'string' ? identifier : radiusAxisIds[identifier ?? 0];
221
+ const id = axisId ?? radiusAxisIds[0];
118
222
  return radiusAxis[id];
119
223
  }
@@ -1,8 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { createSeriesSelectorsOfType, createAllSeriesSelectorOfType } from "../internals/createSeriesSelectorOfType.js";
4
- const useSelectorSeries = createSeriesSelectorsOfType('bar');
5
- const useSelectorSeriesContext = createAllSeriesSelectorOfType('bar');
3
+ import { useSeriesOfType, useAllSeriesOfType } from "../internals/seriesSelectorOfType.js";
6
4
 
7
5
  /**
8
6
  * Get access to the internal state of bar series.
@@ -27,7 +25,7 @@ const useSelectorSeriesContext = createAllSeriesSelectorOfType('bar');
27
25
  */
28
26
 
29
27
  export function useBarSeries(seriesIds) {
30
- return useSelectorSeries(seriesIds);
28
+ return useSeriesOfType('bar', seriesIds);
31
29
  }
32
30
 
33
31
  /**
@@ -39,5 +37,5 @@ export function useBarSeries(seriesIds) {
39
37
  * @returns the bar series
40
38
  */
41
39
  export function useBarSeriesContext() {
42
- return useSelectorSeriesContext();
40
+ return useAllSeriesOfType('bar');
43
41
  }
@@ -1,8 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { createSeriesSelectorsOfType, createAllSeriesSelectorOfType } from "../internals/createSeriesSelectorOfType.js";
4
- const useSelectorSeries = createSeriesSelectorsOfType('line');
5
- const useSelectorSeriesContext = createAllSeriesSelectorOfType('line');
3
+ import { useSeriesOfType, useAllSeriesOfType } from "../internals/seriesSelectorOfType.js";
6
4
 
7
5
  /**
8
6
  * Get access to the internal state of line series.
@@ -27,7 +25,7 @@ const useSelectorSeriesContext = createAllSeriesSelectorOfType('line');
27
25
  */
28
26
 
29
27
  export function useLineSeries(seriesIds) {
30
- return useSelectorSeries(seriesIds);
28
+ return useSeriesOfType('line', seriesIds);
31
29
  }
32
30
 
33
31
  /**
@@ -39,5 +37,5 @@ export function useLineSeries(seriesIds) {
39
37
  * @returns the line series
40
38
  */
41
39
  export function useLineSeriesContext() {
42
- return useSelectorSeriesContext();
40
+ return useAllSeriesOfType('line');
43
41
  }
@@ -1,8 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { createSeriesSelectorsOfType, createAllSeriesSelectorOfType } from "../internals/createSeriesSelectorOfType.js";
4
- const useSelectorSeries = createSeriesSelectorsOfType('pie');
5
- const useSelectorSeriesContext = createAllSeriesSelectorOfType('pie');
3
+ import { useSeriesOfType, useAllSeriesOfType } from "../internals/seriesSelectorOfType.js";
6
4
 
7
5
  /**
8
6
  * Get access to the internal state of pie series.
@@ -27,7 +25,7 @@ const useSelectorSeriesContext = createAllSeriesSelectorOfType('pie');
27
25
  */
28
26
 
29
27
  export function usePieSeries(seriesIds) {
30
- return useSelectorSeries(seriesIds);
28
+ return useSeriesOfType('pie', seriesIds);
31
29
  }
32
30
 
33
31
  /**
@@ -38,5 +36,5 @@ export function usePieSeries(seriesIds) {
38
36
  * @returns the pie series
39
37
  */
40
38
  export function usePieSeriesContext() {
41
- return useSelectorSeriesContext();
39
+ return useAllSeriesOfType('pie');
42
40
  }
@@ -1,8 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { createSeriesSelectorsOfType, createAllSeriesSelectorOfType } from "../internals/createSeriesSelectorOfType.js";
4
- const useSelectorSeries = createSeriesSelectorsOfType('radar');
5
- const useSelectorSeriesContext = createAllSeriesSelectorOfType('radar');
3
+ import { useSeriesOfType, useAllSeriesOfType } from "../internals/seriesSelectorOfType.js";
6
4
 
7
5
  /**
8
6
  * Get access to the internal state of radar series.
@@ -27,7 +25,7 @@ const useSelectorSeriesContext = createAllSeriesSelectorOfType('radar');
27
25
  */
28
26
 
29
27
  export function useRadarSeries(seriesIds) {
30
- return useSelectorSeries(seriesIds);
28
+ return useSeriesOfType('radar', seriesIds);
31
29
  }
32
30
 
33
31
  /**
@@ -38,5 +36,5 @@ export function useRadarSeries(seriesIds) {
38
36
  * @returns the radar series
39
37
  */
40
38
  export function useRadarSeriesContext() {
41
- return useSelectorSeriesContext();
39
+ return useAllSeriesOfType('radar');
42
40
  }
@@ -13,16 +13,35 @@ export declare function getValueToPositionMapper<Domain extends {
13
13
  /**
14
14
  * Get the X scale.
15
15
  *
16
- * @param {AxisId | undefined} axisId - If provided returns the scale for the x axis with axisId, else returns the values for the default x axis.
17
- * @returns {AxisScaleConfig[S]['scale']} The scale for the specified X axis.
16
+ * @param axisId - The axis identifier. Can be:
17
+ * - A string or number matching the axis ID defined in the chart's `xAxis` prop
18
+ * - Undefined to get the default (first) X axis
19
+ * @returns The X axis scale
18
20
  */
19
21
  export declare function useXScale<S extends ScaleName>(axisId?: AxisId): AxisScaleConfig[S]['scale'];
20
22
  /**
21
23
  * Get the Y scale.
22
24
  *
23
- * @param {AxisId | undefined} axisId - If provided returns the scale for the y axis with axisId, else returns the values for the default y axis.
24
- * @returns {AxisScaleConfig[S]['scale']} The scale for the specified Y axis.
25
+ * @param axisId - The axis identifier. Can be:
26
+ * - A string or number matching the axis ID defined in the chart's `yAxis` prop
27
+ * - Undefined to get the default (first) Y axis
28
+ * @returns The Y axis scale
25
29
  */
26
30
  export declare function useYScale<S extends ScaleName>(axisId?: AxisId): AxisScaleConfig[S]['scale'];
27
- export declare function useRotationScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'] | undefined;
28
- export declare function useRadiusScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'] | undefined;
31
+ /**
32
+ * Get the rotation scale.
33
+ *
34
+ * @param axisId - The axis identifier. Can be:
35
+ * - A string or number matching the axis ID defined in the chart's `rotationAxis` prop
36
+ * - Undefined to get the default rotation axis
37
+ * @returns The rotation axis scale, or undefined if not found
38
+ */
39
+ export declare function useRotationScale<S extends ScaleName>(axisId?: number | string): AxisScaleConfig[S]['scale'] | undefined;
40
+ /**
41
+ * Get the radius scale.
42
+ * @param axisId - The axis identifier. Can be:
43
+ * - A string or number matching the axis ID defined in the chart's `radiusAxis` prop
44
+ * - Undefined to get the default radius axis
45
+ * @returns The radius axis scale, or undefined if not found
46
+ */
47
+ export declare function useRadiusScale<S extends ScaleName>(axisId?: number | string): AxisScaleConfig[S]['scale'] | undefined;
@@ -25,8 +25,10 @@ export function getValueToPositionMapper(scale) {
25
25
  /**
26
26
  * Get the X scale.
27
27
  *
28
- * @param {AxisId | undefined} axisId - If provided returns the scale for the x axis with axisId, else returns the values for the default x axis.
29
- * @returns {AxisScaleConfig[S]['scale']} The scale for the specified X axis.
28
+ * @param axisId - The axis identifier. Can be:
29
+ * - A string or number matching the axis ID defined in the chart's `xAxis` prop
30
+ * - Undefined to get the default (first) X axis
31
+ * @returns The X axis scale
30
32
  */
31
33
  export function useXScale(axisId) {
32
34
  const axis = useXAxis(axisId);
@@ -36,18 +38,37 @@ export function useXScale(axisId) {
36
38
  /**
37
39
  * Get the Y scale.
38
40
  *
39
- * @param {AxisId | undefined} axisId - If provided returns the scale for the y axis with axisId, else returns the values for the default y axis.
40
- * @returns {AxisScaleConfig[S]['scale']} The scale for the specified Y axis.
41
+ * @param axisId - The axis identifier. Can be:
42
+ * - A string or number matching the axis ID defined in the chart's `yAxis` prop
43
+ * - Undefined to get the default (first) Y axis
44
+ * @returns The Y axis scale
41
45
  */
42
46
  export function useYScale(axisId) {
43
47
  const axis = useYAxis(axisId);
44
48
  return axis.scale;
45
49
  }
46
- export function useRotationScale(identifier) {
47
- const axis = useRotationAxis(identifier);
50
+
51
+ /**
52
+ * Get the rotation scale.
53
+ *
54
+ * @param axisId - The axis identifier. Can be:
55
+ * - A string or number matching the axis ID defined in the chart's `rotationAxis` prop
56
+ * - Undefined to get the default rotation axis
57
+ * @returns The rotation axis scale, or undefined if not found
58
+ */
59
+ export function useRotationScale(axisId) {
60
+ const axis = useRotationAxis(axisId);
48
61
  return axis?.scale;
49
62
  }
50
- export function useRadiusScale(identifier) {
51
- const axis = useRadiusAxis(identifier);
63
+
64
+ /**
65
+ * Get the radius scale.
66
+ * @param axisId - The axis identifier. Can be:
67
+ * - A string or number matching the axis ID defined in the chart's `radiusAxis` prop
68
+ * - Undefined to get the default radius axis
69
+ * @returns The radius axis scale, or undefined if not found
70
+ */
71
+ export function useRadiusScale(axisId) {
72
+ const axis = useRadiusAxis(axisId);
52
73
  return axis?.scale;
53
74
  }
@@ -1,8 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { createSeriesSelectorsOfType, createAllSeriesSelectorOfType } from "../internals/createSeriesSelectorOfType.js";
4
- const useSelectorSeries = createSeriesSelectorsOfType('scatter');
5
- const useSelectorSeriesContext = createAllSeriesSelectorOfType('scatter');
3
+ import { useSeriesOfType, useAllSeriesOfType } from "../internals/seriesSelectorOfType.js";
6
4
 
7
5
  /**
8
6
  * Get access to the internal state of scatter series.
@@ -27,7 +25,7 @@ const useSelectorSeriesContext = createAllSeriesSelectorOfType('scatter');
27
25
  */
28
26
 
29
27
  export function useScatterSeries(seriesIds) {
30
- return useSelectorSeries(seriesIds);
28
+ return useSeriesOfType('scatter', seriesIds);
31
29
  }
32
30
 
33
31
  /**
@@ -38,5 +36,5 @@ export function useScatterSeries(seriesIds) {
38
36
  * @returns the scatter series
39
37
  */
40
38
  export function useScatterSeriesContext() {
41
- return useSelectorSeriesContext();
39
+ return useAllSeriesOfType('scatter');
42
40
  }
package/esm/index.d.ts CHANGED
@@ -29,4 +29,5 @@ export type { ChartContainerProps } from "./ChartContainer/index.js";
29
29
  export * from "./ChartDataProvider/index.js";
30
30
  export * from "./Toolbar/index.js";
31
31
  export * from "./ChartsWrapper/index.js";
32
- export * from "./ChartsBrushOverlay/index.js";
32
+ export * from "./ChartsBrushOverlay/index.js";
33
+ export * from "./utils/index.js";
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.17.0
2
+ * @mui/x-charts v8.19.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -36,6 +36,7 @@ export * from "./ChartDataProvider/index.js";
36
36
  export * from "./Toolbar/index.js";
37
37
  export * from "./ChartsWrapper/index.js";
38
38
  export * from "./ChartsBrushOverlay/index.js";
39
+ export * from "./utils/index.js";
39
40
 
40
41
  // Locales should be imported from `@mui/x-charts/locales`
41
42
  // export * from './locales';
@@ -86,11 +86,7 @@ export const getStringSize = (text, style = {}) => {
86
86
  });
87
87
  measurementElem.textContent = str;
88
88
  measurementSpanContainer.replaceChildren(measurementElem);
89
- const rect = measurementElem.getBoundingClientRect();
90
- const result = {
91
- width: rect.width,
92
- height: rect.height
93
- };
89
+ const result = measureSVGTextElement(measurementElem);
94
90
  stringCache.set(cacheKey, result);
95
91
  if (stringCache.size + 1 > MAX_CACHE_NUM) {
96
92
  stringCache.clear();
@@ -134,21 +130,17 @@ export function batchMeasureStrings(texts, style = {}) {
134
130
  measurementContainer.style[camelCaseToDashCase(styleKey)] = convertPixelValue(styleKey, measurementSpanStyle[styleKey]);
135
131
  return styleKey;
136
132
  });
137
- const measurementElems = [];
133
+ const measurementElements = [];
138
134
  for (const string of textToMeasure) {
139
135
  const measurementElem = document.createElementNS('http://www.w3.org/2000/svg', 'text');
140
136
  measurementElem.textContent = `${string}`;
141
- measurementElems.push(measurementElem);
137
+ measurementElements.push(measurementElem);
142
138
  }
143
- measurementContainer.replaceChildren(...measurementElems);
139
+ measurementContainer.replaceChildren(...measurementElements);
144
140
  for (let i = 0; i < textToMeasure.length; i += 1) {
145
141
  const text = textToMeasure[i];
146
- const measurementSpan = measurementContainer.children[i];
147
- const rect = measurementSpan.getBoundingClientRect();
148
- const result = {
149
- width: rect.width,
150
- height: rect.height
151
- };
142
+ const measurementElem = measurementContainer.children[i];
143
+ const result = measureSVGTextElement(measurementElem);
152
144
  const cacheKey = `${text}-${styleString}`;
153
145
  stringCache.set(cacheKey, result);
154
146
  sizeMap.set(text, result);
@@ -162,6 +154,30 @@ export function batchMeasureStrings(texts, style = {}) {
162
154
  }
163
155
  return sizeMap;
164
156
  }
157
+
158
+ /**
159
+ * Measures an SVG text element using getBBox() with fallback to getBoundingClientRect()
160
+ * @param element SVG text element to measure
161
+ * @returns width and height of the text element
162
+ */
163
+ function measureSVGTextElement(element) {
164
+ // getBBox() is more reliable across browsers for SVG elements
165
+ try {
166
+ const result = element.getBBox();
167
+ return {
168
+ width: result.width,
169
+ height: result.height
170
+ };
171
+ } catch {
172
+ // Fallback to getBoundingClientRect if getBBox fails
173
+ // This can happen in tests
174
+ const result = element.getBoundingClientRect();
175
+ return {
176
+ width: result.width,
177
+ height: result.height
178
+ };
179
+ }
180
+ }
165
181
  let measurementContainer = null;
166
182
 
167
183
  /**
@@ -1,2 +1,3 @@
1
+ import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
1
2
  import { ContinuousScaleName, D3ContinuousScale } from "../models/axis.js";
2
- export declare function getScale(scaleType: ContinuousScaleName, domain: readonly any[], range: readonly any[]): D3ContinuousScale;
3
+ export declare function getScale<Domain extends NumberValue = any, Range = any>(scaleType: ContinuousScaleName, domain: Iterable<Domain>, range: readonly Range[]): D3ContinuousScale<Range, Range>;
@@ -15,7 +15,7 @@ export { useBarPlotData } from "../BarChart/useBarPlotData.js";
15
15
  export { useRadarChartProps } from "../RadarChart/useRadarChartProps.js";
16
16
  export * from "../ChartContainer/useChartContainerProps.js";
17
17
  export * from "../ChartDataProvider/useChartDataProviderProps.js";
18
- export * from "./createSeriesSelectorOfType.js";
18
+ export * from "./seriesSelectorOfType.js";
19
19
  export * from "./plugins/corePlugins/useChartId/index.js";
20
20
  export * from "./plugins/corePlugins/useChartSeries/index.js";
21
21
  export * from "./plugins/corePlugins/useChartDimensions/index.js";
@@ -18,7 +18,7 @@ export { useBarPlotData } from "../BarChart/useBarPlotData.js";
18
18
  export { useRadarChartProps } from "../RadarChart/useRadarChartProps.js";
19
19
  export * from "../ChartContainer/useChartContainerProps.js";
20
20
  export * from "../ChartDataProvider/useChartDataProviderProps.js";
21
- export * from "./createSeriesSelectorOfType.js";
21
+ export * from "./seriesSelectorOfType.js";
22
22
 
23
23
  // plugins
24
24
  export * from "./plugins/corePlugins/useChartId/index.js";
@@ -1,3 +1,3 @@
1
- import { createSelector } from "../../utils/selectors.js";
1
+ import { createSelector } from '@mui/x-internals/store';
2
2
  const selectorChartAnimationState = state => state.animation;
3
- export const selectorChartSkipAnimation = createSelector([selectorChartAnimationState], state => state.skip || state.skipAnimationRequests > 0);
3
+ export const selectorChartSkipAnimation = createSelector(selectorChartAnimationState, state => state.skip || state.skipAnimationRequests > 0);
@@ -1,5 +1,4 @@
1
- import { createSelectorMemoized } from '@mui/x-internals/store';
2
- import { createSelector } from "../../utils/selectors.js";
1
+ import { createSelector, createSelectorMemoized } from '@mui/x-internals/store';
3
2
  import { selectorChartAxisSizes } from "../../featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.js";
4
3
  export const selectorChartDimensionsState = state => state.dimensions;
5
4
  export const selectorChartMargin = state => state.dimensions.margin;
@@ -26,7 +25,7 @@ export const selectorChartDrawingArea = createSelectorMemoized(selectorChartDime
26
25
  bottom: marginBottom + axisSizeBottom
27
26
  };
28
27
  });
29
- export const selectorChartSvgWidth = createSelector([selectorChartDimensionsState], dimensionsState => dimensionsState.width);
30
- export const selectorChartSvgHeight = createSelector([selectorChartDimensionsState], dimensionsState => dimensionsState.height);
31
- export const selectorChartPropsWidth = createSelector([selectorChartDimensionsState], dimensionsState => dimensionsState.propsWidth);
32
- export const selectorChartPropsHeight = createSelector([selectorChartDimensionsState], dimensionsState => dimensionsState.propsHeight);
28
+ export const selectorChartSvgWidth = createSelector(selectorChartDimensionsState, dimensionsState => dimensionsState.width);
29
+ export const selectorChartSvgHeight = createSelector(selectorChartDimensionsState, dimensionsState => dimensionsState.height);
30
+ export const selectorChartPropsWidth = createSelector(selectorChartDimensionsState, dimensionsState => dimensionsState.propsWidth);
31
+ export const selectorChartPropsHeight = createSelector(selectorChartDimensionsState, dimensionsState => dimensionsState.propsHeight);
@@ -1,3 +1,3 @@
1
- import { createSelector } from "../../utils/selectors.js";
1
+ import { createSelector } from '@mui/x-internals/store';
2
2
  export const selectorChartExperimentalFeaturesState = state => state.experimentalFeatures;
3
- export const selectorPreferStrictDomainInLineCharts = createSelector([selectorChartExperimentalFeaturesState], features => Boolean(features?.preferStrictDomainInLineCharts));
3
+ export const selectorPreferStrictDomainInLineCharts = createSelector(selectorChartExperimentalFeaturesState, features => Boolean(features?.preferStrictDomainInLineCharts));
@@ -1,4 +1,4 @@
1
- import { createSelector } from "../../utils/selectors.js";
1
+ import { createSelector } from '@mui/x-internals/store';
2
2
  const selectorChartIdState = state => state.id;
3
3
 
4
4
  /**
@@ -6,4 +6,4 @@ const selectorChartIdState = state => state.id;
6
6
  * @param {ChartState<[UseChartIdSignature]>} state The state of the chart.
7
7
  * @returns {string} The id attribute of the chart.
8
8
  */
9
- export const selectorChartId = createSelector([selectorChartIdState], idState => idState.chartId);
9
+ export const selectorChartId = createSelector(selectorChartIdState, idState => idState.chartId);
@@ -44,6 +44,9 @@ export const useChartInteractionListener = ({
44
44
  name: 'zoomTurnWheel',
45
45
  sensitivity: 0.01,
46
46
  initialDelta: 1
47
+ }), new TurnWheelGesture({
48
+ name: 'panTurnWheel',
49
+ sensitivity: 0.5
47
50
  }), new TapAndDragGesture({
48
51
  name: 'zoomTapAndDrag',
49
52
  dragThreshold: 10
@@ -63,7 +66,7 @@ export const useChartInteractionListener = ({
63
66
  if (!svg || !gestureManager) {
64
67
  return undefined;
65
68
  }
66
- gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag', 'zoomPressAndDrag', 'zoomDoubleTapReset', 'brush'], svg);
69
+ gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'panTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag', 'zoomPressAndDrag', 'zoomDoubleTapReset', 'brush'], svg);
67
70
  return () => {
68
71
  // Cleanup gesture manager
69
72
  gestureManager.unregisterAllGestures(svg);
@@ -1,6 +1,6 @@
1
1
  import { MoveEvent, PanEvent, PanGestureOptions, PinchEvent, PinchGestureOptions, PressEvent, TapEvent, TurnWheelEvent, type PressAndDragEvent, type PressAndDragGestureOptions, type TapAndDragEvent, type TapAndDragGestureOptions, type TapGestureOptions, type TurnWheelGestureOptions } from '@mui/x-internal-gestures/core';
2
2
  import { ChartPluginSignature } from "../../models/index.js";
3
- export type ChartInteraction = 'pan' | 'panStart' | 'panEnd' | 'zoomPan' | 'zoomPanStart' | 'zoomPanEnd' | 'zoomPinch' | 'zoomPinchStart' | 'zoomPinchEnd' | 'zoomTurnWheel' | 'zoomTapAndDrag' | 'zoomTapAndDragStart' | 'zoomTapAndDragEnd' | 'zoomPressAndDrag' | 'zoomPressAndDragStart' | 'zoomPressAndDragEnd' | 'move' | 'moveStart' | 'moveEnd' | 'tap' | 'quickPress' | 'quickPressEnd' | 'zoomDoubleTapReset' | 'brush' | 'brushStart' | 'brushCancel' | 'brushEnd';
3
+ export type ChartInteraction = 'pan' | 'panStart' | 'panEnd' | 'zoomPan' | 'zoomPanStart' | 'zoomPanEnd' | 'zoomPinch' | 'zoomPinchStart' | 'zoomPinchEnd' | 'zoomTurnWheel' | 'panTurnWheel' | 'zoomTapAndDrag' | 'zoomTapAndDragStart' | 'zoomTapAndDragEnd' | 'zoomPressAndDrag' | 'zoomPressAndDragStart' | 'zoomPressAndDragEnd' | 'move' | 'moveStart' | 'moveEnd' | 'tap' | 'quickPress' | 'quickPressEnd' | 'zoomDoubleTapReset' | 'brush' | 'brushStart' | 'brushCancel' | 'brushEnd';
4
4
  export type InteractionListenerResult = {
5
5
  cleanup: () => void;
6
6
  };
@@ -8,6 +8,7 @@ export type AddInteractionListener = {
8
8
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'pan' | 'panStart' | 'panEnd' | 'zoomPan' | 'zoomPanStart' | 'zoomPanEnd' | 'brush' | 'brushStart' | 'brushCancel' | 'brushEnd', callback: (event: PanEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
9
9
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'zoomPinch' | 'zoomPinchStart' | 'zoomPinchEnd', callback: (event: PinchEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
10
10
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'zoomTurnWheel', callback: (event: TurnWheelEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
11
+ <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'panTurnWheel', callback: (event: TurnWheelEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
11
12
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'move' | 'moveStart' | 'moveEnd', callback: (event: MoveEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
12
13
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'tap' | 'zoomDoubleTapReset', callback: (event: TapEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
13
14
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'quickPress' | 'quickPressEnd', callback: (event: PressEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
@@ -18,6 +19,7 @@ export type UpdateZoomInteractionListeners = {
18
19
  (interaction: 'zoomPan', options?: Omit<PanGestureOptions<'zoomPan'>, 'name'>): void;
19
20
  (interaction: 'zoomPinch', options?: Omit<PinchGestureOptions<'zoomPinch'>, 'name'>): void;
20
21
  (interaction: 'zoomTurnWheel', options?: Omit<TurnWheelGestureOptions<'zoomTurnWheel'>, 'name'>): void;
22
+ (interaction: 'panTurnWheel', options?: Omit<TurnWheelGestureOptions<'panTurnWheel'>, 'name'>): void;
21
23
  (interaction: 'zoomTapAndDrag', options?: Omit<TapAndDragGestureOptions<'zoomTapAndDrag'>, 'name'>): void;
22
24
  (interaction: 'zoomPressAndDrag', options?: Omit<PressAndDragGestureOptions<'zoomPressAndDrag'>, 'name'>): void;
23
25
  (interaction: 'zoomDoubleTapReset', options?: Omit<TapGestureOptions<'zoomDoubleTapReset'>, 'name'>): void;