@mui/x-charts 9.10.0 → 9.11.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 (207) hide show
  1. package/BarChart/BarChart.js +4 -2
  2. package/BarChart/BarChart.mjs +4 -2
  3. package/BarChart/BarPlot.d.mts +3 -3
  4. package/BarChart/BarPlot.d.ts +3 -3
  5. package/BarChart/BarPlot.js +1 -1
  6. package/BarChart/BarPlot.mjs +1 -1
  7. package/BarChart/BatchBarPlot/BatchBarPlot.d.mts +2 -2
  8. package/BarChart/BatchBarPlot/BatchBarPlot.d.ts +2 -2
  9. package/BarChart/IndividualBarPlot.d.mts +2 -2
  10. package/BarChart/IndividualBarPlot.d.ts +2 -2
  11. package/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.mts +4 -4
  12. package/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.ts +4 -4
  13. package/BarChart/seriesConfig/bar/keyboardFocusHandler.js +3 -1
  14. package/BarChart/seriesConfig/bar/keyboardFocusHandler.mjs +3 -1
  15. package/BarChart/useRegisterItemClickHandlers.d.mts +2 -1
  16. package/BarChart/useRegisterItemClickHandlers.d.ts +2 -1
  17. package/BarChart/useRegisterItemClickHandlers.js +8 -0
  18. package/BarChart/useRegisterItemClickHandlers.mjs +8 -1
  19. package/CHANGELOG.md +224 -0
  20. package/ChartsAxisHighlight/getSampledBandHighlight.d.mts +1 -1
  21. package/ChartsAxisHighlight/getSampledBandHighlight.d.ts +1 -1
  22. package/ChartsAxisHighlight/getSampledBandHighlight.js +15 -3
  23. package/ChartsAxisHighlight/getSampledBandHighlight.mjs +15 -3
  24. package/ChartsContainer/ChartsContainer.js +4 -2
  25. package/ChartsContainer/ChartsContainer.mjs +4 -2
  26. package/ChartsDataProvider/ChartsDataProvider.js +3 -1
  27. package/ChartsDataProvider/ChartsDataProvider.mjs +3 -1
  28. package/ChartsRadialDataProvider/ChartsRadialDataProvider.js +3 -1
  29. package/ChartsRadialDataProvider/ChartsRadialDataProvider.mjs +3 -1
  30. package/ChartsXAxis/useAxisTicksProps.d.mts +101 -101
  31. package/ChartsXAxis/useAxisTicksProps.d.ts +101 -101
  32. package/ChartsYAxis/useAxisTicksProps.d.mts +101 -101
  33. package/ChartsYAxis/useAxisTicksProps.d.ts +101 -101
  34. package/LineChart/AreaPlot.d.mts +3 -2
  35. package/LineChart/AreaPlot.d.ts +3 -2
  36. package/LineChart/AreaPlot.js +8 -2
  37. package/LineChart/AreaPlot.mjs +9 -3
  38. package/LineChart/LineChart.js +2 -1
  39. package/LineChart/LineChart.mjs +2 -1
  40. package/LineChart/LinePlot.d.mts +3 -2
  41. package/LineChart/LinePlot.d.ts +3 -2
  42. package/LineChart/LinePlot.js +2 -2
  43. package/LineChart/LinePlot.mjs +3 -3
  44. package/LineChart/MarkPlot.d.mts +5 -4
  45. package/LineChart/MarkPlot.d.ts +5 -4
  46. package/LineChart/MarkPlot.js +17 -8
  47. package/LineChart/MarkPlot.mjs +17 -8
  48. package/LineChart/seriesConfig/keyboardFocusHandler.js +3 -1
  49. package/LineChart/seriesConfig/keyboardFocusHandler.mjs +3 -1
  50. package/LineChart/useLineItemClickHandler.d.mts +25 -1
  51. package/LineChart/useLineItemClickHandler.d.ts +25 -1
  52. package/LineChart/useLineItemClickHandler.js +48 -1
  53. package/LineChart/useLineItemClickHandler.mjs +47 -1
  54. package/PieChart/PieArcPlot.d.mts +3 -2
  55. package/PieChart/PieArcPlot.d.ts +3 -2
  56. package/PieChart/PieArcPlot.js +16 -1
  57. package/PieChart/PieArcPlot.mjs +16 -1
  58. package/PieChart/PieChart.js +3 -1
  59. package/PieChart/PieChart.mjs +3 -1
  60. package/PieChart/PiePlot.js +1 -1
  61. package/PieChart/PiePlot.mjs +1 -1
  62. package/README.md +1 -11
  63. package/RadarChart/RadarChart.js +3 -1
  64. package/RadarChart/RadarChart.mjs +3 -1
  65. package/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +3 -1
  66. package/RadarChart/RadarSeriesPlot/RadarSeriesArea.mjs +3 -1
  67. package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +4 -1
  68. package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.mjs +4 -1
  69. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.mts +5 -4
  70. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.ts +5 -4
  71. package/RadarChart/RadarSeriesPlot/useRegisterRadarItemActivation.d.mts +15 -0
  72. package/RadarChart/RadarSeriesPlot/useRegisterRadarItemActivation.d.ts +15 -0
  73. package/RadarChart/RadarSeriesPlot/useRegisterRadarItemActivation.js +32 -0
  74. package/RadarChart/RadarSeriesPlot/useRegisterRadarItemActivation.mjs +26 -0
  75. package/RadarChart/seriesConfig/keyboardFocusHandler.js +3 -1
  76. package/RadarChart/seriesConfig/keyboardFocusHandler.mjs +3 -1
  77. package/RadarChart/useRadarChartProps.js +5 -1
  78. package/RadarChart/useRadarChartProps.mjs +5 -1
  79. package/ScatterChart/Scatter.d.mts +3 -2
  80. package/ScatterChart/Scatter.d.ts +3 -2
  81. package/ScatterChart/Scatter.js +10 -1
  82. package/ScatterChart/Scatter.mjs +10 -1
  83. package/ScatterChart/ScatterChart.js +1 -0
  84. package/ScatterChart/ScatterChart.mjs +1 -0
  85. package/ScatterChart/async/ScatterAsync.js +9 -0
  86. package/ScatterChart/async/ScatterAsync.mjs +9 -0
  87. package/SparkLineChart/SparkLineChart.js +2 -1
  88. package/SparkLineChart/SparkLineChart.mjs +2 -1
  89. package/Toolbar/ToolbarButton.js +1 -1
  90. package/Toolbar/ToolbarButton.mjs +1 -1
  91. package/hooks/animation/useAnimatePieArc.js +2 -1
  92. package/hooks/animation/useAnimatePieArc.mjs +2 -1
  93. package/hooks/useFocusedItem.d.mts +1 -1
  94. package/hooks/useFocusedItem.d.ts +1 -1
  95. package/hooks/useItemHighlightStateGetter.d.mts +1 -1
  96. package/hooks/useItemHighlightStateGetter.d.ts +1 -1
  97. package/index.js +1 -1
  98. package/index.mjs +1 -1
  99. package/internals/commonNextFocusItem.d.mts +2 -2
  100. package/internals/commonNextFocusItem.d.ts +2 -2
  101. package/internals/commonNextFocusItem.js +4 -4
  102. package/internals/commonNextFocusItem.mjs +4 -4
  103. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.js +1 -0
  104. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.mjs +1 -0
  105. package/internals/createCommonKeyboardFocusHandler.d.mts +2 -2
  106. package/internals/createCommonKeyboardFocusHandler.d.ts +2 -2
  107. package/internals/createGetBarDimensions.js +10 -5
  108. package/internals/createGetBarDimensions.mjs +10 -5
  109. package/internals/getSampledBucketRegion.d.mts +12 -0
  110. package/internals/getSampledBucketRegion.d.ts +12 -0
  111. package/internals/getSampledBucketRegion.js +23 -0
  112. package/internals/getSampledBucketRegion.mjs +17 -0
  113. package/internals/index.d.mts +1 -0
  114. package/internals/index.d.ts +1 -0
  115. package/internals/index.js +8 -0
  116. package/internals/index.mjs +1 -0
  117. package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.d.mts +8 -1
  118. package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.d.ts +8 -1
  119. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +11 -3
  120. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.mjs +11 -3
  121. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.mts +1 -0
  122. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +1 -0
  123. package/internals/plugins/corePlugins/useChartSeriesConfig/types/getItemWithData.types.d.mts +12 -0
  124. package/internals/plugins/corePlugins/useChartSeriesConfig/types/getItemWithData.types.d.ts +12 -0
  125. package/internals/plugins/corePlugins/useChartSeriesConfig/types/getItemWithData.types.js +5 -0
  126. package/internals/plugins/corePlugins/useChartSeriesConfig/types/getItemWithData.types.mjs +1 -0
  127. package/internals/plugins/corePlugins/useChartSeriesConfig/types/index.d.mts +1 -0
  128. package/internals/plugins/corePlugins/useChartSeriesConfig/types/index.d.ts +1 -0
  129. package/internals/plugins/corePlugins/useChartSeriesConfig/types/index.js +11 -0
  130. package/internals/plugins/corePlugins/useChartSeriesConfig/types/index.mjs +1 -0
  131. package/internals/plugins/corePlugins/useChartSeriesConfig/types/seriesConfig.types.d.mts +6 -0
  132. package/internals/plugins/corePlugins/useChartSeriesConfig/types/seriesConfig.types.d.ts +6 -0
  133. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisClickPayload.d.mts +21 -0
  134. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisClickPayload.d.ts +21 -0
  135. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisClickPayload.js +46 -0
  136. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisClickPayload.mjs +40 -0
  137. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +13 -31
  138. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.mjs +13 -31
  139. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.mts +2 -2
  140. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +2 -2
  141. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.mts +11 -11
  142. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +11 -11
  143. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.mts +4 -4
  144. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +4 -4
  145. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +19 -0
  146. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.mjs +19 -0
  147. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.types.d.mts +5 -3
  148. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.types.d.ts +5 -3
  149. package/internals/plugins/featurePlugins/useChartItemClick/useChartItemClick.js +15 -0
  150. package/internals/plugins/featurePlugins/useChartItemClick/useChartItemClick.mjs +14 -0
  151. package/internals/plugins/featurePlugins/useChartItemClick/useChartItemClick.types.d.mts +5 -2
  152. package/internals/plugins/featurePlugins/useChartItemClick/useChartItemClick.types.d.ts +5 -2
  153. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/index.d.mts +2 -1
  154. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/index.d.ts +2 -1
  155. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/index.js +10 -2
  156. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/index.mjs +2 -1
  157. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/itemActivation.d.mts +13 -0
  158. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/itemActivation.d.ts +13 -0
  159. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/itemActivation.js +39 -0
  160. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/itemActivation.mjs +32 -0
  161. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +47 -7
  162. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.mjs +47 -7
  163. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.mts +3 -0
  164. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +3 -0
  165. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +3 -1
  166. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.mjs +2 -0
  167. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.mts +39 -2
  168. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +39 -2
  169. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/findVisibleDataIndex.d.mts +3 -0
  170. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/findVisibleDataIndex.d.ts +3 -0
  171. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/findVisibleDataIndex.js +3 -0
  172. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/findVisibleDataIndex.mjs +3 -0
  173. package/internals/plugins/featurePlugins/useChartPolarAxis/getPolarAxisClickPayload.d.mts +27 -0
  174. package/internals/plugins/featurePlugins/useChartPolarAxis/getPolarAxisClickPayload.d.ts +27 -0
  175. package/internals/plugins/featurePlugins/useChartPolarAxis/getPolarAxisClickPayload.js +36 -0
  176. package/internals/plugins/featurePlugins/useChartPolarAxis/getPolarAxisClickPayload.mjs +30 -0
  177. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +19 -20
  178. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.mjs +19 -20
  179. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.mts +2 -2
  180. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +2 -2
  181. package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.mts +1 -1
  182. package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +1 -1
  183. package/internals/seriesSelectorOfType.d.mts +4 -4
  184. package/internals/seriesSelectorOfType.d.ts +4 -4
  185. package/internals/snapEndAngleToFullCircle.d.mts +20 -0
  186. package/internals/snapEndAngleToFullCircle.d.ts +20 -0
  187. package/internals/snapEndAngleToFullCircle.js +47 -0
  188. package/internals/snapEndAngleToFullCircle.mjs +41 -0
  189. package/internals/useRegisterItemActivation.d.mts +23 -0
  190. package/internals/useRegisterItemActivation.d.ts +23 -0
  191. package/internals/useRegisterItemActivation.js +53 -0
  192. package/internals/useRegisterItemActivation.mjs +46 -0
  193. package/models/axis.d.mts +1 -1
  194. package/models/axis.d.ts +1 -1
  195. package/models/events.d.mts +11 -0
  196. package/models/events.d.ts +11 -0
  197. package/models/events.js +5 -0
  198. package/models/events.mjs +1 -0
  199. package/models/index.d.mts +1 -0
  200. package/models/index.d.ts +1 -0
  201. package/moduleAugmentation/barChartBatchRendererOnItemClick.d.mts +3 -4
  202. package/moduleAugmentation/barChartBatchRendererOnItemClick.d.ts +3 -4
  203. package/moduleAugmentation/keyboardActivation.d.mts +7 -0
  204. package/moduleAugmentation/keyboardActivation.d.ts +7 -0
  205. package/moduleAugmentation/keyboardActivation.js +8 -0
  206. package/moduleAugmentation/keyboardActivation.mjs +2 -0
  207. package/package.json +19 -5
@@ -12,6 +12,8 @@ var React = _interopRequireWildcard(require("react"));
12
12
  var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
13
13
  var _useChartSeries = require("../../corePlugins/useChartSeries/useChartSeries.selectors");
14
14
  var _useChartSeriesConfig = require("../../corePlugins/useChartSeriesConfig");
15
+ var _itemActivation = require("./itemActivation");
16
+ var _useChartKeyboardNavigation = require("./useChartKeyboardNavigation.selectors");
15
17
  const useChartKeyboardNavigation = ({
16
18
  params,
17
19
  store,
@@ -20,6 +22,20 @@ const useChartKeyboardNavigation = ({
20
22
  const {
21
23
  chartsLayerContainerRef
22
24
  } = instance;
25
+ const activationRegistrationsRef = React.useRef(new Map());
26
+ const nextRegistrationIdRef = React.useRef(0);
27
+ const registerItemActivationHandler = React.useCallback((scope, handler) => {
28
+ const registrationId = nextRegistrationIdRef.current;
29
+ nextRegistrationIdRef.current += 1;
30
+ const registrations = activationRegistrationsRef.current;
31
+ registrations.set(registrationId, {
32
+ scope,
33
+ handler
34
+ });
35
+ return () => {
36
+ registrations.delete(registrationId);
37
+ };
38
+ }, []);
23
39
  React.useEffect(() => {
24
40
  const element = chartsLayerContainerRef.current;
25
41
  if (!element || params.disableKeyboardNavigation) {
@@ -31,12 +47,14 @@ const useChartKeyboardNavigation = ({
31
47
 
32
48
  // Avoid removing focus if we know it is moving to another children in the chart.
33
49
  // This avoid extra computation ot remove/add focus at each keyboard pressed when navigating in the chart.
34
- if (root && next instanceof Node && !root.contains(next)) {
35
- if (store.state.keyboardNavigation.isFocused) {
36
- store.set('keyboardNavigation', (0, _extends2.default)({}, store.state.keyboardNavigation, {
37
- isFocused: false
38
- }));
39
- }
50
+ // A null relatedTarget means focus left to a non-focusable element (clicking outside), so focus is removed.
51
+ if (root && next !== null && root.contains(next)) {
52
+ return;
53
+ }
54
+ if (store.state.keyboardNavigation.isFocused) {
55
+ store.set('keyboardNavigation', (0, _extends2.default)({}, store.state.keyboardNavigation, {
56
+ isFocused: false
57
+ }));
40
58
  }
41
59
  }
42
60
  function restoreFocus() {
@@ -56,6 +74,22 @@ const useChartKeyboardNavigation = ({
56
74
  }));
57
75
  }
58
76
  }
77
+ function activationHandler(event) {
78
+ // Ignore the auto-repeat while the key is held: a pointer click does not repeat either.
79
+ if (event.repeat || !(0, _itemActivation.isItemActivationKey)(event) || !(0, _useChartKeyboardNavigation.selectorChartsIsKeyboardActivationEnabled)(store.state)) {
80
+ return;
81
+ }
82
+ const focusedItem = store.state.keyboardNavigation.item;
83
+ if (focusedItem === null || !store.state.keyboardNavigation.isFocused) {
84
+ return;
85
+ }
86
+ const handler = (0, _itemActivation.findItemActivationHandler)(activationRegistrationsRef.current.values(), focusedItem);
87
+ if (handler === null) {
88
+ return;
89
+ }
90
+ event.preventDefault();
91
+ handler(event, focusedItem);
92
+ }
59
93
  function keyboardHandler(event) {
60
94
  let newFocusedItem = store.state.keyboardNavigation.item;
61
95
  const seriesConfig = (0, _useChartSeriesConfig.selectorChartSeriesConfig)(store.state);
@@ -88,10 +122,12 @@ const useChartKeyboardNavigation = ({
88
122
  }));
89
123
  }
90
124
  }
125
+ element.addEventListener('keydown', activationHandler);
91
126
  element.addEventListener('keydown', keyboardHandler);
92
127
  element.addEventListener('focusout', removeFocus);
93
128
  element.addEventListener('focusin', restoreFocus);
94
129
  return () => {
130
+ element.removeEventListener('keydown', activationHandler);
95
131
  element.removeEventListener('keydown', keyboardHandler);
96
132
  element.removeEventListener('focusout', removeFocus);
97
133
  element.removeEventListener('focusin', restoreFocus);
@@ -102,7 +138,11 @@ const useChartKeyboardNavigation = ({
102
138
  enabled: !params.disableKeyboardNavigation
103
139
  }));
104
140
  }, [store, params.disableKeyboardNavigation]);
105
- return {};
141
+ return {
142
+ instance: {
143
+ registerItemActivationHandler
144
+ }
145
+ };
106
146
  };
107
147
  exports.useChartKeyboardNavigation = useChartKeyboardNavigation;
108
148
  useChartKeyboardNavigation.getInitialState = params => ({
@@ -5,6 +5,8 @@ import * as React from 'react';
5
5
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
6
6
  import { selectorChartDefaultizedSeries } from "../../corePlugins/useChartSeries/useChartSeries.selectors.mjs";
7
7
  import { selectorChartSeriesConfig } from "../../corePlugins/useChartSeriesConfig/index.mjs";
8
+ import { findItemActivationHandler, isItemActivationKey } from "./itemActivation.mjs";
9
+ import { selectorChartsIsKeyboardActivationEnabled } from "./useChartKeyboardNavigation.selectors.mjs";
8
10
  export const useChartKeyboardNavigation = ({
9
11
  params,
10
12
  store,
@@ -13,6 +15,20 @@ export const useChartKeyboardNavigation = ({
13
15
  const {
14
16
  chartsLayerContainerRef
15
17
  } = instance;
18
+ const activationRegistrationsRef = React.useRef(new Map());
19
+ const nextRegistrationIdRef = React.useRef(0);
20
+ const registerItemActivationHandler = React.useCallback((scope, handler) => {
21
+ const registrationId = nextRegistrationIdRef.current;
22
+ nextRegistrationIdRef.current += 1;
23
+ const registrations = activationRegistrationsRef.current;
24
+ registrations.set(registrationId, {
25
+ scope,
26
+ handler
27
+ });
28
+ return () => {
29
+ registrations.delete(registrationId);
30
+ };
31
+ }, []);
16
32
  React.useEffect(() => {
17
33
  const element = chartsLayerContainerRef.current;
18
34
  if (!element || params.disableKeyboardNavigation) {
@@ -24,12 +40,14 @@ export const useChartKeyboardNavigation = ({
24
40
 
25
41
  // Avoid removing focus if we know it is moving to another children in the chart.
26
42
  // This avoid extra computation ot remove/add focus at each keyboard pressed when navigating in the chart.
27
- if (root && next instanceof Node && !root.contains(next)) {
28
- if (store.state.keyboardNavigation.isFocused) {
29
- store.set('keyboardNavigation', _extends({}, store.state.keyboardNavigation, {
30
- isFocused: false
31
- }));
32
- }
43
+ // A null relatedTarget means focus left to a non-focusable element (clicking outside), so focus is removed.
44
+ if (root && next !== null && root.contains(next)) {
45
+ return;
46
+ }
47
+ if (store.state.keyboardNavigation.isFocused) {
48
+ store.set('keyboardNavigation', _extends({}, store.state.keyboardNavigation, {
49
+ isFocused: false
50
+ }));
33
51
  }
34
52
  }
35
53
  function restoreFocus() {
@@ -49,6 +67,22 @@ export const useChartKeyboardNavigation = ({
49
67
  }));
50
68
  }
51
69
  }
70
+ function activationHandler(event) {
71
+ // Ignore the auto-repeat while the key is held: a pointer click does not repeat either.
72
+ if (event.repeat || !isItemActivationKey(event) || !selectorChartsIsKeyboardActivationEnabled(store.state)) {
73
+ return;
74
+ }
75
+ const focusedItem = store.state.keyboardNavigation.item;
76
+ if (focusedItem === null || !store.state.keyboardNavigation.isFocused) {
77
+ return;
78
+ }
79
+ const handler = findItemActivationHandler(activationRegistrationsRef.current.values(), focusedItem);
80
+ if (handler === null) {
81
+ return;
82
+ }
83
+ event.preventDefault();
84
+ handler(event, focusedItem);
85
+ }
52
86
  function keyboardHandler(event) {
53
87
  let newFocusedItem = store.state.keyboardNavigation.item;
54
88
  const seriesConfig = selectorChartSeriesConfig(store.state);
@@ -81,10 +115,12 @@ export const useChartKeyboardNavigation = ({
81
115
  }));
82
116
  }
83
117
  }
118
+ element.addEventListener('keydown', activationHandler);
84
119
  element.addEventListener('keydown', keyboardHandler);
85
120
  element.addEventListener('focusout', removeFocus);
86
121
  element.addEventListener('focusin', restoreFocus);
87
122
  return () => {
123
+ element.removeEventListener('keydown', activationHandler);
88
124
  element.removeEventListener('keydown', keyboardHandler);
89
125
  element.removeEventListener('focusout', removeFocus);
90
126
  element.removeEventListener('focusin', restoreFocus);
@@ -95,7 +131,11 @@ export const useChartKeyboardNavigation = ({
95
131
  enabled: !params.disableKeyboardNavigation
96
132
  }));
97
133
  }, [store, params.disableKeyboardNavigation]);
98
- return {};
134
+ return {
135
+ instance: {
136
+ registerItemActivationHandler
137
+ }
138
+ };
99
139
  };
100
140
  useChartKeyboardNavigation.getInitialState = params => ({
101
141
  keyboardNavigation: {
@@ -20,6 +20,9 @@ export declare const selectorChartsFocusedOrToFocusedItem: (args_0: import("../.
20
20
  export declare const selectorChartsIsKeyboardNavigationEnabled: (args_0: import("../../corePlugins/useChartId/useChartId.types.mjs").UseChartIdState & import("../../corePlugins/useChartSeriesConfig/useChartSeriesConfig.types.mjs").UseChartSeriesConfigState<keyof import("../../../index.mjs").ChartsSeriesConfig> & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.mjs").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.mjs").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.mjs").UseChartSeriesState<keyof import("../../../index.mjs").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.mjs").UseChartAnimationState & import("../../../index.mjs").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.mjs").UseChartKeyboardNavigationState> & {
21
21
  cacheKey: import("../../models/index.mjs").ChartStateCacheKey;
22
22
  }) => boolean;
23
+ export declare const selectorChartsIsKeyboardActivationEnabled: (args_0: import("../../corePlugins/useChartId/useChartId.types.mjs").UseChartIdState & import("../../corePlugins/useChartSeriesConfig/useChartSeriesConfig.types.mjs").UseChartSeriesConfigState<keyof import("../../../index.mjs").ChartsSeriesConfig> & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.mjs").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.mjs").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.mjs").UseChartSeriesState<keyof import("../../../index.mjs").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.mjs").UseChartAnimationState & import("../../../index.mjs").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.mjs").UseChartKeyboardNavigationState> & {
24
+ cacheKey: import("../../models/index.mjs").ChartStateCacheKey;
25
+ }) => boolean;
23
26
  export declare const selectorChartsKeyboardXAxisIndex: (args_0: import("../../corePlugins/useChartId/useChartId.types.mjs").UseChartIdState & import("../../corePlugins/useChartSeriesConfig/useChartSeriesConfig.types.mjs").UseChartSeriesConfigState<keyof import("../../../index.mjs").ChartsSeriesConfig> & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.mjs").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.mjs").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.mjs").UseChartSeriesState<keyof import("../../../index.mjs").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.mjs").UseChartAnimationState & import("../../../index.mjs").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.mjs").UseChartKeyboardNavigationState> & {
24
27
  cacheKey: import("../../models/index.mjs").ChartStateCacheKey;
25
28
  }) => AxisItemIdentifier | undefined;
@@ -20,6 +20,9 @@ export declare const selectorChartsFocusedOrToFocusedItem: (args_0: import("../.
20
20
  export declare const selectorChartsIsKeyboardNavigationEnabled: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartSeriesConfig/useChartSeriesConfig.types.js").UseChartSeriesConfigState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
21
21
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
22
22
  }) => boolean;
23
+ export declare const selectorChartsIsKeyboardActivationEnabled: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartSeriesConfig/useChartSeriesConfig.types.js").UseChartSeriesConfigState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
24
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
25
+ }) => boolean;
23
26
  export declare const selectorChartsKeyboardXAxisIndex: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartSeriesConfig/useChartSeriesConfig.types.js").UseChartSeriesConfigState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
24
27
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
25
28
  }) => AxisItemIdentifier | undefined;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardXAxisIndex = exports.selectorChartsKeyboardItem = exports.selectorChartsItemIsFocused = exports.selectorChartsIsKeyboardNavigationEnabled = exports.selectorChartsHasFocusedItem = exports.selectorChartsFocusedOrToFocusedItem = exports.selectorChartsFocusedItem = void 0;
6
+ exports.selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardXAxisIndex = exports.selectorChartsKeyboardItem = exports.selectorChartsItemIsFocused = exports.selectorChartsIsKeyboardNavigationEnabled = exports.selectorChartsIsKeyboardActivationEnabled = exports.selectorChartsHasFocusedItem = exports.selectorChartsFocusedOrToFocusedItem = exports.selectorChartsFocusedItem = void 0;
7
7
  var _store = require("@mui/x-internals/store");
8
8
  var _fastObjectShallowCompare = require("@mui/x-internals/fastObjectShallowCompare");
9
9
  var _useChartSeries = require("../../corePlugins/useChartSeries");
@@ -20,6 +20,8 @@ const selectorChartsFocusedItem = exports.selectorChartsFocusedItem = (0, _store
20
20
  */
21
21
  const selectorChartsFocusedOrToFocusedItem = exports.selectorChartsFocusedOrToFocusedItem = (0, _store.createSelector)(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item ?? null);
22
22
  const selectorChartsIsKeyboardNavigationEnabled = exports.selectorChartsIsKeyboardNavigationEnabled = (0, _store.createSelector)(selectKeyboardNavigation, keyboardNavigationState => !!keyboardNavigationState?.enabled);
23
+ const selectKeyboardActivationFeature = state => state.experimentalFeatures?.keyboardActivation;
24
+ const selectorChartsIsKeyboardActivationEnabled = exports.selectorChartsIsKeyboardActivationEnabled = (0, _store.createSelector)(selectKeyboardNavigation, selectKeyboardActivationFeature, (keyboardNavigationState, keyboardActivation) => keyboardActivation === true && !!keyboardNavigationState?.enabled);
23
25
 
24
26
  /**
25
27
  * Selectors to override highlight behavior.
@@ -14,6 +14,8 @@ export const selectorChartsFocusedItem = createSelector(selectKeyboardNavigation
14
14
  */
15
15
  export const selectorChartsFocusedOrToFocusedItem = createSelector(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item ?? null);
16
16
  export const selectorChartsIsKeyboardNavigationEnabled = createSelector(selectKeyboardNavigation, keyboardNavigationState => !!keyboardNavigationState?.enabled);
17
+ const selectKeyboardActivationFeature = state => state.experimentalFeatures?.keyboardActivation;
18
+ export const selectorChartsIsKeyboardActivationEnabled = createSelector(selectKeyboardNavigation, selectKeyboardActivationFeature, (keyboardNavigationState, keyboardActivation) => keyboardActivation === true && !!keyboardNavigationState?.enabled);
17
19
 
18
20
  /**
19
21
  * Selectors to override highlight behavior.
@@ -2,9 +2,46 @@ import type { ChartPluginSignature } from "../../models/index.mjs";
2
2
  import type { UseChartInteractionSignature } from "../useChartInteraction/index.mjs";
3
3
  import type { UseChartCartesianAxisSignature } from "../useChartCartesianAxis/index.mjs";
4
4
  import type { UseChartHighlightSignature } from "../useChartHighlight/index.mjs";
5
- import type { FocusedItemIdentifier } from "../../../../models/seriesType/index.mjs";
5
+ import type { FocusedItemIdentifier, SeriesId } from "../../../../models/seriesType/index.mjs";
6
6
  import type { ChartSeriesType } from "../../../../models/seriesType/config.mjs";
7
- export interface UseChartKeyboardNavigationInstance {}
7
+ /**
8
+ * Called when the focused item is activated with the keyboard.
9
+ * @param {KeyboardEvent} event The keyboard event that triggered the activation.
10
+ * @param {FocusedItemIdentifier<ChartSeriesType>} item The activated item.
11
+ */
12
+ export type ItemActivationHandler = (event: KeyboardEvent, item: FocusedItemIdentifier<ChartSeriesType>) => void;
13
+ /**
14
+ * The items a handler covers. An empty scope covers every item.
15
+ */
16
+ export interface ItemActivationScope {
17
+ type?: ChartSeriesType;
18
+ seriesId?: SeriesId;
19
+ /**
20
+ * Breaks ties between handlers covering the same items, highest first.
21
+ * Mirrors pointer hit-testing, where marks sit above lines, and lines above areas.
22
+ * @default 0
23
+ */
24
+ priority?: number;
25
+ /**
26
+ * When set, the handler is a candidate only for items it returns `true` for. Lets a plot decline
27
+ * an item a pointer could not reach — e.g. a line mark that is not rendered — so activation falls
28
+ * through to the next handler.
29
+ * @param {FocusedItemIdentifier<ChartSeriesType>} item The focused item.
30
+ * @returns {boolean} Whether the handler can activate this item.
31
+ */
32
+ canActivate?: (item: FocusedItemIdentifier<ChartSeriesType>) => boolean;
33
+ }
34
+ export interface UseChartKeyboardNavigationInstance {
35
+ /**
36
+ * Registers a handler triggered when the focused item is activated with the keyboard.
37
+ * Only the handler with the most specific matching scope runs, so plots sharing a series
38
+ * do not fire the callback twice.
39
+ * @param {ItemActivationScope} scope The items the handler covers.
40
+ * @param {ItemActivationHandler} handler The handler to call on activation.
41
+ * @returns {() => void} A cleanup function unregistering the handler.
42
+ */
43
+ registerItemActivationHandler: (scope: ItemActivationScope, handler: ItemActivationHandler) => () => void;
44
+ }
8
45
  export interface UseChartKeyboardNavigationState {
9
46
  keyboardNavigation: {
10
47
  /**
@@ -2,9 +2,46 @@ import type { ChartPluginSignature } from "../../models/index.js";
2
2
  import type { UseChartInteractionSignature } from "../useChartInteraction/index.js";
3
3
  import type { UseChartCartesianAxisSignature } from "../useChartCartesianAxis/index.js";
4
4
  import type { UseChartHighlightSignature } from "../useChartHighlight/index.js";
5
- import type { FocusedItemIdentifier } from "../../../../models/seriesType/index.js";
5
+ import type { FocusedItemIdentifier, SeriesId } from "../../../../models/seriesType/index.js";
6
6
  import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
7
- export interface UseChartKeyboardNavigationInstance {}
7
+ /**
8
+ * Called when the focused item is activated with the keyboard.
9
+ * @param {KeyboardEvent} event The keyboard event that triggered the activation.
10
+ * @param {FocusedItemIdentifier<ChartSeriesType>} item The activated item.
11
+ */
12
+ export type ItemActivationHandler = (event: KeyboardEvent, item: FocusedItemIdentifier<ChartSeriesType>) => void;
13
+ /**
14
+ * The items a handler covers. An empty scope covers every item.
15
+ */
16
+ export interface ItemActivationScope {
17
+ type?: ChartSeriesType;
18
+ seriesId?: SeriesId;
19
+ /**
20
+ * Breaks ties between handlers covering the same items, highest first.
21
+ * Mirrors pointer hit-testing, where marks sit above lines, and lines above areas.
22
+ * @default 0
23
+ */
24
+ priority?: number;
25
+ /**
26
+ * When set, the handler is a candidate only for items it returns `true` for. Lets a plot decline
27
+ * an item a pointer could not reach — e.g. a line mark that is not rendered — so activation falls
28
+ * through to the next handler.
29
+ * @param {FocusedItemIdentifier<ChartSeriesType>} item The focused item.
30
+ * @returns {boolean} Whether the handler can activate this item.
31
+ */
32
+ canActivate?: (item: FocusedItemIdentifier<ChartSeriesType>) => boolean;
33
+ }
34
+ export interface UseChartKeyboardNavigationInstance {
35
+ /**
36
+ * Registers a handler triggered when the focused item is activated with the keyboard.
37
+ * Only the handler with the most specific matching scope runs, so plots sharing a series
38
+ * do not fire the callback twice.
39
+ * @param {ItemActivationScope} scope The items the handler covers.
40
+ * @param {ItemActivationHandler} handler The handler to call on activation.
41
+ * @returns {() => void} A cleanup function unregistering the handler.
42
+ */
43
+ registerItemActivationHandler: (scope: ItemActivationScope, handler: ItemActivationHandler) => () => void;
44
+ }
8
45
  export interface UseChartKeyboardNavigationState {
9
46
  keyboardNavigation: {
10
47
  /**
@@ -5,6 +5,9 @@ import type { ProcessedSeries } from "../../../corePlugins/useChartSeries/useCha
5
5
  * Walk forward (or backward) from `startIndex` and return the first dataIndex
6
6
  * whose data point is visible. Returns `null` if every traversed index is hidden.
7
7
  *
8
+ * Shared-axis types (line, bar) opt out of `useCurrentSeriesMaxLength`, so `dataLength`
9
+ * can exceed the focused series length to focus an index with no value.
10
+ *
8
11
  * Series-level hidden flags are filtered upstream (see `getNonEmptySeriesArray`),
9
12
  * so only per-data-point hidden flags are relevant here. Today only Pie sets a
10
13
  * `hidden` flag on individual data items; for other series types the data
@@ -5,6 +5,9 @@ import type { ProcessedSeries } from "../../../corePlugins/useChartSeries/useCha
5
5
  * Walk forward (or backward) from `startIndex` and return the first dataIndex
6
6
  * whose data point is visible. Returns `null` if every traversed index is hidden.
7
7
  *
8
+ * Shared-axis types (line, bar) opt out of `useCurrentSeriesMaxLength`, so `dataLength`
9
+ * can exceed the focused series length to focus an index with no value.
10
+ *
8
11
  * Series-level hidden flags are filtered upstream (see `getNonEmptySeriesArray`),
9
12
  * so only per-data-point hidden flags are relevant here. Today only Pie sets a
10
13
  * `hidden` flag on individual data items; for other series types the data
@@ -8,6 +8,9 @@ exports.findVisibleDataIndex = findVisibleDataIndex;
8
8
  * Walk forward (or backward) from `startIndex` and return the first dataIndex
9
9
  * whose data point is visible. Returns `null` if every traversed index is hidden.
10
10
  *
11
+ * Shared-axis types (line, bar) opt out of `useCurrentSeriesMaxLength`, so `dataLength`
12
+ * can exceed the focused series length to focus an index with no value.
13
+ *
11
14
  * Series-level hidden flags are filtered upstream (see `getNonEmptySeriesArray`),
12
15
  * so only per-data-point hidden flags are relevant here. Today only Pie sets a
13
16
  * `hidden` flag on individual data items; for other series types the data
@@ -2,6 +2,9 @@
2
2
  * Walk forward (or backward) from `startIndex` and return the first dataIndex
3
3
  * whose data point is visible. Returns `null` if every traversed index is hidden.
4
4
  *
5
+ * Shared-axis types (line, bar) opt out of `useCurrentSeriesMaxLength`, so `dataLength`
6
+ * can exceed the focused series length to focus an index with no value.
7
+ *
5
8
  * Series-level hidden flags are filtered upstream (see `getNonEmptySeriesArray`),
6
9
  * so only per-data-point hidden flags are relevant here. Today only Pie sets a
7
10
  * `hidden` flag on individual data items; for other series types the data
@@ -0,0 +1,27 @@
1
+ import type { ChartsAxisData } from "../../../../models/axis.mjs";
2
+ import type { ProcessedSeries } from "../../corePlugins/useChartSeries/index.mjs";
3
+ import type { ChartSeriesType } from "../../../../models/seriesType/config.mjs";
4
+ type PolarAxes = {
5
+ axis: Record<string, {
6
+ data?: readonly any[];
7
+ }>;
8
+ axisIds: string[];
9
+ };
10
+ /**
11
+ * Builds the `onAxisClick` payload for a data index on a polar axis.
12
+ * Returns `null` when the axis has no value at this index.
13
+ */
14
+ export declare function getPolarAxisClickPayload({
15
+ dataIndex,
16
+ isRotationAxis,
17
+ rotationAxes,
18
+ radiusAxes,
19
+ processedSeries
20
+ }: {
21
+ dataIndex: number;
22
+ isRotationAxis: boolean;
23
+ rotationAxes: PolarAxes;
24
+ radiusAxes: PolarAxes;
25
+ processedSeries: ProcessedSeries<ChartSeriesType>;
26
+ }): ChartsAxisData | null;
27
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { ChartsAxisData } from "../../../../models/axis.js";
2
+ import type { ProcessedSeries } from "../../corePlugins/useChartSeries/index.js";
3
+ import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
4
+ type PolarAxes = {
5
+ axis: Record<string, {
6
+ data?: readonly any[];
7
+ }>;
8
+ axisIds: string[];
9
+ };
10
+ /**
11
+ * Builds the `onAxisClick` payload for a data index on a polar axis.
12
+ * Returns `null` when the axis has no value at this index.
13
+ */
14
+ export declare function getPolarAxisClickPayload({
15
+ dataIndex,
16
+ isRotationAxis,
17
+ rotationAxes,
18
+ radiusAxes,
19
+ processedSeries
20
+ }: {
21
+ dataIndex: number;
22
+ isRotationAxis: boolean;
23
+ rotationAxes: PolarAxes;
24
+ radiusAxes: PolarAxes;
25
+ processedSeries: ProcessedSeries<ChartSeriesType>;
26
+ }): ChartsAxisData | null;
27
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPolarAxisClickPayload = getPolarAxisClickPayload;
7
+ var _isPolar = require("../../../isPolar");
8
+ /**
9
+ * Builds the `onAxisClick` payload for a data index on a polar axis.
10
+ * Returns `null` when the axis has no value at this index.
11
+ */
12
+ function getPolarAxisClickPayload({
13
+ dataIndex,
14
+ isRotationAxis,
15
+ rotationAxes,
16
+ radiusAxes,
17
+ processedSeries
18
+ }) {
19
+ const axes = isRotationAxis ? rotationAxes : radiusAxes;
20
+ const axisValue = axes.axis[axes.axisIds[0]]?.data?.[dataIndex];
21
+ if (axisValue === undefined) {
22
+ return null;
23
+ }
24
+ const seriesValues = {};
25
+ Object.keys(processedSeries).filter(_isPolar.isPolarSeriesType).forEach(seriesType => {
26
+ processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
27
+ const seriesItem = processedSeries[seriesType].series[seriesId];
28
+ seriesValues[seriesId] = seriesItem.data[dataIndex];
29
+ });
30
+ });
31
+ return {
32
+ dataIndex,
33
+ axisValue,
34
+ seriesValues
35
+ };
36
+ }
@@ -0,0 +1,30 @@
1
+ import { isPolarSeriesType } from "../../../isPolar.mjs";
2
+ /**
3
+ * Builds the `onAxisClick` payload for a data index on a polar axis.
4
+ * Returns `null` when the axis has no value at this index.
5
+ */
6
+ export function getPolarAxisClickPayload({
7
+ dataIndex,
8
+ isRotationAxis,
9
+ rotationAxes,
10
+ radiusAxes,
11
+ processedSeries
12
+ }) {
13
+ const axes = isRotationAxis ? rotationAxes : radiusAxes;
14
+ const axisValue = axes.axis[axes.axisIds[0]]?.data?.[dataIndex];
15
+ if (axisValue === undefined) {
16
+ return null;
17
+ }
18
+ const seriesValues = {};
19
+ Object.keys(processedSeries).filter(isPolarSeriesType).forEach(seriesType => {
20
+ processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
21
+ const seriesItem = processedSeries[seriesType].series[seriesId];
22
+ seriesValues[seriesId] = seriesItem.data[dataIndex];
23
+ });
24
+ });
25
+ return {
26
+ dataIndex,
27
+ axisValue,
28
+ seriesValues
29
+ };
30
+ }
@@ -19,7 +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
+ var _getPolarAxisClickPayload = require("./getPolarAxisClickPayload");
23
23
  const useChartPolarAxis = ({
24
24
  params,
25
25
  store,
@@ -174,34 +174,33 @@ const useChartPolarAxis = ({
174
174
  return () => {};
175
175
  }
176
176
  const axisClickHandler = instance.addInteractionListener('tap', event => {
177
- let dataIndex = null;
178
- let isRotationAxis = false;
179
177
  const svgPoint = (0, _getChartPoint.getChartPoint)(element, event.detail.srcEvent);
180
178
  const rotation = (0, _coordinateTransformation.generateSvg2rotation)(center)(svgPoint.x, svgPoint.y);
181
179
  const rotationIndex = (0, _getAxisIndex.getRotationAxisIndex)(rotationAxisWithScale[usedRotationAxisId], rotation);
182
180
  const radius = (0, _coordinateTransformation.generateSvg2radius)(center)(svgPoint.x, svgPoint.y);
183
181
  const radiusIndex = (0, _getAxisIndex.getRadiusAxisIndex)(radiusAxisWithScale[usedRadiusAxisId], radius);
184
- isRotationAxis = rotationIndex !== -1;
185
- dataIndex = isRotationAxis ? rotationIndex : radiusIndex;
186
- const USED_AXIS_ID = isRotationAxis ? usedRotationAxisId : usedRadiusAxisId;
187
- if (dataIndex == null || dataIndex === -1) {
182
+ const isRotationAxis = rotationIndex !== -1;
183
+ const dataIndex = isRotationAxis ? rotationIndex : radiusIndex;
184
+ if (dataIndex === -1) {
188
185
  return;
189
186
  }
190
-
191
- // The .data exist because otherwise the dataIndex would be null or -1.
192
- const axisValue = (isRotationAxis ? rotationAxisWithScale : radiusAxisWithScale)[USED_AXIS_ID].data[dataIndex];
193
- const seriesValues = {};
194
- Object.keys(processedSeries).filter(_isPolar.isPolarSeriesType).forEach(seriesType => {
195
- processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
196
- const seriesItem = processedSeries[seriesType].series[seriesId];
197
- seriesValues[seriesId] = seriesItem.data[dataIndex];
198
- });
199
- });
200
- onAxisClick(event.detail.srcEvent, {
187
+ const payload = (0, _getPolarAxisClickPayload.getPolarAxisClickPayload)({
201
188
  dataIndex,
202
- axisValue,
203
- seriesValues
189
+ isRotationAxis,
190
+ rotationAxes: {
191
+ axis: rotationAxisWithScale,
192
+ axisIds: [usedRotationAxisId]
193
+ },
194
+ radiusAxes: {
195
+ axis: radiusAxisWithScale,
196
+ axisIds: [usedRadiusAxisId]
197
+ },
198
+ processedSeries
204
199
  });
200
+ if (payload === null) {
201
+ return;
202
+ }
203
+ onAxisClick(event.detail.srcEvent, payload);
205
204
  });
206
205
  return () => {
207
206
  axisClickHandler.cleanup();