@mui/x-charts 8.22.1 → 8.24.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 (354) hide show
  1. package/BarChart/BarChart.js +39 -0
  2. package/BarChart/BarChart.plugins.d.ts +2 -1
  3. package/BarChart/BarChart.plugins.js +2 -1
  4. package/BarChart/BarElement.js +1 -1
  5. package/BarChart/BarLabel/BarLabel.d.ts +2 -0
  6. package/BarChart/BarLabel/BarLabel.js +8 -3
  7. package/BarChart/BarLabel/BarLabelItem.d.ts +2 -0
  8. package/BarChart/BarLabel/BarLabelItem.js +4 -2
  9. package/BarChart/BarPlot.d.ts +12 -2
  10. package/BarChart/BarPlot.js +29 -86
  11. package/BarChart/BatchBarPlot/BarGroup.d.ts +15 -0
  12. package/BarChart/BatchBarPlot/BarGroup.js +142 -0
  13. package/BarChart/BatchBarPlot/BatchBarPlot.d.ts +12 -0
  14. package/BarChart/BatchBarPlot/BatchBarPlot.js +140 -0
  15. package/BarChart/BatchBarPlot/index.d.ts +1 -0
  16. package/BarChart/BatchBarPlot/index.js +12 -0
  17. package/BarChart/BatchBarPlot/useCreateBarPaths.d.ts +8 -0
  18. package/BarChart/BatchBarPlot/useCreateBarPaths.js +53 -0
  19. package/BarChart/FocusedBar.js +6 -2
  20. package/BarChart/IndividualBarPlot.d.ts +21 -0
  21. package/BarChart/IndividualBarPlot.js +106 -0
  22. package/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.ts +1 -1
  23. package/BarChart/seriesConfig/bar/keyboardFocusHandler.d.ts +3 -0
  24. package/BarChart/seriesConfig/bar/keyboardFocusHandler.js +23 -0
  25. package/BarChart/seriesConfig/bar/legend.js +1 -0
  26. package/BarChart/seriesConfig/bar/seriesProcessor.js +2 -2
  27. package/BarChart/seriesConfig/index.js +5 -1
  28. package/BarChart/types.d.ts +2 -0
  29. package/BarChart/useBarChartProps.d.ts +6 -2
  30. package/BarChart/useBarChartProps.js +4 -2
  31. package/BarChart/useBarPlotData.d.ts +1 -1
  32. package/BarChart/useBarPlotData.js +23 -4
  33. package/BarChart/useRegisterItemClickHandlers.d.ts +6 -0
  34. package/BarChart/useRegisterItemClickHandlers.js +72 -0
  35. package/CHANGELOG.md +211 -0
  36. package/ChartContainer/ChartContainer.js +34 -0
  37. package/ChartContainer/useChartContainerProps.js +6 -2
  38. package/ChartsLegend/ChartsLegend.js +2 -2
  39. package/ChartsLegend/legendContext.types.d.ts +12 -0
  40. package/ChartsLegend/onClickContextBuilder.js +2 -1
  41. package/ChartsOverlay/ChartsLoadingOverlay.js +4 -1
  42. package/ChartsOverlay/ChartsNoDataOverlay.js +4 -1
  43. package/ChartsReferenceLine/common.d.ts +1 -1
  44. package/ChartsReferenceLine/common.js +4 -1
  45. package/ChartsTooltip/ChartsTooltipContainer.js +25 -21
  46. package/Gauge/GaugeContainer.js +4 -1
  47. package/LineChart/AnimatedLine.js +7 -3
  48. package/LineChart/AppearingMask.js +4 -1
  49. package/LineChart/CircleMarkElement.d.ts +5 -0
  50. package/LineChart/CircleMarkElement.js +13 -5
  51. package/LineChart/FocusedLineMark.js +6 -2
  52. package/LineChart/LineChart.js +30 -0
  53. package/LineChart/LineChart.plugins.d.ts +2 -1
  54. package/LineChart/LineChart.plugins.js +2 -1
  55. package/LineChart/LineElement.d.ts +4 -0
  56. package/LineChart/LineElement.js +7 -3
  57. package/LineChart/MarkElement.d.ts +5 -0
  58. package/LineChart/MarkElement.js +17 -10
  59. package/LineChart/markElementClasses.d.ts +0 -1
  60. package/LineChart/seriesConfig/index.js +5 -1
  61. package/LineChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  62. package/LineChart/seriesConfig/keyboardFocusHandler.js +23 -0
  63. package/LineChart/seriesConfig/legend.js +1 -0
  64. package/LineChart/seriesConfig/seriesProcessor.js +2 -2
  65. package/PieChart/FocusedPieArc.js +6 -3
  66. package/PieChart/PieArcLabel.d.ts +2 -0
  67. package/PieChart/PieArcLabel.js +5 -2
  68. package/PieChart/PieChart.js +35 -5
  69. package/PieChart/PieChart.plugins.d.ts +2 -1
  70. package/PieChart/PieChart.plugins.js +2 -1
  71. package/PieChart/dataTransform/useTransformData.js +1 -1
  72. package/PieChart/seriesConfig/index.js +5 -1
  73. package/PieChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  74. package/PieChart/seriesConfig/keyboardFocusHandler.js +23 -0
  75. package/PieChart/seriesConfig/legend.js +6 -3
  76. package/RadarChart/RadarChart.js +30 -0
  77. package/RadarChart/RadarChart.plugins.d.ts +3 -2
  78. package/RadarChart/RadarChart.plugins.js +2 -1
  79. package/RadarChart/seriesConfig/index.js +3 -1
  80. package/RadarChart/seriesConfig/legend.js +1 -0
  81. package/ScatterChart/BatchScatter.js +8 -14
  82. package/ScatterChart/FocusedScatterMark.js +1 -1
  83. package/ScatterChart/ScatterChart.js +30 -0
  84. package/ScatterChart/ScatterChart.plugins.d.ts +2 -1
  85. package/ScatterChart/ScatterChart.plugins.js +2 -1
  86. package/ScatterChart/seriesConfig/index.js +5 -1
  87. package/ScatterChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  88. package/ScatterChart/seriesConfig/keyboardFocusHandler.js +23 -0
  89. package/ScatterChart/seriesConfig/legend.js +1 -0
  90. package/SparkLineChart/SparkLineChart.js +46 -0
  91. package/esm/BarChart/BarChart.js +39 -0
  92. package/esm/BarChart/BarChart.plugins.d.ts +2 -1
  93. package/esm/BarChart/BarChart.plugins.js +2 -1
  94. package/esm/BarChart/BarElement.js +1 -1
  95. package/esm/BarChart/BarLabel/BarLabel.d.ts +2 -0
  96. package/esm/BarChart/BarLabel/BarLabel.js +8 -3
  97. package/esm/BarChart/BarLabel/BarLabelItem.d.ts +2 -0
  98. package/esm/BarChart/BarLabel/BarLabelItem.js +4 -2
  99. package/esm/BarChart/BarPlot.d.ts +12 -2
  100. package/esm/BarChart/BarPlot.js +29 -86
  101. package/esm/BarChart/BatchBarPlot/BarGroup.d.ts +15 -0
  102. package/esm/BarChart/BatchBarPlot/BarGroup.js +134 -0
  103. package/esm/BarChart/BatchBarPlot/BatchBarPlot.d.ts +12 -0
  104. package/esm/BarChart/BatchBarPlot/BatchBarPlot.js +133 -0
  105. package/esm/BarChart/BatchBarPlot/index.d.ts +1 -0
  106. package/esm/BarChart/BatchBarPlot/index.js +1 -0
  107. package/esm/BarChart/BatchBarPlot/useCreateBarPaths.d.ts +8 -0
  108. package/esm/BarChart/BatchBarPlot/useCreateBarPaths.js +46 -0
  109. package/esm/BarChart/FocusedBar.js +6 -2
  110. package/esm/BarChart/IndividualBarPlot.d.ts +21 -0
  111. package/esm/BarChart/IndividualBarPlot.js +98 -0
  112. package/esm/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.ts +1 -1
  113. package/esm/BarChart/seriesConfig/bar/keyboardFocusHandler.d.ts +3 -0
  114. package/esm/BarChart/seriesConfig/bar/keyboardFocusHandler.js +17 -0
  115. package/esm/BarChart/seriesConfig/bar/legend.js +1 -0
  116. package/esm/BarChart/seriesConfig/bar/seriesProcessor.js +1 -1
  117. package/esm/BarChart/seriesConfig/index.js +5 -1
  118. package/esm/BarChart/types.d.ts +2 -0
  119. package/esm/BarChart/useBarChartProps.d.ts +6 -2
  120. package/esm/BarChart/useBarChartProps.js +4 -3
  121. package/esm/BarChart/useBarPlotData.d.ts +1 -1
  122. package/esm/BarChart/useBarPlotData.js +20 -1
  123. package/esm/BarChart/useRegisterItemClickHandlers.d.ts +6 -0
  124. package/esm/BarChart/useRegisterItemClickHandlers.js +67 -0
  125. package/esm/ChartContainer/ChartContainer.js +34 -0
  126. package/esm/ChartContainer/useChartContainerProps.js +6 -2
  127. package/esm/ChartsLegend/ChartsLegend.js +2 -2
  128. package/esm/ChartsLegend/legendContext.types.d.ts +12 -0
  129. package/esm/ChartsLegend/onClickContextBuilder.js +2 -1
  130. package/esm/ChartsOverlay/ChartsLoadingOverlay.js +4 -1
  131. package/esm/ChartsOverlay/ChartsNoDataOverlay.js +4 -1
  132. package/esm/ChartsReferenceLine/common.d.ts +1 -1
  133. package/esm/ChartsReferenceLine/common.js +4 -1
  134. package/esm/ChartsTooltip/ChartsTooltipContainer.js +26 -22
  135. package/esm/Gauge/GaugeContainer.js +4 -1
  136. package/esm/LineChart/AnimatedLine.js +7 -3
  137. package/esm/LineChart/AppearingMask.js +4 -1
  138. package/esm/LineChart/CircleMarkElement.d.ts +5 -0
  139. package/esm/LineChart/CircleMarkElement.js +13 -5
  140. package/esm/LineChart/FocusedLineMark.js +6 -2
  141. package/esm/LineChart/LineChart.js +30 -0
  142. package/esm/LineChart/LineChart.plugins.d.ts +2 -1
  143. package/esm/LineChart/LineChart.plugins.js +2 -1
  144. package/esm/LineChart/LineElement.d.ts +4 -0
  145. package/esm/LineChart/LineElement.js +7 -3
  146. package/esm/LineChart/MarkElement.d.ts +5 -0
  147. package/esm/LineChart/MarkElement.js +17 -10
  148. package/esm/LineChart/markElementClasses.d.ts +0 -1
  149. package/esm/LineChart/seriesConfig/index.js +5 -1
  150. package/esm/LineChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  151. package/esm/LineChart/seriesConfig/keyboardFocusHandler.js +17 -0
  152. package/esm/LineChart/seriesConfig/legend.js +1 -0
  153. package/esm/LineChart/seriesConfig/seriesProcessor.js +1 -1
  154. package/esm/PieChart/FocusedPieArc.js +5 -2
  155. package/esm/PieChart/PieArcLabel.d.ts +2 -0
  156. package/esm/PieChart/PieArcLabel.js +5 -2
  157. package/esm/PieChart/PieChart.js +35 -5
  158. package/esm/PieChart/PieChart.plugins.d.ts +2 -1
  159. package/esm/PieChart/PieChart.plugins.js +2 -1
  160. package/esm/PieChart/dataTransform/useTransformData.js +1 -1
  161. package/esm/PieChart/seriesConfig/index.js +5 -1
  162. package/esm/PieChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  163. package/esm/PieChart/seriesConfig/keyboardFocusHandler.js +17 -0
  164. package/esm/PieChart/seriesConfig/legend.js +6 -3
  165. package/esm/RadarChart/RadarChart.js +30 -0
  166. package/esm/RadarChart/RadarChart.plugins.d.ts +3 -2
  167. package/esm/RadarChart/RadarChart.plugins.js +2 -1
  168. package/esm/RadarChart/seriesConfig/index.js +3 -1
  169. package/esm/RadarChart/seriesConfig/legend.js +1 -0
  170. package/esm/ScatterChart/BatchScatter.js +5 -11
  171. package/esm/ScatterChart/FocusedScatterMark.js +1 -1
  172. package/esm/ScatterChart/ScatterChart.js +30 -0
  173. package/esm/ScatterChart/ScatterChart.plugins.d.ts +2 -1
  174. package/esm/ScatterChart/ScatterChart.plugins.js +2 -1
  175. package/esm/ScatterChart/seriesConfig/index.js +5 -1
  176. package/esm/ScatterChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  177. package/esm/ScatterChart/seriesConfig/keyboardFocusHandler.js +17 -0
  178. package/esm/ScatterChart/seriesConfig/legend.js +1 -0
  179. package/esm/SparkLineChart/SparkLineChart.js +46 -0
  180. package/esm/hooks/useFocusedItem.d.ts +1 -12
  181. package/esm/hooks/useFocusedItem.js +3 -10
  182. package/esm/hooks/useIsItemFocused.d.ts +4 -3
  183. package/esm/hooks/useIsItemFocused.js +1 -1
  184. package/esm/hooks/useIsItemFocusedGetter.d.ts +3 -2
  185. package/esm/hooks/useIsItemFocusedGetter.js +2 -1
  186. package/esm/index.js +1 -1
  187. package/esm/internals/appendAtKey.d.ts +8 -0
  188. package/esm/internals/appendAtKey.js +17 -0
  189. package/esm/internals/commonNextFocusItem.d.ts +14 -0
  190. package/esm/internals/commonNextFocusItem.js +88 -0
  191. package/esm/internals/getBarDimensions.d.ts +1 -2
  192. package/esm/internals/identifierSerializer.d.ts +9 -0
  193. package/esm/internals/identifierSerializer.js +6 -0
  194. package/esm/internals/index.d.ts +7 -3
  195. package/esm/internals/index.js +7 -3
  196. package/esm/internals/invertScale.d.ts +6 -2
  197. package/esm/internals/invertScale.js +9 -1
  198. package/esm/internals/plugins/allPlugins.d.ts +4 -3
  199. package/esm/internals/plugins/allPlugins.js +2 -1
  200. package/esm/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.d.ts +14 -0
  201. package/esm/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.js +18 -0
  202. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +8 -1
  203. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +12 -1
  204. package/esm/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.d.ts +11 -0
  205. package/esm/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +74 -0
  206. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +20 -3
  207. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -3
  208. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +4 -0
  209. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +83 -0
  210. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.d.ts +13 -0
  211. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.js +1 -0
  212. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.d.ts +2 -2
  213. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +12 -105
  214. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +5 -31
  215. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +9 -15
  216. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +6 -21
  217. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.d.ts +3 -0
  218. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.js +6 -0
  219. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.d.ts +15 -0
  220. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +18 -0
  221. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.d.ts +7 -0
  222. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.js +9 -0
  223. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.d.ts +11 -0
  224. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +18 -0
  225. package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +2 -10
  226. package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.js +2 -2
  227. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/index.d.ts +3 -0
  228. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/index.js +3 -0
  229. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.d.ts +4 -0
  230. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.js +5 -0
  231. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.d.ts +3 -0
  232. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.js +78 -0
  233. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.d.ts +16 -0
  234. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.js +19 -0
  235. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.d.ts +90 -0
  236. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.js +1 -0
  237. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.d.ts +4 -0
  238. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.js +11 -0
  239. package/esm/internals/plugins/models/seriesConfig/identifierSerializer.types.d.ts +2 -0
  240. package/esm/internals/plugins/models/seriesConfig/identifierSerializer.types.js +1 -0
  241. package/esm/internals/plugins/models/seriesConfig/index.d.ts +2 -1
  242. package/esm/internals/plugins/models/seriesConfig/index.js +2 -1
  243. package/esm/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +9 -0
  244. package/esm/internals/plugins/models/seriesConfig/seriesProcessor.types.d.ts +1 -1
  245. package/esm/internals/seriesHasData.d.ts +4 -0
  246. package/esm/internals/seriesHasData.js +8 -0
  247. package/esm/internals/stacking/index.d.ts +1 -0
  248. package/esm/internals/stacking/index.js +1 -0
  249. package/esm/internals/stacking/offset/index.d.ts +1 -0
  250. package/esm/internals/stacking/offset/index.js +1 -0
  251. package/esm/internals/stacking/offset/offsetDiverging.d.ts +8 -0
  252. package/esm/internals/stacking/offset/offsetDiverging.js +47 -0
  253. package/esm/internals/{stackSeries.d.ts → stacking/stackSeries.d.ts} +8 -8
  254. package/esm/internals/{stackSeries.js → stacking/stackSeries.js} +8 -6
  255. package/esm/models/axis.d.ts +5 -4
  256. package/esm/models/featureFlags.d.ts +1 -0
  257. package/esm/models/featureFlags.js +1 -0
  258. package/esm/models/index.d.ts +1 -0
  259. package/esm/models/index.js +1 -0
  260. package/esm/models/seriesType/index.d.ts +3 -1
  261. package/esm/moduleAugmentation/barChartBatchRendererOnItemClick.d.ts +13 -0
  262. package/esm/moduleAugmentation/barChartBatchRendererOnItemClick.js +1 -0
  263. package/hooks/useFocusedItem.d.ts +1 -12
  264. package/hooks/useFocusedItem.js +1 -10
  265. package/hooks/useIsItemFocused.d.ts +4 -3
  266. package/hooks/useIsItemFocused.js +1 -1
  267. package/hooks/useIsItemFocusedGetter.d.ts +3 -2
  268. package/hooks/useIsItemFocusedGetter.js +2 -1
  269. package/index.js +1 -1
  270. package/internals/appendAtKey.d.ts +8 -0
  271. package/internals/appendAtKey.js +23 -0
  272. package/internals/commonNextFocusItem.d.ts +14 -0
  273. package/internals/commonNextFocusItem.js +97 -0
  274. package/internals/getBarDimensions.d.ts +1 -2
  275. package/internals/identifierSerializer.d.ts +9 -0
  276. package/internals/identifierSerializer.js +16 -0
  277. package/internals/index.d.ts +7 -3
  278. package/internals/index.js +55 -11
  279. package/internals/invertScale.d.ts +6 -2
  280. package/internals/invertScale.js +10 -1
  281. package/internals/plugins/allPlugins.d.ts +4 -3
  282. package/internals/plugins/allPlugins.js +2 -1
  283. package/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.d.ts +14 -0
  284. package/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.js +25 -0
  285. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +8 -1
  286. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +12 -1
  287. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.d.ts +11 -0
  288. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +81 -0
  289. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +20 -3
  290. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -3
  291. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +4 -0
  292. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +89 -0
  293. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.d.ts +13 -0
  294. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.js +5 -0
  295. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.d.ts +2 -2
  296. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +11 -104
  297. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +5 -31
  298. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +10 -16
  299. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +6 -21
  300. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.d.ts +3 -0
  301. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.js +12 -0
  302. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.d.ts +15 -0
  303. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +23 -0
  304. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.d.ts +7 -0
  305. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.js +15 -0
  306. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.d.ts +11 -0
  307. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +23 -0
  308. package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +2 -10
  309. package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.js +1 -1
  310. package/internals/plugins/featurePlugins/useChartVisibilityManager/index.d.ts +3 -0
  311. package/internals/plugins/featurePlugins/useChartVisibilityManager/index.js +39 -0
  312. package/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.d.ts +4 -0
  313. package/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.js +12 -0
  314. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.d.ts +3 -0
  315. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.js +85 -0
  316. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.d.ts +16 -0
  317. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.js +25 -0
  318. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.d.ts +90 -0
  319. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.js +5 -0
  320. package/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.d.ts +4 -0
  321. package/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.js +18 -0
  322. package/internals/plugins/models/seriesConfig/identifierSerializer.types.d.ts +2 -0
  323. package/internals/plugins/models/seriesConfig/identifierSerializer.types.js +5 -0
  324. package/internals/plugins/models/seriesConfig/index.d.ts +2 -1
  325. package/internals/plugins/models/seriesConfig/index.js +11 -0
  326. package/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +9 -0
  327. package/internals/plugins/models/seriesConfig/seriesProcessor.types.d.ts +1 -1
  328. package/internals/seriesHasData.d.ts +4 -0
  329. package/internals/seriesHasData.js +14 -0
  330. package/internals/stacking/index.d.ts +1 -0
  331. package/internals/stacking/index.js +16 -0
  332. package/internals/stacking/offset/index.d.ts +1 -0
  333. package/internals/stacking/offset/index.js +16 -0
  334. package/internals/stacking/offset/offsetDiverging.d.ts +8 -0
  335. package/internals/stacking/offset/offsetDiverging.js +53 -0
  336. package/internals/{stackSeries.d.ts → stacking/stackSeries.d.ts} +8 -8
  337. package/internals/{stackSeries.js → stacking/stackSeries.js} +3 -1
  338. package/models/axis.d.ts +5 -4
  339. package/models/featureFlags.d.ts +1 -0
  340. package/models/featureFlags.js +5 -0
  341. package/models/index.d.ts +1 -0
  342. package/models/index.js +11 -0
  343. package/models/seriesType/index.d.ts +3 -1
  344. package/moduleAugmentation/barChartBatchRendererOnItemClick.d.ts +13 -0
  345. package/moduleAugmentation/barChartBatchRendererOnItemClick.js +5 -0
  346. package/package.json +14 -4
  347. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.d.ts +0 -3
  348. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.js +0 -4
  349. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.d.ts +0 -21
  350. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.js +0 -92
  351. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.d.ts +0 -3
  352. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.js +0 -10
  353. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.d.ts +0 -21
  354. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.js +0 -99
@@ -1,8 +1,16 @@
1
1
  import { isOrdinalScale } from "./scaleGuards.js";
2
2
  export function invertScale(scale, data, value) {
3
3
  if (isOrdinalScale(scale)) {
4
- const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
4
+ const dataIndex = getDataIndexForOrdinalScaleValue(scale, value);
5
5
  return data[dataIndex];
6
6
  }
7
7
  return scale.invert(value);
8
+ }
9
+
10
+ /**
11
+ * Get the data index for a given value on an ordinal scale.
12
+ */
13
+ export function getDataIndexForOrdinalScaleValue(scale, value) {
14
+ const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
15
+ return dataIndex;
8
16
  }
@@ -7,7 +7,8 @@ import { type UseChartPolarAxisSignature } from "./featurePlugins/useChartPolarA
7
7
  import { type UseChartClosestPointSignature } from "./featurePlugins/useChartClosestPoint/index.js";
8
8
  import { type UseChartZAxisSignature } from "./featurePlugins/useChartZAxis/index.js";
9
9
  import { type UseChartBrushSignature } from "./featurePlugins/useChartBrush/index.js";
10
+ import { type UseChartVisibilityManagerSignature } from "./featurePlugins/useChartVisibilityManager/index.js";
10
11
  import { type UseChartTooltipSignature } from "./featurePlugins/useChartTooltip/index.js";
11
- export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartBrushSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature, UseChartTooltipSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
12
- export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartBrushSignature, UseChartTooltipSignature, UseChartInteractionSignature, UseChartCartesianAxisSignature<TSeries>, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
13
- export declare const DEFAULT_PLUGINS: readonly [import("./models/index.js").ChartPlugin<UseChartZAxisSignature>, import("./models/index.js").ChartPlugin<UseChartBrushSignature>, import("./models/index.js").ChartPlugin<UseChartTooltipSignature>, import("./models/index.js").ChartPlugin<UseChartInteractionSignature>, import("./models/index.js").ChartPlugin<UseChartCartesianAxisSignature<any>>, import("./models/index.js").ChartPlugin<UseChartHighlightSignature>, import("./models/index.js").ChartPlugin<UseChartClosestPointSignature>, import("./models/index.js").ChartPlugin<UseChartKeyboardNavigationSignature>];
12
+ export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartBrushSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature, UseChartTooltipSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartVisibilityManagerSignature<TSeries>, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
13
+ export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartBrushSignature, UseChartTooltipSignature, UseChartInteractionSignature, UseChartCartesianAxisSignature<TSeries>, UseChartHighlightSignature, UseChartVisibilityManagerSignature<TSeries>, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
14
+ export declare const DEFAULT_PLUGINS: readonly [import("./models/index.js").ChartPlugin<UseChartZAxisSignature>, import("./models/index.js").ChartPlugin<UseChartBrushSignature>, import("./models/index.js").ChartPlugin<UseChartTooltipSignature>, import("./models/index.js").ChartPlugin<UseChartInteractionSignature>, import("./models/index.js").ChartPlugin<UseChartCartesianAxisSignature<any>>, import("./models/index.js").ChartPlugin<UseChartHighlightSignature>, import("./models/index.js").ChartPlugin<UseChartVisibilityManagerSignature<any>>, import("./models/index.js").ChartPlugin<UseChartClosestPointSignature>, import("./models/index.js").ChartPlugin<UseChartKeyboardNavigationSignature>];
@@ -7,5 +7,6 @@ import { useChartKeyboardNavigation } from "./featurePlugins/useChartKeyboardNav
7
7
  import { useChartClosestPoint } from "./featurePlugins/useChartClosestPoint/index.js";
8
8
  import { useChartZAxis } from "./featurePlugins/useChartZAxis/index.js";
9
9
  import { useChartBrush } from "./featurePlugins/useChartBrush/index.js";
10
+ import { useChartVisibilityManager } from "./featurePlugins/useChartVisibilityManager/index.js";
10
11
  import { useChartTooltip } from "./featurePlugins/useChartTooltip/index.js";
11
- export const DEFAULT_PLUGINS = [useChartZAxis, useChartBrush, useChartTooltip, useChartInteraction, useChartCartesianAxis, useChartHighlight, useChartClosestPoint, useChartKeyboardNavigation];
12
+ export const DEFAULT_PLUGINS = [useChartZAxis, useChartBrush, useChartTooltip, useChartInteraction, useChartCartesianAxis, useChartHighlight, useChartVisibilityManager, useChartClosestPoint, useChartKeyboardNavigation];
@@ -0,0 +1,14 @@
1
+ import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
2
+ import type { ChartSeriesConfig } from "../../models/index.js";
3
+ /**
4
+ * Serializes a series item identifier into a unique string using the appropriate serializer
5
+ * from the provided series configuration.
6
+ *
7
+ * @param {ChartSeriesConfig<ChartSeriesType>} seriesConfig - The configuration object for chart series.
8
+ * @param {SeriesItemIdentifier<ChartSeriesType>} identifier - The series item identifier to serialize.
9
+ * @returns {string} A unique string representation of the identifier.
10
+ * @throws Will throw an error if no serializer is found for the given series type.
11
+ */
12
+ export declare const serializeIdentifier: <T extends ChartSeriesType, U extends {
13
+ type: T;
14
+ }>(seriesConfig: ChartSeriesConfig<T>, identifier: U) => string;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Serializes a series item identifier into a unique string using the appropriate serializer
3
+ * from the provided series configuration.
4
+ *
5
+ * @param {ChartSeriesConfig<ChartSeriesType>} seriesConfig - The configuration object for chart series.
6
+ * @param {SeriesItemIdentifier<ChartSeriesType>} identifier - The series item identifier to serialize.
7
+ * @returns {string} A unique string representation of the identifier.
8
+ * @throws Will throw an error if no serializer is found for the given series type.
9
+ */
10
+ export const serializeIdentifier = (seriesConfig, identifier) => {
11
+ const serializer = seriesConfig[identifier.type]?.identifierSerializer;
12
+ if (!serializer) {
13
+ throw new Error(`MUI X Charts: No identifier serializer found for series type "${identifier.type}".`);
14
+ }
15
+ // @ts-expect-error identifierSerializer expects the full object,
16
+ // but this function accepts a partial one in order be able to serialize all identifiers.
17
+ return serializer(identifier);
18
+ };
@@ -2,8 +2,10 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import { useEffectAfterFirstRender } from '@mui/x-internals/useEffectAfterFirstRender';
5
+ import useEventCallback from '@mui/utils/useEventCallback';
5
6
  import { rainbowSurgePalette } from "../../../../colorPalettes/index.js";
6
7
  import { defaultizeSeries } from "./processSeries.js";
8
+ import { serializeIdentifier as serializeIdentifierFn } from "./serializeIdentifier.js";
7
9
  export const useChartSeries = ({
8
10
  params,
9
11
  store,
@@ -28,7 +30,12 @@ export const useChartSeries = ({
28
30
  dataset
29
31
  }));
30
32
  }, [colors, dataset, series, theme, seriesConfig, store]);
31
- return {};
33
+ const serializeIdentifier = useEventCallback(identifier => serializeIdentifierFn(seriesConfig, identifier));
34
+ return {
35
+ instance: {
36
+ serializeIdentifier
37
+ }
38
+ };
32
39
  };
33
40
  useChartSeries.params = {
34
41
  dataset: true,
@@ -45,7 +45,18 @@ export interface UseChartSeriesState<T extends ChartSeriesType = ChartSeriesType
45
45
  dataset?: Readonly<DatasetType>;
46
46
  };
47
47
  }
48
- export interface UseChartSeriesInstance {}
48
+ export type SerializeIdentifierFunction = <T extends {
49
+ type: ChartSeriesType;
50
+ }>(identifier: T) => string;
51
+ export interface UseChartSeriesInstance {
52
+ /**
53
+ * Function to serialize a series item identifier into a unique string.
54
+ *
55
+ * @param identifier The identifier to serialize.
56
+ * @returns A unique string representing the identifier.
57
+ */
58
+ serializeIdentifier: SerializeIdentifierFunction;
59
+ }
49
60
  export type UseChartSeriesSignature<SeriesType extends ChartSeriesType = ChartSeriesType> = ChartPluginSignature<{
50
61
  params: UseChartSeriesParameters;
51
62
  defaultizedParams: UseChartSeriesDefaultizedParameters<SeriesType>;
@@ -0,0 +1,11 @@
1
+ import { type SeriesItemIdentifier } from "../../../../models/seriesType/index.js";
2
+ import { type UseChartHighlightSignature } from "../useChartHighlight/index.js";
3
+ import { type UseChartCartesianAxisSignature } from "../useChartCartesianAxis/index.js";
4
+ import { type ChartState } from "../../models/index.js";
5
+ /**
6
+ * Hook to get pointer interaction props for chart items.
7
+ */
8
+ export declare function useRegisterPointerInteractions(getItemAtPosition: (state: ChartState<[UseChartCartesianAxisSignature, UseChartHighlightSignature]>, point: {
9
+ x: number;
10
+ y: number;
11
+ }) => SeriesItemIdentifier | undefined, onItemEnter?: () => void, onItemLeave?: () => void): void;
@@ -0,0 +1,74 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import useEventCallback from '@mui/utils/useEventCallback';
5
+ import { useSvgRef } from "../../../../hooks/index.js";
6
+ import { useStore } from "../../../store/useStore.js";
7
+ import { useChartContext } from "../../../../context/ChartProvider/index.js";
8
+ import { getSVGPoint } from "../../../getSVGPoint.js";
9
+ /**
10
+ * Hook to get pointer interaction props for chart items.
11
+ */
12
+ export function useRegisterPointerInteractions(getItemAtPosition, onItemEnter, onItemLeave) {
13
+ const {
14
+ instance
15
+ } = useChartContext();
16
+ const svgRef = useSvgRef();
17
+ const store = useStore();
18
+ const interactionActive = React.useRef(false);
19
+ const lastItemRef = React.useRef(undefined);
20
+ const onItemEnterRef = useEventCallback(() => onItemEnter?.());
21
+ const onItemLeaveRef = useEventCallback(() => onItemLeave?.());
22
+ React.useEffect(() => {
23
+ const svg = svgRef.current;
24
+ if (!svg) {
25
+ return undefined;
26
+ }
27
+ function onPointerEnter() {
28
+ interactionActive.current = true;
29
+ }
30
+ function reset() {
31
+ const lastItem = lastItemRef.current;
32
+ if (lastItem) {
33
+ lastItemRef.current = undefined;
34
+ instance.removeTooltipItem(lastItem);
35
+ instance.clearHighlight();
36
+ onItemLeaveRef();
37
+ }
38
+ }
39
+ function onPointerLeave() {
40
+ interactionActive.current = false;
41
+ reset();
42
+ }
43
+ const onPointerMove = function onPointerMove(event) {
44
+ const svgPoint = getSVGPoint(svg, event);
45
+ if (!instance.isPointInside(svgPoint.x, svgPoint.y)) {
46
+ reset();
47
+ return;
48
+ }
49
+ const item = getItemAtPosition(store.state, svgPoint);
50
+ if (item) {
51
+ instance.setLastUpdateSource('pointer');
52
+ instance.setTooltipItem(item);
53
+ instance.setHighlight(item);
54
+ onItemEnterRef();
55
+ lastItemRef.current = item;
56
+ } else {
57
+ reset();
58
+ }
59
+ };
60
+ svg.addEventListener('pointerleave', onPointerLeave);
61
+ svg.addEventListener('pointermove', onPointerMove);
62
+ svg.addEventListener('pointerenter', onPointerEnter);
63
+ return () => {
64
+ svg.removeEventListener('pointerenter', onPointerEnter);
65
+ svg.removeEventListener('pointermove', onPointerMove);
66
+ svg.removeEventListener('pointerleave', onPointerLeave);
67
+
68
+ /* Clean up state if this item is unmounted while active. */
69
+ if (interactionActive.current) {
70
+ onPointerLeave();
71
+ }
72
+ };
73
+ }, [getItemAtPosition, instance, onItemEnterRef, onItemLeaveRef, store, svgRef]);
74
+ }
@@ -13,6 +13,16 @@ reverse) {
13
13
  const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
14
14
  return reverse ? [range[1], range[0]] : range;
15
15
  }
16
+ function shouldIgnoreGapRatios(scale, categoryGapRatio) {
17
+ const step = scale.step();
18
+ const paddingPx = step * categoryGapRatio;
19
+
20
+ /* If the padding is less than 0.1px, we consider it negligible and ignore it.
21
+ * This prevents issues where very small gaps cause rendering artifacts or unexpected layouts.
22
+ * A threshold of 0.1px is chosen as it's generally below the perceptible limit for most displays.
23
+ */
24
+ return paddingPx < 0.1;
25
+ }
16
26
  const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
17
27
  const DEFAULT_BAR_GAP_RATIO = 0.1;
18
28
  export function computeAxisValue({
@@ -47,8 +57,10 @@ export function computeAxisValue({
47
57
  // Reverse range because ordinal scales are presented from top to bottom on y-axis
48
58
  const scaleRange = axisDirection === 'y' ? [range[1], range[0]] : range;
49
59
  if (isBandScale(scale) && isBandScaleConfig(axis)) {
50
- const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
51
- const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
60
+ const desiredCategoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
61
+ const ignoreGapRatios = shouldIgnoreGapRatios(scale, desiredCategoryGapRatio);
62
+ const categoryGapRatio = ignoreGapRatios ? 0 : desiredCategoryGapRatio;
63
+ const barGapRatio = ignoreGapRatios ? 0 : axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
52
64
  completeAxis[axis.id] = _extends({
53
65
  offset: 0,
54
66
  height: 0,
@@ -57,7 +69,12 @@ export function computeAxisValue({
57
69
  triggerTooltip
58
70
  }, axis, {
59
71
  data,
60
- scale,
72
+ /* Doing this here is technically wrong, but acceptable in practice.
73
+ * In theory, this should be done in the normalized scale selector, but then we'd need that selector to depend
74
+ * on the zoom range, which would void its goal (which is to be independent of zoom).
75
+ * Since we only ignore gap ratios when they're practically invisible, the small errors caused by this
76
+ * discrepancy will hopefully not be noticeable. */
77
+ scale: ignoreGapRatios ? scale.copy().padding(0) : scale,
61
78
  tickNumber,
62
79
  colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
63
80
  values: axis.data
@@ -16,6 +16,7 @@ import { getSVGPoint } from "../../../getSVGPoint.js";
16
16
  import { selectorChartsInteractionIsInitialized } from "../useChartInteraction/index.js";
17
17
  import { selectorChartAxisInteraction } from "./useChartCartesianInteraction.selectors.js";
18
18
  import { checkHasInteractionPlugin } from "../useChartInteraction/checkHasInteractionPlugin.js";
19
+ const AXIS_CLICK_SERIES_TYPES = new Set(['bar', 'rangeBar', 'line']);
19
20
  export const useChartCartesianAxis = ({
20
21
  params,
21
22
  store,
@@ -165,13 +166,19 @@ export const useChartCartesianAxis = ({
165
166
  // The .data exist because otherwise the dataIndex would be null or -1.
166
167
  const axisValue = (isXAxis ? xAxisWithScale : yAxisWithScale)[USED_AXIS_ID].data[dataIndex];
167
168
  const seriesValues = {};
168
- Object.keys(processedSeries).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
169
- processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
170
- const seriesItem = processedSeries[seriesType].series[seriesId];
169
+ Object.keys(processedSeries).filter(seriesType => AXIS_CLICK_SERIES_TYPES.has(seriesType)).forEach(seriesType => {
170
+ // @ts-ignore
171
+ const seriesTypeConfig = processedSeries[seriesType];
172
+ seriesTypeConfig?.seriesOrder.forEach(seriesId => {
173
+ const seriesItem = seriesTypeConfig.series[seriesId];
171
174
  const providedXAxisId = seriesItem.xAxisId;
172
175
  const providedYAxisId = seriesItem.yAxisId;
173
176
  const axisKey = isXAxis ? providedXAxisId : providedYAxisId;
174
177
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
178
+ // @ts-ignore This is safe because users need to opt in to use range bar series.
179
+ // In that case, they should import the module augmentation from `x-charts-pro/moduleAugmentation/rangeBarOnClick`
180
+ // Which adds the proper type to the series data.
181
+ // TODO(v9): Remove this ts-ignore when we can make the breaking change to ChartsAxisData.
175
182
  seriesValues[seriesId] = seriesItem.data[dataIndex];
176
183
  }
177
184
  });
@@ -0,0 +1,4 @@
1
+ import { type BarItemIdentifier } from "../../../../models/index.js";
2
+ export declare const selectorBarItemAtPosition: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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<{}> & {
3
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
4
+ }, svgPoint: Pick<DOMPoint, "x" | "y">) => BarItemIdentifier | undefined;
@@ -0,0 +1,83 @@
1
+ import { createSelector } from '@mui/x-internals/store';
2
+ import { selectorChartXAxis, selectorChartYAxis } from "./useChartCartesianAxisRendering.selectors.js";
3
+ import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
4
+ import { getBandSize } from "../../../getBandSize.js";
5
+ import { isBandScale } from "../../../scaleGuards.js";
6
+ import { getDataIndexForOrdinalScaleValue } from "../../../invertScale.js";
7
+ export const selectorBarItemAtPosition = createSelector(selectorChartXAxis, selectorChartYAxis, selectorChartSeriesProcessed, function selectorBarItemAtPosition({
8
+ axis: xAxes,
9
+ axisIds: xAxisIds
10
+ }, {
11
+ axis: yAxes,
12
+ axisIds: yAxisIds
13
+ }, processedSeries, svgPoint) {
14
+ const {
15
+ series,
16
+ stackingGroups = []
17
+ } = processedSeries?.bar ?? {};
18
+ const defaultXAxisId = xAxisIds[0];
19
+ const defaultYAxisId = yAxisIds[0];
20
+ let item = undefined;
21
+ for (let stackIndex = 0; stackIndex < stackingGroups.length; stackIndex += 1) {
22
+ const group = stackingGroups[stackIndex];
23
+ const seriesIds = group.ids;
24
+ for (const seriesId of seriesIds) {
25
+ const aSeries = (series ?? {})[seriesId];
26
+ const xAxisId = aSeries.xAxisId ?? defaultXAxisId;
27
+ const yAxisId = aSeries.yAxisId ?? defaultYAxisId;
28
+ const xAxis = xAxes[xAxisId];
29
+ const yAxis = yAxes[yAxisId];
30
+ const bandAxis = aSeries.layout === 'horizontal' ? yAxis : xAxis;
31
+ const continuousAxis = aSeries.layout === 'horizontal' ? xAxis : yAxis;
32
+ const bandScale = bandAxis.scale;
33
+ const svgPointBandCoordinate = aSeries.layout === 'horizontal' ? svgPoint.y : svgPoint.x;
34
+ if (!isBandScale(bandScale)) {
35
+ continue;
36
+ }
37
+ const dataIndex = getDataIndexForOrdinalScaleValue(bandScale, svgPointBandCoordinate);
38
+ const {
39
+ barWidth,
40
+ offset
41
+ } = getBandSize(bandScale.bandwidth(), stackingGroups.length, bandAxis.barGapRatio);
42
+ const barOffset = stackIndex * (barWidth + offset);
43
+ const bandValue = bandAxis.data?.[dataIndex];
44
+ if (bandValue == null) {
45
+ continue;
46
+ }
47
+ const bandStart = bandScale(bandValue);
48
+ if (bandStart == null) {
49
+ continue;
50
+ }
51
+ const bandBarStart = bandStart + barOffset;
52
+ const bandBarEnd = bandBarStart + barWidth;
53
+ const bandBarMin = Math.min(bandBarStart, bandBarEnd);
54
+ const bandBarMax = Math.max(bandBarStart, bandBarEnd);
55
+ if (svgPointBandCoordinate >= bandBarMin && svgPointBandCoordinate <= bandBarMax) {
56
+ // The point is inside the band for this series
57
+ const svgPointContinuousCoordinate = aSeries.layout === 'horizontal' ? svgPoint.x : svgPoint.y;
58
+ const bar = aSeries.stackedData[dataIndex];
59
+ const start = continuousAxis.scale(bar[0]);
60
+ const end = continuousAxis.scale(bar[1]);
61
+ if (start == null || end == null) {
62
+ continue;
63
+ }
64
+ const continuousMin = Math.min(start, end);
65
+ const continuousMax = Math.max(start, end);
66
+ if (svgPointContinuousCoordinate >= continuousMin && svgPointContinuousCoordinate <= continuousMax) {
67
+ item = {
68
+ seriesId,
69
+ dataIndex
70
+ };
71
+ }
72
+ }
73
+ }
74
+ }
75
+ if (item) {
76
+ return {
77
+ type: 'bar',
78
+ seriesId: item.seriesId,
79
+ dataIndex: item.dataIndex
80
+ };
81
+ }
82
+ return undefined;
83
+ });
@@ -0,0 +1,13 @@
1
+ import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
2
+ import type { FocusedItemIdentifier } from "../../../../models/seriesType/index.js";
3
+ import type { UseChartKeyboardNavigationSignature } from "./useChartKeyboardNavigation.types.js";
4
+ import type { ChartState } from "../../models/chart.js";
5
+ export type FocusedItemUpdater<TSeriesType extends ChartSeriesType, OutputSeriesType extends ChartSeriesType = ChartSeriesType> = (currentItem: (TSeriesType extends any ? FocusedItemIdentifier<TSeriesType> : never) | null, state: ChartState<[UseChartKeyboardNavigationSignature], []>) => FocusedItemIdentifier<OutputSeriesType> | null;
6
+ /**
7
+ * Get the next focusable item in the chart.
8
+ * @param {SeriesItemIdentifier<TSeriesType> | null} currentItem The current focused item.
9
+ * @param {KeyboardEvent} event The keyboard event that triggered the navigation.
10
+ * @param {ChartState<[UseChartKeyboardNavigationSignature], []>} state The current chart state.
11
+ * @returns {SeriesItemIdentifier<ChartSeriesType> | null} The next focusable item or null if none found.
12
+ */
13
+ export type KeyboardFocusHandler<TSeriesType extends ChartSeriesType, OutputSeriesType extends ChartSeriesType = ChartSeriesType> = (event: KeyboardEvent) => FocusedItemUpdater<TSeriesType, OutputSeriesType> | null;
@@ -1,3 +1,3 @@
1
- import { type ChartPlugin } from "../../models/index.js";
2
- import { type UseChartKeyboardNavigationSignature } from "./useChartKeyboardNavigation.types.js";
1
+ import type { ChartPlugin } from "../../models/index.js";
2
+ import type { UseChartKeyboardNavigationSignature } from "./useChartKeyboardNavigation.types.js";
3
3
  export declare const useChartKeyboardNavigation: ChartPlugin<UseChartKeyboardNavigationSignature>;
@@ -4,92 +4,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import useEventCallback from '@mui/utils/useEventCallback';
6
6
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
- import { getNextSeriesWithData, getPreviousSeriesWithData, seriesHasData } from "./useChartKeyboardNavigation.helpers.js";
8
- import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
9
- function getNextIndexFocusedItem(state) {
10
- const processedSeries = selectorChartSeriesProcessed(state);
11
- let {
12
- type,
13
- seriesId
14
- } = state.keyboardNavigation.item ?? {};
15
- if (type === undefined ||
16
- // @ts-ignore sankey is not in MIT version
17
- type === 'sankey' || seriesId === undefined || !seriesHasData(processedSeries, type, seriesId)) {
18
- const nextSeries = getNextSeriesWithData(processedSeries, type, seriesId);
19
- if (nextSeries === null) {
20
- return null;
21
- }
22
- type = nextSeries.type;
23
- seriesId = nextSeries.seriesId;
24
- }
25
- const dataLength = processedSeries[type].series[seriesId].data.length;
26
- return {
27
- type,
28
- seriesId,
29
- dataIndex: ((state.keyboardNavigation.item?.dataIndex ?? -1) + 1) % dataLength
30
- };
31
- }
32
- function getPreviousIndexFocusedItem(state) {
33
- const processedSeries = selectorChartSeriesProcessed(state);
34
- let {
35
- type,
36
- seriesId
37
- } = state.keyboardNavigation.item ?? {};
38
- if (type === undefined ||
39
- // @ts-ignore sankey is not in MIT version
40
- type === 'sankey' || seriesId === undefined || !seriesHasData(processedSeries, type, seriesId)) {
41
- const previousSeries = getPreviousSeriesWithData(processedSeries, type, seriesId);
42
- if (previousSeries === null) {
43
- return null;
44
- }
45
- type = previousSeries.type;
46
- seriesId = previousSeries.seriesId;
47
- }
48
- const dataLength = processedSeries[type].series[seriesId].data.length;
49
- return {
50
- type,
51
- seriesId,
52
- dataIndex: (dataLength + (state.keyboardNavigation.item?.dataIndex ?? 1) - 1) % dataLength
53
- };
54
- }
55
- function getNextSeriesFocusedItem(state) {
56
- const processedSeries = selectorChartSeriesProcessed(state);
57
- let {
58
- type,
59
- seriesId
60
- } = state.keyboardNavigation.item ?? {};
61
- const nextSeries = getNextSeriesWithData(processedSeries, type, seriesId);
62
- if (nextSeries === null) {
63
- return null; // No series to move the focus to.
64
- }
65
- type = nextSeries.type;
66
- seriesId = nextSeries.seriesId;
67
- const dataLength = processedSeries[type].series[seriesId].data.length;
68
- return {
69
- type,
70
- seriesId,
71
- dataIndex: Math.min(dataLength - 1, state.keyboardNavigation.item?.dataIndex ?? 0)
72
- };
73
- }
74
- function getPreviousSeriesFocusedItem(state) {
75
- const processedSeries = selectorChartSeriesProcessed(state);
76
- let {
77
- type,
78
- seriesId
79
- } = state.keyboardNavigation.item ?? {};
80
- const previousSeries = getPreviousSeriesWithData(processedSeries, type, seriesId);
81
- if (previousSeries === null) {
82
- return null; // No series to move the focus to.
83
- }
84
- type = previousSeries.type;
85
- seriesId = previousSeries.seriesId;
86
- const dataLength = processedSeries[type].series[seriesId].data.length;
87
- return {
88
- type,
89
- seriesId,
90
- dataIndex: Math.min(dataLength - 1, state.keyboardNavigation.item?.dataIndex ?? 0)
91
- };
92
- }
7
+ import { selectorChartDefaultizedSeries } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
93
8
  export const useChartKeyboardNavigation = ({
94
9
  params,
95
10
  store,
@@ -109,26 +24,18 @@ export const useChartKeyboardNavigation = ({
109
24
  }
110
25
  function keyboardHandler(event) {
111
26
  let newFocusedItem = store.state.keyboardNavigation.item;
112
- switch (event.key) {
113
- case 'ArrowRight':
114
- newFocusedItem = getNextIndexFocusedItem(store.state);
115
- break;
116
- case 'ArrowLeft':
117
- newFocusedItem = getPreviousIndexFocusedItem(store.state);
118
- break;
119
- case 'ArrowDown':
120
- {
121
- newFocusedItem = getPreviousSeriesFocusedItem(store.state);
122
- break;
123
- }
124
- case 'ArrowUp':
125
- {
126
- newFocusedItem = getNextSeriesFocusedItem(store.state);
127
- break;
128
- }
129
- default:
130
- break;
27
+ let seriesType = newFocusedItem?.type;
28
+ if (!seriesType) {
29
+ seriesType = Object.keys(selectorChartDefaultizedSeries(store.state)).find(key => store.state.series.seriesConfig[key] !== undefined);
30
+ if (seriesType === undefined) {
31
+ return;
32
+ }
33
+ }
34
+ const calculateFocusedItem = store.state.series.seriesConfig[seriesType]?.keyboardFocusHandler?.(event);
35
+ if (!calculateFocusedItem) {
36
+ return;
131
37
  }
38
+ newFocusedItem = calculateFocusedItem(newFocusedItem, store.state);
132
39
  if (newFocusedItem !== store.state.keyboardNavigation.item) {
133
40
  event.preventDefault();
134
41
  store.update(_extends({}, store.state.highlight && {
@@ -1,21 +1,14 @@
1
- import { type SeriesId } from "../../../../models/seriesType/common.js";
1
+ import type { FocusedItemIdentifier } from "../../../../models/seriesType/index.js";
2
2
  import { type AxisItemIdentifier } from "../../../../models/axis.js";
3
- import { type FocusedItemData } from "../../../../hooks/useFocusedItem.js";
4
3
  export declare const selectorChartsItemIsFocused: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
5
4
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
6
- }, item: FocusedItemData) => boolean;
5
+ }, item: FocusedItemIdentifier<keyof import("../../../index.js").ChartsSeriesConfig>) => boolean;
7
6
  export declare const selectorChartsHasFocusedItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
8
7
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
9
8
  }) => boolean;
10
- export declare const selectorChartsFocusedSeriesType: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
9
+ export declare const selectorChartsFocusedItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
11
10
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
12
- }) => "line" | "bar" | "scatter" | "pie" | undefined;
13
- export declare const selectorChartsFocusedSeriesId: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
14
- cacheKey: import("../../models/index.js").ChartStateCacheKey;
15
- }) => SeriesId | undefined;
16
- export declare const selectorChartsFocusedDataIndex: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
17
- cacheKey: import("../../models/index.js").ChartStateCacheKey;
18
- }) => number | undefined;
11
+ }) => FocusedItemIdentifier<keyof import("../../../index.js").ChartsSeriesConfig> | null;
19
12
  export declare const selectorChartsIsKeyboardNavigationEnabled: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
20
13
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
21
14
  }) => boolean;
@@ -27,23 +20,4 @@ export declare const selectorChartsKeyboardYAxisIndex: (args_0: import("../../co
27
20
  }) => AxisItemIdentifier | undefined;
28
21
  export declare const selectorChartsKeyboardItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
29
22
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
30
- }) => {
31
- type: "line";
32
- seriesId: SeriesId;
33
- dataIndex: number;
34
- } | {
35
- type: "bar";
36
- seriesId: SeriesId;
37
- dataIndex: number;
38
- } | {
39
- type: "scatter";
40
- seriesId: SeriesId;
41
- dataIndex: number;
42
- } | {
43
- type: "pie";
44
- seriesId: SeriesId;
45
- dataIndex: number;
46
- } | null;
47
- export declare const selectorChartsKeyboardItemIsDefined: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & 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> & {
48
- cacheKey: import("../../models/index.js").ChartStateCacheKey;
49
- }) => boolean;
23
+ }) => FocusedItemIdentifier<keyof import("../../../index.js").ChartsSeriesConfig> | null;