@mui/x-charts 8.23.0 → 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 (262) 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/BarLabel/BarLabel.d.ts +2 -0
  5. package/BarChart/BarLabel/BarLabel.js +8 -3
  6. package/BarChart/BarLabel/BarLabelItem.d.ts +2 -0
  7. package/BarChart/BarLabel/BarLabelItem.js +4 -2
  8. package/BarChart/BarPlot.d.ts +12 -2
  9. package/BarChart/BarPlot.js +29 -86
  10. package/BarChart/BatchBarPlot/BarGroup.d.ts +15 -0
  11. package/BarChart/BatchBarPlot/BarGroup.js +142 -0
  12. package/BarChart/BatchBarPlot/BatchBarPlot.d.ts +12 -0
  13. package/BarChart/BatchBarPlot/BatchBarPlot.js +140 -0
  14. package/BarChart/BatchBarPlot/index.d.ts +1 -0
  15. package/BarChart/BatchBarPlot/index.js +12 -0
  16. package/BarChart/BatchBarPlot/useCreateBarPaths.d.ts +8 -0
  17. package/BarChart/BatchBarPlot/useCreateBarPaths.js +53 -0
  18. package/BarChart/FocusedBar.js +5 -1
  19. package/BarChart/IndividualBarPlot.d.ts +21 -0
  20. package/BarChart/IndividualBarPlot.js +106 -0
  21. package/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.ts +1 -1
  22. package/BarChart/seriesConfig/bar/legend.js +1 -0
  23. package/BarChart/seriesConfig/index.js +3 -1
  24. package/BarChart/types.d.ts +2 -0
  25. package/BarChart/useBarChartProps.d.ts +6 -2
  26. package/BarChart/useBarChartProps.js +4 -2
  27. package/BarChart/useBarPlotData.d.ts +1 -1
  28. package/BarChart/useBarPlotData.js +23 -4
  29. package/BarChart/useRegisterItemClickHandlers.d.ts +6 -0
  30. package/BarChart/useRegisterItemClickHandlers.js +72 -0
  31. package/CHANGELOG.md +111 -1
  32. package/ChartContainer/ChartContainer.js +34 -0
  33. package/ChartContainer/useChartContainerProps.js +6 -2
  34. package/ChartsLegend/ChartsLegend.js +2 -2
  35. package/ChartsLegend/legendContext.types.d.ts +12 -0
  36. package/ChartsLegend/onClickContextBuilder.js +2 -1
  37. package/ChartsOverlay/ChartsLoadingOverlay.js +4 -1
  38. package/ChartsOverlay/ChartsNoDataOverlay.js +4 -1
  39. package/ChartsReferenceLine/common.d.ts +1 -1
  40. package/ChartsReferenceLine/common.js +4 -1
  41. package/ChartsTooltip/ChartsTooltipContainer.js +25 -21
  42. package/Gauge/GaugeContainer.js +4 -1
  43. package/LineChart/AnimatedLine.js +7 -3
  44. package/LineChart/AppearingMask.js +4 -1
  45. package/LineChart/CircleMarkElement.d.ts +5 -0
  46. package/LineChart/CircleMarkElement.js +13 -5
  47. package/LineChart/FocusedLineMark.js +5 -1
  48. package/LineChart/LineChart.js +30 -0
  49. package/LineChart/LineChart.plugins.d.ts +2 -1
  50. package/LineChart/LineChart.plugins.js +2 -1
  51. package/LineChart/LineElement.d.ts +4 -0
  52. package/LineChart/LineElement.js +7 -3
  53. package/LineChart/MarkElement.d.ts +5 -0
  54. package/LineChart/MarkElement.js +17 -10
  55. package/LineChart/markElementClasses.d.ts +0 -1
  56. package/LineChart/seriesConfig/index.js +3 -1
  57. package/LineChart/seriesConfig/legend.js +1 -0
  58. package/PieChart/FocusedPieArc.js +5 -2
  59. package/PieChart/PieArcLabel.d.ts +2 -0
  60. package/PieChart/PieArcLabel.js +5 -2
  61. package/PieChart/PieChart.js +35 -5
  62. package/PieChart/PieChart.plugins.d.ts +2 -1
  63. package/PieChart/PieChart.plugins.js +2 -1
  64. package/PieChart/seriesConfig/index.js +3 -1
  65. package/PieChart/seriesConfig/legend.js +6 -3
  66. package/RadarChart/RadarChart.js +30 -0
  67. package/RadarChart/RadarChart.plugins.d.ts +3 -2
  68. package/RadarChart/RadarChart.plugins.js +2 -1
  69. package/RadarChart/seriesConfig/index.js +3 -1
  70. package/RadarChart/seriesConfig/legend.js +1 -0
  71. package/ScatterChart/BatchScatter.js +8 -14
  72. package/ScatterChart/ScatterChart.js +30 -0
  73. package/ScatterChart/ScatterChart.plugins.d.ts +2 -1
  74. package/ScatterChart/ScatterChart.plugins.js +2 -1
  75. package/ScatterChart/seriesConfig/index.js +3 -1
  76. package/ScatterChart/seriesConfig/legend.js +1 -0
  77. package/SparkLineChart/SparkLineChart.js +46 -0
  78. package/esm/BarChart/BarChart.js +39 -0
  79. package/esm/BarChart/BarChart.plugins.d.ts +2 -1
  80. package/esm/BarChart/BarChart.plugins.js +2 -1
  81. package/esm/BarChart/BarLabel/BarLabel.d.ts +2 -0
  82. package/esm/BarChart/BarLabel/BarLabel.js +8 -3
  83. package/esm/BarChart/BarLabel/BarLabelItem.d.ts +2 -0
  84. package/esm/BarChart/BarLabel/BarLabelItem.js +4 -2
  85. package/esm/BarChart/BarPlot.d.ts +12 -2
  86. package/esm/BarChart/BarPlot.js +29 -86
  87. package/esm/BarChart/BatchBarPlot/BarGroup.d.ts +15 -0
  88. package/esm/BarChart/BatchBarPlot/BarGroup.js +134 -0
  89. package/esm/BarChart/BatchBarPlot/BatchBarPlot.d.ts +12 -0
  90. package/esm/BarChart/BatchBarPlot/BatchBarPlot.js +133 -0
  91. package/esm/BarChart/BatchBarPlot/index.d.ts +1 -0
  92. package/esm/BarChart/BatchBarPlot/index.js +1 -0
  93. package/esm/BarChart/BatchBarPlot/useCreateBarPaths.d.ts +8 -0
  94. package/esm/BarChart/BatchBarPlot/useCreateBarPaths.js +46 -0
  95. package/esm/BarChart/FocusedBar.js +5 -1
  96. package/esm/BarChart/IndividualBarPlot.d.ts +21 -0
  97. package/esm/BarChart/IndividualBarPlot.js +98 -0
  98. package/esm/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.ts +1 -1
  99. package/esm/BarChart/seriesConfig/bar/legend.js +1 -0
  100. package/esm/BarChart/seriesConfig/index.js +3 -1
  101. package/esm/BarChart/types.d.ts +2 -0
  102. package/esm/BarChart/useBarChartProps.d.ts +6 -2
  103. package/esm/BarChart/useBarChartProps.js +4 -3
  104. package/esm/BarChart/useBarPlotData.d.ts +1 -1
  105. package/esm/BarChart/useBarPlotData.js +20 -1
  106. package/esm/BarChart/useRegisterItemClickHandlers.d.ts +6 -0
  107. package/esm/BarChart/useRegisterItemClickHandlers.js +67 -0
  108. package/esm/ChartContainer/ChartContainer.js +34 -0
  109. package/esm/ChartContainer/useChartContainerProps.js +6 -2
  110. package/esm/ChartsLegend/ChartsLegend.js +2 -2
  111. package/esm/ChartsLegend/legendContext.types.d.ts +12 -0
  112. package/esm/ChartsLegend/onClickContextBuilder.js +2 -1
  113. package/esm/ChartsOverlay/ChartsLoadingOverlay.js +4 -1
  114. package/esm/ChartsOverlay/ChartsNoDataOverlay.js +4 -1
  115. package/esm/ChartsReferenceLine/common.d.ts +1 -1
  116. package/esm/ChartsReferenceLine/common.js +4 -1
  117. package/esm/ChartsTooltip/ChartsTooltipContainer.js +26 -22
  118. package/esm/Gauge/GaugeContainer.js +4 -1
  119. package/esm/LineChart/AnimatedLine.js +7 -3
  120. package/esm/LineChart/AppearingMask.js +4 -1
  121. package/esm/LineChart/CircleMarkElement.d.ts +5 -0
  122. package/esm/LineChart/CircleMarkElement.js +13 -5
  123. package/esm/LineChart/FocusedLineMark.js +5 -1
  124. package/esm/LineChart/LineChart.js +30 -0
  125. package/esm/LineChart/LineChart.plugins.d.ts +2 -1
  126. package/esm/LineChart/LineChart.plugins.js +2 -1
  127. package/esm/LineChart/LineElement.d.ts +4 -0
  128. package/esm/LineChart/LineElement.js +7 -3
  129. package/esm/LineChart/MarkElement.d.ts +5 -0
  130. package/esm/LineChart/MarkElement.js +17 -10
  131. package/esm/LineChart/markElementClasses.d.ts +0 -1
  132. package/esm/LineChart/seriesConfig/index.js +3 -1
  133. package/esm/LineChart/seriesConfig/legend.js +1 -0
  134. package/esm/PieChart/FocusedPieArc.js +4 -1
  135. package/esm/PieChart/PieArcLabel.d.ts +2 -0
  136. package/esm/PieChart/PieArcLabel.js +5 -2
  137. package/esm/PieChart/PieChart.js +35 -5
  138. package/esm/PieChart/PieChart.plugins.d.ts +2 -1
  139. package/esm/PieChart/PieChart.plugins.js +2 -1
  140. package/esm/PieChart/seriesConfig/index.js +3 -1
  141. package/esm/PieChart/seriesConfig/legend.js +6 -3
  142. package/esm/RadarChart/RadarChart.js +30 -0
  143. package/esm/RadarChart/RadarChart.plugins.d.ts +3 -2
  144. package/esm/RadarChart/RadarChart.plugins.js +2 -1
  145. package/esm/RadarChart/seriesConfig/index.js +3 -1
  146. package/esm/RadarChart/seriesConfig/legend.js +1 -0
  147. package/esm/ScatterChart/BatchScatter.js +5 -11
  148. package/esm/ScatterChart/ScatterChart.js +30 -0
  149. package/esm/ScatterChart/ScatterChart.plugins.d.ts +2 -1
  150. package/esm/ScatterChart/ScatterChart.plugins.js +2 -1
  151. package/esm/ScatterChart/seriesConfig/index.js +3 -1
  152. package/esm/ScatterChart/seriesConfig/legend.js +1 -0
  153. package/esm/SparkLineChart/SparkLineChart.js +46 -0
  154. package/esm/index.js +1 -1
  155. package/esm/internals/appendAtKey.d.ts +8 -0
  156. package/esm/internals/appendAtKey.js +17 -0
  157. package/esm/internals/commonNextFocusItem.js +12 -8
  158. package/esm/internals/getBarDimensions.d.ts +1 -2
  159. package/esm/internals/identifierSerializer.d.ts +9 -0
  160. package/esm/internals/identifierSerializer.js +6 -0
  161. package/esm/internals/index.d.ts +6 -2
  162. package/esm/internals/index.js +6 -2
  163. package/esm/internals/invertScale.d.ts +6 -2
  164. package/esm/internals/invertScale.js +9 -1
  165. package/esm/internals/plugins/allPlugins.d.ts +4 -3
  166. package/esm/internals/plugins/allPlugins.js +2 -1
  167. package/esm/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.d.ts +14 -0
  168. package/esm/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.js +18 -0
  169. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +8 -1
  170. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +12 -1
  171. package/esm/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.d.ts +11 -0
  172. package/esm/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +74 -0
  173. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +20 -3
  174. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -3
  175. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +4 -0
  176. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +83 -0
  177. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.d.ts +3 -0
  178. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.js +6 -0
  179. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +7 -34
  180. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.d.ts +7 -0
  181. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.js +9 -0
  182. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +10 -32
  183. package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +2 -2
  184. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/index.d.ts +3 -0
  185. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/index.js +3 -0
  186. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.d.ts +4 -0
  187. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.js +5 -0
  188. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.d.ts +3 -0
  189. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.js +78 -0
  190. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.d.ts +16 -0
  191. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.js +19 -0
  192. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.d.ts +90 -0
  193. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.js +1 -0
  194. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.d.ts +4 -0
  195. package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.js +11 -0
  196. package/esm/internals/plugins/models/seriesConfig/identifierSerializer.types.d.ts +2 -0
  197. package/esm/internals/plugins/models/seriesConfig/identifierSerializer.types.js +1 -0
  198. package/esm/internals/plugins/models/seriesConfig/index.d.ts +2 -1
  199. package/esm/internals/plugins/models/seriesConfig/index.js +2 -1
  200. package/esm/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +7 -0
  201. package/esm/models/axis.d.ts +5 -4
  202. package/esm/models/featureFlags.d.ts +1 -0
  203. package/esm/models/featureFlags.js +1 -0
  204. package/esm/models/index.d.ts +1 -0
  205. package/esm/models/index.js +1 -0
  206. package/esm/moduleAugmentation/barChartBatchRendererOnItemClick.d.ts +13 -0
  207. package/esm/moduleAugmentation/barChartBatchRendererOnItemClick.js +1 -0
  208. package/index.js +1 -1
  209. package/internals/appendAtKey.d.ts +8 -0
  210. package/internals/appendAtKey.js +23 -0
  211. package/internals/commonNextFocusItem.js +12 -8
  212. package/internals/getBarDimensions.d.ts +1 -2
  213. package/internals/identifierSerializer.d.ts +9 -0
  214. package/internals/identifierSerializer.js +16 -0
  215. package/internals/index.d.ts +6 -2
  216. package/internals/index.js +51 -7
  217. package/internals/invertScale.d.ts +6 -2
  218. package/internals/invertScale.js +10 -1
  219. package/internals/plugins/allPlugins.d.ts +4 -3
  220. package/internals/plugins/allPlugins.js +2 -1
  221. package/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.d.ts +14 -0
  222. package/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.js +25 -0
  223. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +8 -1
  224. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +12 -1
  225. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.d.ts +11 -0
  226. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +81 -0
  227. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +20 -3
  228. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -3
  229. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +4 -0
  230. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +89 -0
  231. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.d.ts +3 -0
  232. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.js +12 -0
  233. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +6 -34
  234. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.d.ts +7 -0
  235. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.js +15 -0
  236. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +9 -32
  237. package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +2 -2
  238. package/internals/plugins/featurePlugins/useChartVisibilityManager/index.d.ts +3 -0
  239. package/internals/plugins/featurePlugins/useChartVisibilityManager/index.js +39 -0
  240. package/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.d.ts +4 -0
  241. package/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.js +12 -0
  242. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.d.ts +3 -0
  243. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.js +85 -0
  244. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.d.ts +16 -0
  245. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.js +25 -0
  246. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.d.ts +90 -0
  247. package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.js +5 -0
  248. package/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.d.ts +4 -0
  249. package/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.js +18 -0
  250. package/internals/plugins/models/seriesConfig/identifierSerializer.types.d.ts +2 -0
  251. package/internals/plugins/models/seriesConfig/identifierSerializer.types.js +5 -0
  252. package/internals/plugins/models/seriesConfig/index.d.ts +2 -1
  253. package/internals/plugins/models/seriesConfig/index.js +11 -0
  254. package/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +7 -0
  255. package/models/axis.d.ts +5 -4
  256. package/models/featureFlags.d.ts +1 -0
  257. package/models/featureFlags.js +5 -0
  258. package/models/index.d.ts +1 -0
  259. package/models/index.js +11 -0
  260. package/moduleAugmentation/barChartBatchRendererOnItemClick.d.ts +13 -0
  261. package/moduleAugmentation/barChartBatchRendererOnItemClick.js +5 -0
  262. package/package.json +13 -3
@@ -134,6 +134,31 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
134
134
  * The height of the chart in px. If not defined, it takes the height of the parent element.
135
135
  */
136
136
  height: PropTypes.number,
137
+ /**
138
+ * List of hidden series and/or items.
139
+ *
140
+ * Different chart types use different keys.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * [
145
+ * {
146
+ * type: 'pie',
147
+ * seriesId: 'series-1',
148
+ * dataIndex: 3,
149
+ * },
150
+ * {
151
+ * type: 'line',
152
+ * seriesId: 'series-2',
153
+ * }
154
+ * ]
155
+ * ```
156
+ */
157
+ hiddenItems: PropTypes.arrayOf(PropTypes.shape({
158
+ dataIndex: PropTypes.number,
159
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
160
+ type: PropTypes.oneOf(['bar']).isRequired
161
+ })),
137
162
  /**
138
163
  * If `true`, the legend is not rendered.
139
164
  */
@@ -192,6 +217,11 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
192
217
  * @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
193
218
  */
194
219
  onAxisClick: PropTypes.func,
220
+ /**
221
+ * Callback fired when any hidden identifiers change.
222
+ * @param {VisibilityIdentifier[]} hiddenItems The new list of hidden identifiers.
223
+ */
224
+ onHiddenItemsChange: PropTypes.func,
195
225
  /**
196
226
  * The callback fired when the highlighted item changes.
197
227
  *
@@ -212,6 +242,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
212
242
  * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
213
243
  */
214
244
  onItemClick: PropTypes.func,
245
+ /**
246
+ * The type of renderer to use for the bar plot.
247
+ * - `svg-single`: Renders every bar in a `<rect />` element.
248
+ * - `svg-batch`: Batch renders bars in `<path />` elements for better performance with large datasets, at the cost of some limitations.
249
+ * Read more: https://mui.com/x/react-charts/bars/#performance
250
+ *
251
+ * @default 'svg-single'
252
+ */
253
+ renderer: PropTypes.oneOf(['svg-batch', 'svg-single']),
215
254
  /**
216
255
  * The series to display in the bar chart.
217
256
  * An array of [[BarSeries]] objects.
@@ -6,5 +6,6 @@ import { type UseChartHighlightSignature } from "../internals/plugins/featurePlu
6
6
  import { type UseChartKeyboardNavigationSignature } from "../internals/plugins/featurePlugins/useChartKeyboardNavigation/index.js";
7
7
  import { type ConvertSignaturesIntoPlugins } from "../internals/plugins/models/helpers.js";
8
8
  import { type UseChartBrushSignature } from "../internals/plugins/featurePlugins/useChartBrush/index.js";
9
- export type BarChartPluginSignatures = [UseChartZAxisSignature, UseChartBrushSignature, UseChartTooltipSignature, UseChartInteractionSignature, UseChartCartesianAxisSignature<'bar'>, UseChartHighlightSignature, UseChartKeyboardNavigationSignature];
9
+ import { type UseChartVisibilityManagerSignature } from "../internals/plugins/featurePlugins/useChartVisibilityManager/index.js";
10
+ export type BarChartPluginSignatures = [UseChartZAxisSignature, UseChartBrushSignature, UseChartTooltipSignature, UseChartInteractionSignature, UseChartCartesianAxisSignature<'bar'>, UseChartHighlightSignature, UseChartVisibilityManagerSignature<'bar'>, UseChartKeyboardNavigationSignature];
10
11
  export declare const BAR_CHART_PLUGINS: ConvertSignaturesIntoPlugins<BarChartPluginSignatures>;
@@ -5,4 +5,5 @@ import { useChartInteraction } from "../internals/plugins/featurePlugins/useChar
5
5
  import { useChartHighlight } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
6
6
  import { useChartKeyboardNavigation } from "../internals/plugins/featurePlugins/useChartKeyboardNavigation/index.js";
7
7
  import { useChartBrush } from "../internals/plugins/featurePlugins/useChartBrush/index.js";
8
- export const BAR_CHART_PLUGINS = [useChartZAxis, useChartBrush, useChartTooltip, useChartInteraction, useChartCartesianAxis, useChartHighlight, useChartKeyboardNavigation];
8
+ import { useChartVisibilityManager } from "../internals/plugins/featurePlugins/useChartVisibilityManager/index.js";
9
+ export const BAR_CHART_PLUGINS = [useChartZAxis, useChartBrush, useChartTooltip, useChartInteraction, useChartCartesianAxis, useChartHighlight, useChartVisibilityManager, useChartKeyboardNavigation];
@@ -32,6 +32,8 @@ export type BarLabelProps = Omit<React.SVGProps<SVGTextElement>, 'ref' | 'id' |
32
32
  * @default 'center'
33
33
  */
34
34
  placement?: 'center' | 'outside';
35
+ /** If true, the bar label is hidden. */
36
+ hidden?: boolean;
35
37
  };
36
38
  declare function BarLabel(inProps: BarLabelProps): React.JSX.Element;
37
39
  declare namespace BarLabel {
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
4
  import _extends from "@babel/runtime/helpers/esm/extends";
5
- const _excluded = ["seriesId", "dataIndex", "color", "isFaded", "isHighlighted", "classes", "skipAnimation", "layout", "xOrigin", "yOrigin", "placement"];
5
+ const _excluded = ["seriesId", "dataIndex", "color", "isFaded", "isHighlighted", "classes", "skipAnimation", "layout", "xOrigin", "yOrigin", "placement", "hidden"];
6
6
  import * as React from 'react';
7
7
  import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import PropTypes from 'prop-types';
@@ -34,7 +34,8 @@ function BarLabel(inProps) {
34
34
  name: 'MuiBarLabel'
35
35
  });
36
36
  const {
37
- isFaded
37
+ isFaded,
38
+ hidden
38
39
  } = props,
39
40
  otherProps = _objectWithoutPropertiesLoose(props, _excluded);
40
41
  const animatedProps = useAnimateBarLabel(props);
@@ -44,7 +45,7 @@ function BarLabel(inProps) {
44
45
  return /*#__PURE__*/_jsx(BarLabelComponent, _extends({
45
46
  textAnchor: textAnchor,
46
47
  dominantBaseline: dominantBaseline,
47
- opacity: fadedOpacity
48
+ opacity: hidden ? 0 : fadedOpacity
48
49
  }, otherProps, animatedProps));
49
50
  }
50
51
  function getTextAnchor({
@@ -86,6 +87,10 @@ process.env.NODE_ENV !== "production" ? BarLabel.propTypes = {
86
87
  * Height of the bar this label belongs to.
87
88
  */
88
89
  height: PropTypes.number.isRequired,
90
+ /**
91
+ * If true, the bar label is hidden.
92
+ */
93
+ hidden: PropTypes.bool,
89
94
  isFaded: PropTypes.bool.isRequired,
90
95
  isHighlighted: PropTypes.bool.isRequired,
91
96
  layout: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
@@ -74,6 +74,8 @@ export type BarLabelItemProps<V extends BarValueType | null> = Omit<BarLabelOwne
74
74
  * @default 'center'
75
75
  */
76
76
  barLabelPlacement?: BarLabelProps['placement'];
77
+ /** If true, the bar label is hidden. */
78
+ hidden?: boolean;
77
79
  };
78
80
  /**
79
81
  * @ignore - internal component.
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["seriesId", "classes", "color", "dataIndex", "barLabel", "slots", "slotProps", "xOrigin", "yOrigin", "x", "y", "width", "height", "value", "skipAnimation", "layout", "barLabelPlacement"],
3
+ const _excluded = ["seriesId", "classes", "color", "dataIndex", "barLabel", "slots", "slotProps", "xOrigin", "yOrigin", "x", "y", "width", "height", "value", "skipAnimation", "layout", "barLabelPlacement", "hidden"],
4
4
  _excluded2 = ["ownerState"];
5
5
  import * as React from 'react';
6
6
  import useSlotProps from '@mui/utils/useSlotProps';
@@ -31,7 +31,8 @@ function BarLabelItem(props) {
31
31
  value,
32
32
  skipAnimation,
33
33
  layout,
34
- barLabelPlacement
34
+ barLabelPlacement,
35
+ hidden
35
36
  } = props,
36
37
  other = _objectWithoutPropertiesLoose(props, _excluded);
37
38
  const {
@@ -87,6 +88,7 @@ function BarLabelItem(props) {
87
88
  return null;
88
89
  }
89
90
  return /*#__PURE__*/_jsx(Component, _extends({}, barLabelProps, barLabelOwnerState, {
91
+ hidden: hidden,
90
92
  children: formattedLabelText
91
93
  }));
92
94
  }
@@ -3,6 +3,7 @@ import { type BarElementSlotProps, type BarElementSlots } from "./BarElement.js"
3
3
  import { type BarItemIdentifier } from "../models/index.js";
4
4
  import { type BarLabelSlotProps, type BarLabelSlots } from "./BarLabel/BarLabelItem.js";
5
5
  import type { BarItem, BarLabelContext } from "./BarLabel/index.js";
6
+ import { type RendererType } from "../ScatterChart/index.js";
6
7
  export interface BarPlotSlots extends BarElementSlots, BarLabelSlots {}
7
8
  export interface BarPlotSlotProps extends BarElementSlotProps, BarLabelSlotProps {}
8
9
  export interface BarPlotProps {
@@ -16,7 +17,7 @@ export interface BarPlotProps {
16
17
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
17
18
  * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
18
19
  */
19
- onItemClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, barItemIdentifier: BarItemIdentifier) => void;
20
+ onItemClick?(event: React.MouseEvent<SVGElement, MouseEvent>, barItemIdentifier: BarItemIdentifier): void;
20
21
  /**
21
22
  * Defines the border radius of the bar element.
22
23
  */
@@ -30,6 +31,15 @@ export interface BarPlotProps {
30
31
  * @returns {string} The formatted label.
31
32
  */
32
33
  barLabel?: 'value' | ((item: BarItem, context: BarLabelContext) => string | null | undefined);
34
+ /**
35
+ * The type of renderer to use for the bar plot.
36
+ * - `svg-single`: Renders every bar in a `<rect />` element.
37
+ * - `svg-batch`: Batch renders bars in `<path />` elements for better performance with large datasets, at the cost of some limitations.
38
+ * Read more: https://mui.com/x/react-charts/bars/#performance
39
+ *
40
+ * @default 'svg-single'
41
+ */
42
+ renderer?: RendererType;
33
43
  /**
34
44
  * The props used for each component slot.
35
45
  * @default {}
@@ -52,7 +62,7 @@ export interface BarPlotProps {
52
62
  *
53
63
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
54
64
  */
55
- declare function BarPlot(props: BarPlotProps): import("react/jsx-runtime").JSX.Element;
65
+ declare function BarPlot(props: BarPlotProps): React.JSX.Element;
56
66
  declare namespace BarPlot {
57
67
  var propTypes: any;
58
68
  }
@@ -2,20 +2,20 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["skipAnimation", "onItemClick", "borderRadius", "barLabel"];
5
+ const _excluded = ["skipAnimation", "onItemClick", "borderRadius", "barLabel", "renderer"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { styled } from '@mui/material/styles';
9
9
  import { barElementClasses } from "./barElementClasses.js";
10
- import { BarElement } from "./BarElement.js";
11
10
  import { useDrawingArea, useXAxes, useYAxes } from "../hooks/index.js";
12
- import { BarClipPath } from "./BarClipPath.js";
13
11
  import { BarLabelPlot } from "./BarLabel/BarLabelPlot.js";
14
12
  import { useSkipAnimation } from "../hooks/useSkipAnimation.js";
15
13
  import { useInternalIsZoomInteracting } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting.js";
16
14
  import { useBarPlotData } from "./useBarPlotData.js";
17
15
  import { useUtilityClasses } from "./barClasses.js";
18
16
  import { ANIMATION_DURATION_MS, ANIMATION_TIMING_FUNCTION } from "../internals/animation/animation.js";
17
+ import { IndividualBarPlot } from "./IndividualBarPlot.js";
18
+ import { BatchBarPlot } from "./BatchBarPlot/index.js";
19
19
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
20
  const BarPlotRoot = styled('g', {
21
21
  name: 'MuiBarPlot',
@@ -44,11 +44,13 @@ function BarPlot(props) {
44
44
  skipAnimation: inSkipAnimation,
45
45
  onItemClick,
46
46
  borderRadius,
47
- barLabel
47
+ barLabel,
48
+ renderer
48
49
  } = props,
49
50
  other = _objectWithoutPropertiesLoose(props, _excluded);
50
51
  const isZoomInteracting = useInternalIsZoomInteracting();
51
52
  const skipAnimation = useSkipAnimation(isZoomInteracting || inSkipAnimation);
53
+ const batchSkipAnimation = useSkipAnimation(inSkipAnimation);
52
54
  const {
53
55
  xAxis: xAxes
54
56
  } = useXAxes();
@@ -59,86 +61,22 @@ function BarPlot(props) {
59
61
  completedData,
60
62
  masksData
61
63
  } = useBarPlotData(useDrawingArea(), xAxes, yAxes);
62
- const withoutBorderRadius = !borderRadius || borderRadius <= 0;
63
64
  const classes = useUtilityClasses();
65
+ const BarElementPlot = renderer === 'svg-batch' ? BatchBarPlot : IndividualBarPlot;
64
66
  return /*#__PURE__*/_jsxs(BarPlotRoot, {
65
67
  className: classes.root,
66
- children: [!withoutBorderRadius && masksData.map(({
67
- id,
68
- x,
69
- y,
70
- xOrigin,
71
- yOrigin,
72
- width,
73
- height,
74
- hasPositive,
75
- hasNegative,
76
- layout
77
- }) => {
78
- return /*#__PURE__*/_jsx(BarClipPath, {
79
- maskId: id,
80
- borderRadius: borderRadius,
81
- hasNegative: hasNegative,
82
- hasPositive: hasPositive,
83
- layout: layout,
84
- x: x,
85
- y: y,
86
- xOrigin: xOrigin,
87
- yOrigin: yOrigin,
88
- width: width,
89
- height: height,
90
- skipAnimation: skipAnimation ?? false
91
- }, id);
92
- }), completedData.map(({
93
- seriesId,
94
- layout,
95
- xOrigin,
96
- yOrigin,
97
- data
98
- }) => {
99
- return /*#__PURE__*/_jsx("g", {
100
- "data-series": seriesId,
101
- className: classes.series,
102
- children: data.map(({
103
- dataIndex,
104
- color,
105
- maskId,
106
- x,
107
- y,
108
- width,
109
- height
110
- }) => {
111
- const barElement = /*#__PURE__*/_jsx(BarElement, _extends({
112
- id: seriesId,
113
- dataIndex: dataIndex,
114
- color: color,
115
- skipAnimation: skipAnimation ?? false,
116
- layout: layout ?? 'vertical',
117
- x: x,
118
- xOrigin: xOrigin,
119
- y: y,
120
- yOrigin: yOrigin,
121
- width: width,
122
- height: height
123
- }, other, {
124
- onClick: onItemClick && (event => {
125
- onItemClick(event, {
126
- type: 'bar',
127
- seriesId,
128
- dataIndex
129
- });
130
- })
131
- }), dataIndex);
132
- if (withoutBorderRadius) {
133
- return barElement;
134
- }
135
- return /*#__PURE__*/_jsx("g", {
136
- clipPath: `url(#${maskId})`,
137
- children: barElement
138
- }, dataIndex);
139
- })
140
- }, seriesId);
141
- }), completedData.map(processedSeries => /*#__PURE__*/_jsx(BarLabelPlot, _extends({
68
+ children: [/*#__PURE__*/_jsx(BarElementPlot, _extends({
69
+ completedData: completedData,
70
+ masksData: masksData
71
+ /* The batch renderer doesn't animate bars after the initial mount. Providing skipAnimation was causing an issue
72
+ * where bars would animate again after a zoom interaction because skipAnimation would change from true to false. */,
73
+ skipAnimation: renderer === 'svg-batch' ? batchSkipAnimation : skipAnimation,
74
+ onItemClick:
75
+ /* `onItemClick` accepts a `MouseEvent` when the renderer is "svg-batch" and a `React.MouseEvent` otherwise,
76
+ * so we need this cast to prevent TypeScript from complaining. */
77
+ onItemClick,
78
+ borderRadius: borderRadius
79
+ }, other)), completedData.map(processedSeries => /*#__PURE__*/_jsx(BarLabelPlot, _extends({
142
80
  className: classes.seriesLabels,
143
81
  processedSeries: processedSeries,
144
82
  skipAnimation: skipAnimation,
@@ -152,6 +90,7 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
152
90
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
153
91
  // ----------------------------------------------------------------------
154
92
  /**
93
+ * @deprecated Use `barLabel` in the chart series instead.
155
94
  * If provided, the function will be used to format the label of the bar.
156
95
  * It can be set to 'value' to display the current value.
157
96
  * @param {BarItem} item The item to format.
@@ -159,11 +98,6 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
159
98
  * @returns {string} The formatted label.
160
99
  */
161
100
  barLabel: PropTypes.oneOfType([PropTypes.oneOf(['value']), PropTypes.func]),
162
- /**
163
- * The placement of the bar label.
164
- * It controls whether the label is rendered inside or outside the bar.
165
- */
166
- barLabelPlacement: PropTypes.oneOf(['outside', 'inside']),
167
101
  /**
168
102
  * Defines the border radius of the bar element.
169
103
  */
@@ -174,6 +108,15 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
174
108
  * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
175
109
  */
176
110
  onItemClick: PropTypes.func,
111
+ /**
112
+ * The type of renderer to use for the bar plot.
113
+ * - `svg-single`: Renders every bar in a `<rect />` element.
114
+ * - `svg-batch`: Batch renders bars in `<path />` elements for better performance with large datasets, at the cost of some limitations.
115
+ * Read more: https://mui.com/x/react-charts/bars/#performance
116
+ *
117
+ * @default 'svg-single'
118
+ */
119
+ renderer: PropTypes.oneOf(['svg-batch', 'svg-single']),
177
120
  /**
178
121
  * If `true`, animations are skipped.
179
122
  * @default undefined
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ interface BarGroupProps extends React.HTMLAttributes<SVGGElement> {
3
+ skipAnimation: boolean;
4
+ layout: 'horizontal' | 'vertical' | undefined;
5
+ xOrigin: number;
6
+ yOrigin: number;
7
+ }
8
+ export declare function BarGroup({
9
+ skipAnimation,
10
+ layout,
11
+ xOrigin,
12
+ yOrigin,
13
+ ...props
14
+ }: BarGroupProps): import("react/jsx-runtime").JSX.Element;
15
+ export {};
@@ -0,0 +1,134 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["skipAnimation", "layout", "xOrigin", "yOrigin"],
4
+ _excluded2 = ["children", "layout", "xOrigin", "yOrigin"];
5
+ import { styled } from '@mui/material/styles';
6
+ import * as React from 'react';
7
+ import useId from '@mui/utils/useId';
8
+ import { useStore } from "../../internals/store/useStore.js";
9
+ import { selectorChartDrawingArea } from "../../internals/plugins/corePlugins/useChartDimensions/index.js";
10
+ import { ANIMATION_DURATION_MS } from "../../internals/animation/animation.js";
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ const PathGroup = styled('g')({
13
+ '&[data-faded="true"]': {
14
+ opacity: 0.3
15
+ },
16
+ '& path': {
17
+ /* The browser must do hit testing to know which element a pointer is interacting with.
18
+ * With many data points, we create many paths causing significant time to be spent in the hit test phase.
19
+ * To fix this issue, we disable pointer events for the descendant paths.
20
+ *
21
+ * Ideally, users should be able to override this in case they need pointer events to be enabled,
22
+ * but it can affect performance negatively, especially with many data points. */
23
+ pointerEvents: 'none'
24
+ }
25
+ });
26
+ export function BarGroup(_ref) {
27
+ let {
28
+ skipAnimation,
29
+ layout,
30
+ xOrigin,
31
+ yOrigin
32
+ } = _ref,
33
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
34
+ if (skipAnimation) {
35
+ return /*#__PURE__*/_jsx(PathGroup, _extends({}, props));
36
+ }
37
+ return /*#__PURE__*/_jsx(AnimatedGroup, _extends({}, props, {
38
+ layout: layout,
39
+ xOrigin: xOrigin,
40
+ yOrigin: yOrigin
41
+ }));
42
+ }
43
+ const AnimatedRect = styled('rect')({
44
+ '@keyframes scaleInX': {
45
+ from: {
46
+ transform: 'scaleX(0)'
47
+ },
48
+ to: {
49
+ transform: 'scaleX(1)'
50
+ }
51
+ },
52
+ '@keyframes scaleInY': {
53
+ from: {
54
+ transform: 'scaleY(0)'
55
+ },
56
+ to: {
57
+ transform: 'scaleY(1)'
58
+ }
59
+ },
60
+ animationDuration: `${ANIMATION_DURATION_MS}ms`,
61
+ animationFillMode: 'forwards',
62
+ '&[data-orientation="horizontal"]': {
63
+ animationName: 'scaleInX'
64
+ },
65
+ '&[data-orientation="vertical"]': {
66
+ animationName: 'scaleInY'
67
+ }
68
+ });
69
+ function AnimatedGroup(_ref2) {
70
+ let {
71
+ children,
72
+ layout,
73
+ xOrigin,
74
+ yOrigin
75
+ } = _ref2,
76
+ props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
77
+ const store = useStore();
78
+ const drawingArea = store.use(selectorChartDrawingArea);
79
+ const clipPathId = useId();
80
+ const animateChildren = [];
81
+ if (layout === 'horizontal') {
82
+ animateChildren.push(/*#__PURE__*/_jsx(AnimatedRect, {
83
+ "data-orientation": "horizontal",
84
+ x: drawingArea.left,
85
+ width: xOrigin - drawingArea.left,
86
+ y: drawingArea.top,
87
+ height: drawingArea.height,
88
+ style: {
89
+ transformOrigin: `${xOrigin}px ${drawingArea.top + drawingArea.height / 2}px`
90
+ }
91
+ }, "left"));
92
+ animateChildren.push(/*#__PURE__*/_jsx(AnimatedRect, {
93
+ "data-orientation": "horizontal",
94
+ x: xOrigin,
95
+ width: drawingArea.left + drawingArea.width - xOrigin,
96
+ y: drawingArea.top,
97
+ height: drawingArea.height,
98
+ style: {
99
+ transformOrigin: `${xOrigin}px ${drawingArea.top + drawingArea.height / 2}px`
100
+ }
101
+ }, "right"));
102
+ } else {
103
+ animateChildren.push(/*#__PURE__*/_jsx(AnimatedRect, {
104
+ "data-orientation": "vertical",
105
+ x: drawingArea.left,
106
+ width: drawingArea.width,
107
+ y: drawingArea.top,
108
+ height: yOrigin - drawingArea.top,
109
+ style: {
110
+ transformOrigin: `${drawingArea.left + drawingArea.width / 2}px ${yOrigin}px`
111
+ }
112
+ }, "top"));
113
+ animateChildren.push(/*#__PURE__*/_jsx(AnimatedRect, {
114
+ "data-orientation": "vertical",
115
+ x: drawingArea.left,
116
+ width: drawingArea.width,
117
+ y: yOrigin,
118
+ height: drawingArea.top + drawingArea.height - yOrigin,
119
+ style: {
120
+ transformOrigin: `${drawingArea.left + drawingArea.width / 2}px ${yOrigin}px`
121
+ }
122
+ }, "bottom"));
123
+ }
124
+ return /*#__PURE__*/_jsxs(React.Fragment, {
125
+ children: [/*#__PURE__*/_jsx("clipPath", {
126
+ id: clipPathId,
127
+ children: animateChildren
128
+ }), /*#__PURE__*/_jsx(PathGroup, _extends({
129
+ clipPath: `url(#${clipPathId})`
130
+ }, props, {
131
+ children: children
132
+ }))]
133
+ });
134
+ }
@@ -0,0 +1,12 @@
1
+ import type { BarItemIdentifier } from "../../models/index.js";
2
+ import { type IndividualBarPlotProps } from "../IndividualBarPlot.js";
3
+ interface BatchBarPlotProps extends Omit<IndividualBarPlotProps, 'onItemClick'> {
4
+ onItemClick?: (event: MouseEvent, barItemIdentifier: BarItemIdentifier) => void;
5
+ }
6
+ export declare function BatchBarPlot({
7
+ completedData,
8
+ borderRadius,
9
+ onItemClick,
10
+ skipAnimation
11
+ }: BatchBarPlotProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -0,0 +1,133 @@
1
+ import * as React from 'react';
2
+ import { useSvgRef } from "../../hooks/index.js";
3
+ import { useUtilityClasses } from "../barClasses.js";
4
+ import { useChartContext } from "../../context/ChartProvider/useChartContext.js";
5
+ import { selectorChartIsSeriesFaded, selectorChartIsSeriesHighlighted, selectorChartSeriesHighlightedItem, selectorChartSeriesUnfadedItem } from "../../internals/plugins/featurePlugins/useChartHighlight/index.js";
6
+ import { useRegisterItemClickHandlers } from "../useRegisterItemClickHandlers.js";
7
+ import { createPath, useCreateBarPaths } from "./useCreateBarPaths.js";
8
+ import { BarGroup } from "./BarGroup.js";
9
+ import { useRegisterPointerInteractions } from "../../internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js";
10
+ import { selectorBarItemAtPosition } from "../../internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js";
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ export function BatchBarPlot({
13
+ completedData,
14
+ borderRadius = 0,
15
+ onItemClick,
16
+ skipAnimation = false
17
+ }) {
18
+ const prevCursorRef = React.useRef(null);
19
+ const svgRef = useSvgRef();
20
+ const onItemEnter = onItemClick ? () => {
21
+ const svg = svgRef.current;
22
+ if (!svg) {
23
+ return;
24
+ }
25
+ if (prevCursorRef.current == null) {
26
+ prevCursorRef.current = svg.style.cursor;
27
+ // eslint-disable-next-line react-compiler/react-compiler
28
+ svg.style.cursor = 'pointer';
29
+ }
30
+ } : undefined;
31
+ const onItemLeave = onItemClick ? () => {
32
+ const svg = svgRef.current;
33
+ if (!svg) {
34
+ return;
35
+ }
36
+ if (prevCursorRef.current != null) {
37
+ svg.style.cursor = prevCursorRef.current;
38
+ prevCursorRef.current = null;
39
+ }
40
+ } : undefined;
41
+ useRegisterPointerInteractions(selectorBarItemAtPosition, onItemEnter, onItemLeave);
42
+ useRegisterItemClickHandlers(onItemClick);
43
+ return /*#__PURE__*/_jsx(React.Fragment, {
44
+ children: completedData.map(series => /*#__PURE__*/_jsx(SeriesBatchPlot, {
45
+ series: series,
46
+ borderRadius: borderRadius,
47
+ skipAnimation: skipAnimation
48
+ }, series.seriesId))
49
+ });
50
+ }
51
+ const MemoFadedHighlightedBars = /*#__PURE__*/React.memo(FadedHighlightedBars);
52
+ if (process.env.NODE_ENV !== "production") MemoFadedHighlightedBars.displayName = "MemoFadedHighlightedBars";
53
+ function SeriesBatchPlot({
54
+ series,
55
+ borderRadius,
56
+ skipAnimation
57
+ }) {
58
+ const classes = useUtilityClasses();
59
+ const {
60
+ store
61
+ } = useChartContext();
62
+ const isSeriesHighlighted = store.use(selectorChartIsSeriesHighlighted, series.seriesId);
63
+ const isSeriesFaded = store.use(selectorChartIsSeriesFaded, series.seriesId);
64
+ return /*#__PURE__*/_jsxs(React.Fragment, {
65
+ children: [/*#__PURE__*/_jsx(BarGroup, {
66
+ className: classes.series,
67
+ "data-series": series.seriesId,
68
+ layout: series.layout,
69
+ xOrigin: series.xOrigin,
70
+ yOrigin: series.yOrigin,
71
+ skipAnimation: skipAnimation,
72
+ "data-faded": isSeriesFaded || undefined,
73
+ "data-highlighted": isSeriesHighlighted || undefined,
74
+ children: /*#__PURE__*/_jsx(BatchBarSeriesPlot, {
75
+ processedSeries: series,
76
+ borderRadius: borderRadius
77
+ })
78
+ }), /*#__PURE__*/_jsx(MemoFadedHighlightedBars, {
79
+ processedSeries: series,
80
+ borderRadius: borderRadius
81
+ })]
82
+ });
83
+ }
84
+ function BatchBarSeriesPlot({
85
+ processedSeries,
86
+ borderRadius
87
+ }) {
88
+ const paths = useCreateBarPaths(processedSeries, borderRadius);
89
+ const children = [];
90
+ let i = 0;
91
+ for (const [fill, dArray] of paths.entries()) {
92
+ for (const d of dArray) {
93
+ children.push(/*#__PURE__*/_jsx("path", {
94
+ fill: fill,
95
+ d: d
96
+ }, i));
97
+ i += 1;
98
+ }
99
+ }
100
+ return /*#__PURE__*/_jsx(React.Fragment, {
101
+ children: children
102
+ });
103
+ }
104
+ function FadedHighlightedBars({
105
+ processedSeries,
106
+ borderRadius
107
+ }) {
108
+ const {
109
+ store
110
+ } = useChartContext();
111
+ const seriesHighlightedDataIndex = store.use(selectorChartSeriesHighlightedItem, processedSeries.seriesId);
112
+ const seriesUnfadedDataIndex = store.use(selectorChartSeriesUnfadedItem, processedSeries.seriesId);
113
+ const seriesHighlightedItem = seriesHighlightedDataIndex != null ? processedSeries.data.find(v => v.dataIndex === seriesHighlightedDataIndex) || null : null;
114
+ const seriesUnfadedItem = seriesUnfadedDataIndex != null ? processedSeries.data.find(v => v.dataIndex === seriesUnfadedDataIndex) || null : null;
115
+ const siblings = [];
116
+ if (seriesHighlightedItem != null) {
117
+ siblings.push(/*#__PURE__*/_jsx("path", {
118
+ fill: seriesHighlightedItem.color,
119
+ filter: "brightness(120%)",
120
+ "data-highlighted": true,
121
+ d: createPath(seriesHighlightedItem, borderRadius)
122
+ }, `highlighted-${processedSeries.seriesId}`));
123
+ }
124
+ if (seriesUnfadedItem != null) {
125
+ siblings.push(/*#__PURE__*/_jsx("path", {
126
+ fill: seriesUnfadedItem.color,
127
+ d: createPath(seriesUnfadedItem, borderRadius)
128
+ }, `unfaded-${seriesUnfadedItem.seriesId}`));
129
+ }
130
+ return /*#__PURE__*/_jsx(React.Fragment, {
131
+ children: siblings
132
+ });
133
+ }