@mui/x-charts 8.5.3 → 8.7.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 (228) hide show
  1. package/BarChart/AnimatedBarElement.js +3 -1
  2. package/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
  3. package/BarChart/BarLabel/BarLabelPlot.js +33 -25
  4. package/BarChart/BarPlot.js +59 -183
  5. package/BarChart/barClasses.d.ts +12 -0
  6. package/BarChart/barClasses.js +25 -0
  7. package/BarChart/index.d.ts +3 -1
  8. package/BarChart/index.js +23 -1
  9. package/BarChart/types.d.ts +5 -1
  10. package/BarChart/useBarPlotData.d.ts +8 -0
  11. package/BarChart/useBarPlotData.js +146 -0
  12. package/CHANGELOG.md +210 -0
  13. package/ChartContainer/ChartContainer.d.ts +1 -21
  14. package/ChartContainer/ChartContainer.js +0 -8
  15. package/ChartContainer/index.d.ts +8 -1
  16. package/ChartsLegend/ChartsLegend.js +1 -0
  17. package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  18. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  19. package/ChartsReferenceLine/ChartsXReferenceLine.js +48 -1
  20. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  21. package/ChartsReferenceLine/ChartsYReferenceLine.js +48 -1
  22. package/ChartsReferenceLine/index.d.ts +3 -1
  23. package/ChartsSurface/ChartsSurface.js +2 -1
  24. package/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  25. package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  26. package/ChartsTooltip/utils.js +18 -29
  27. package/ChartsXAxis/ChartsXAxis.js +4 -108
  28. package/ChartsXAxis/getVisibleLabels.d.ts +14 -0
  29. package/ChartsXAxis/getVisibleLabels.js +71 -0
  30. package/ChartsXAxis/shortenLabels.d.ts +4 -0
  31. package/ChartsXAxis/shortenLabels.js +48 -0
  32. package/ChartsYAxis/ChartsYAxis.js +2 -39
  33. package/ChartsYAxis/shortenLabels.d.ts +4 -0
  34. package/ChartsYAxis/shortenLabels.js +46 -0
  35. package/LineChart/AnimatedArea.js +4 -1
  36. package/LineChart/AnimatedLine.js +4 -1
  37. package/LineChart/AreaPlot.js +5 -115
  38. package/LineChart/CircleMarkElement.js +4 -1
  39. package/LineChart/LinePlot.js +5 -99
  40. package/LineChart/MarkElement.js +4 -1
  41. package/LineChart/MarkPlot.js +1 -0
  42. package/LineChart/useAreaPlotData.d.ts +12 -0
  43. package/LineChart/useAreaPlotData.js +125 -0
  44. package/LineChart/useLinePlotData.d.ts +11 -0
  45. package/LineChart/useLinePlotData.js +108 -0
  46. package/PieChart/PieArc.js +3 -1
  47. package/PieChart/PiePlot.js +6 -0
  48. package/PieChart/index.d.ts +3 -1
  49. package/PieChart/index.js +18 -1
  50. package/PieChart/pieClasses.d.ts +12 -0
  51. package/PieChart/pieClasses.js +24 -0
  52. package/ScatterChart/Scatter.js +22 -48
  53. package/ScatterChart/useScatterPlotData.d.ts +8 -0
  54. package/ScatterChart/useScatterPlotData.js +33 -0
  55. package/Toolbar/ToolbarButton.js +2 -0
  56. package/context/ChartApi.d.ts +22 -0
  57. package/context/ChartApi.js +5 -0
  58. package/context/ChartProvider/ChartContext.js +1 -0
  59. package/context/index.d.ts +2 -1
  60. package/context/useChartApiContext.d.ts +1 -1
  61. package/esm/BarChart/AnimatedBarElement.js +3 -1
  62. package/esm/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
  63. package/esm/BarChart/BarLabel/BarLabelPlot.js +33 -25
  64. package/esm/BarChart/BarPlot.js +60 -185
  65. package/esm/BarChart/barClasses.d.ts +12 -0
  66. package/esm/BarChart/barClasses.js +15 -0
  67. package/esm/BarChart/index.d.ts +3 -1
  68. package/esm/BarChart/index.js +2 -1
  69. package/esm/BarChart/types.d.ts +5 -1
  70. package/esm/BarChart/useBarPlotData.d.ts +8 -0
  71. package/esm/BarChart/useBarPlotData.js +139 -0
  72. package/esm/ChartContainer/ChartContainer.d.ts +1 -21
  73. package/esm/ChartContainer/ChartContainer.js +0 -8
  74. package/esm/ChartContainer/index.d.ts +8 -1
  75. package/esm/ChartContainer/index.js +6 -1
  76. package/esm/ChartsLegend/ChartsLegend.js +1 -0
  77. package/esm/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  78. package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  79. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +47 -0
  80. package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  81. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +47 -0
  82. package/esm/ChartsReferenceLine/index.d.ts +3 -1
  83. package/esm/ChartsReferenceLine/index.js +2 -1
  84. package/esm/ChartsSurface/ChartsSurface.js +2 -1
  85. package/esm/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  86. package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  87. package/esm/ChartsTooltip/utils.js +18 -29
  88. package/esm/ChartsXAxis/ChartsXAxis.js +2 -106
  89. package/esm/ChartsXAxis/getVisibleLabels.d.ts +14 -0
  90. package/esm/ChartsXAxis/getVisibleLabels.js +67 -0
  91. package/esm/ChartsXAxis/shortenLabels.d.ts +4 -0
  92. package/esm/ChartsXAxis/shortenLabels.js +42 -0
  93. package/esm/ChartsYAxis/ChartsYAxis.js +1 -38
  94. package/esm/ChartsYAxis/shortenLabels.d.ts +4 -0
  95. package/esm/ChartsYAxis/shortenLabels.js +41 -0
  96. package/esm/LineChart/AnimatedArea.js +4 -1
  97. package/esm/LineChart/AnimatedLine.js +4 -1
  98. package/esm/LineChart/AreaPlot.js +5 -115
  99. package/esm/LineChart/CircleMarkElement.js +4 -1
  100. package/esm/LineChart/LinePlot.js +5 -99
  101. package/esm/LineChart/MarkElement.js +4 -1
  102. package/esm/LineChart/MarkPlot.js +1 -0
  103. package/esm/LineChart/useAreaPlotData.d.ts +12 -0
  104. package/esm/LineChart/useAreaPlotData.js +118 -0
  105. package/esm/LineChart/useLinePlotData.d.ts +11 -0
  106. package/esm/LineChart/useLinePlotData.js +101 -0
  107. package/esm/PieChart/PieArc.js +3 -1
  108. package/esm/PieChart/PiePlot.js +6 -0
  109. package/esm/PieChart/index.d.ts +3 -1
  110. package/esm/PieChart/index.js +2 -1
  111. package/esm/PieChart/pieClasses.d.ts +12 -0
  112. package/esm/PieChart/pieClasses.js +15 -0
  113. package/esm/ScatterChart/Scatter.js +23 -49
  114. package/esm/ScatterChart/useScatterPlotData.d.ts +8 -0
  115. package/esm/ScatterChart/useScatterPlotData.js +26 -0
  116. package/esm/Toolbar/ToolbarButton.js +2 -0
  117. package/esm/context/ChartApi.d.ts +22 -0
  118. package/esm/context/ChartApi.js +1 -0
  119. package/esm/context/ChartProvider/ChartContext.js +2 -0
  120. package/esm/context/index.d.ts +2 -1
  121. package/esm/context/useChartApiContext.d.ts +1 -1
  122. package/esm/hooks/useInteractionItemProps.d.ts +14 -9
  123. package/esm/hooks/useInteractionItemProps.js +28 -28
  124. package/esm/index.d.ts +2 -1
  125. package/esm/index.js +2 -2
  126. package/esm/internals/components/NotRendered.d.ts +9 -0
  127. package/esm/internals/components/NotRendered.js +10 -0
  128. package/esm/internals/index.d.ts +6 -0
  129. package/esm/internals/index.js +6 -0
  130. package/esm/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  131. package/esm/internals/plugins/corePlugins/corePlugins.js +2 -1
  132. package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  133. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -1
  134. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  135. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +2 -2
  136. package/esm/internals/plugins/corePlugins/useChartId/useChartId.js +2 -0
  137. package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  138. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  139. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.js +1 -0
  140. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  141. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +77 -0
  142. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  143. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +1 -0
  144. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  145. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  146. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  147. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  148. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  149. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  150. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  151. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +52 -36
  152. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  153. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  154. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +47 -30
  155. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  156. package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  157. package/esm/internals/store/useCharts.d.ts +1 -1
  158. package/esm/locales/elGR.d.ts +19 -0
  159. package/esm/locales/elGR.js +15 -0
  160. package/esm/locales/enUS.d.ts +3 -0
  161. package/esm/locales/enUS.js +8 -2
  162. package/esm/locales/frFR.d.ts +3 -0
  163. package/esm/locales/frFR.js +7 -0
  164. package/esm/locales/index.d.ts +1 -0
  165. package/esm/locales/index.js +1 -0
  166. package/esm/locales/ptBR.d.ts +3 -0
  167. package/esm/locales/ptBR.js +7 -1
  168. package/esm/locales/ptPT.d.ts +3 -0
  169. package/esm/locales/ptPT.js +7 -1
  170. package/esm/locales/utils/chartsLocaleTextApi.d.ts +17 -0
  171. package/esm/locales/utils/getChartsLocalization.d.ts +3 -0
  172. package/esm/locales/utils/imageMimeTypes.d.ts +2 -0
  173. package/esm/locales/utils/imageMimeTypes.js +5 -0
  174. package/esm/models/slots/chartsBaseSlotProps.d.ts +4 -0
  175. package/hooks/useInteractionItemProps.d.ts +14 -9
  176. package/hooks/useInteractionItemProps.js +29 -28
  177. package/index.d.ts +2 -1
  178. package/index.js +37 -11
  179. package/internals/components/NotRendered.d.ts +9 -0
  180. package/internals/components/NotRendered.js +16 -0
  181. package/internals/index.d.ts +6 -0
  182. package/internals/index.js +56 -0
  183. package/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  184. package/internals/plugins/corePlugins/corePlugins.js +2 -1
  185. package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  186. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -1
  187. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  188. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +2 -2
  189. package/internals/plugins/corePlugins/useChartId/useChartId.js +1 -0
  190. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  191. package/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  192. package/internals/plugins/corePlugins/useChartInteractionListener/index.js +12 -0
  193. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  194. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +84 -0
  195. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  196. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +5 -0
  197. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  198. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  199. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  200. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  201. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  202. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  203. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  204. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +52 -36
  205. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  206. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  207. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +46 -30
  208. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  209. package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  210. package/internals/store/useCharts.d.ts +1 -1
  211. package/locales/elGR.d.ts +19 -0
  212. package/locales/elGR.js +21 -0
  213. package/locales/enUS.d.ts +3 -0
  214. package/locales/enUS.js +8 -2
  215. package/locales/frFR.d.ts +3 -0
  216. package/locales/frFR.js +7 -0
  217. package/locales/index.d.ts +1 -0
  218. package/locales/index.js +11 -0
  219. package/locales/ptBR.d.ts +3 -0
  220. package/locales/ptBR.js +7 -1
  221. package/locales/ptPT.d.ts +3 -0
  222. package/locales/ptPT.js +7 -1
  223. package/locales/utils/chartsLocaleTextApi.d.ts +17 -0
  224. package/locales/utils/getChartsLocalization.d.ts +3 -0
  225. package/locales/utils/imageMimeTypes.d.ts +2 -0
  226. package/locales/utils/imageMimeTypes.js +11 -0
  227. package/models/slots/chartsBaseSlotProps.d.ts +4 -0
  228. package/package.json +3 -2
@@ -12,15 +12,15 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _useSlotProps2 = _interopRequireDefault(require("@mui/utils/useSlotProps"));
15
- var _useScale = require("../hooks/useScale");
16
15
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
17
16
  var _useStore = require("../internals/store/useStore");
18
17
  var _useSelector = require("../internals/store/useSelector");
19
18
  var _useItemHighlightedGetter = require("../hooks/useItemHighlightedGetter");
20
19
  var _useChartVoronoi = require("../internals/plugins/featurePlugins/useChartVoronoi");
21
- var _ChartProvider = require("../context/ChartProvider");
22
20
  var _ScatterMarker = require("./ScatterMarker");
23
21
  var _scatterClasses = require("./scatterClasses");
22
+ var _useScatterPlotData = require("./useScatterPlotData");
23
+ var _ChartProvider = require("../context/ChartProvider");
24
24
  var _jsxRuntime = require("react/jsx-runtime");
25
25
  const _excluded = ["ownerState"];
26
26
  /**
@@ -55,37 +55,7 @@ function Scatter(props) {
55
55
  isFaded,
56
56
  isHighlighted
57
57
  } = (0, _useItemHighlightedGetter.useItemHighlightedGetter)();
58
- const cleanData = React.useMemo(() => {
59
- const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
60
- const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
61
- const temp = [];
62
- for (let i = 0; i < series.data.length; i += 1) {
63
- const scatterPoint = series.data[i];
64
- const x = getXPosition(scatterPoint.x);
65
- const y = getYPosition(scatterPoint.y);
66
- const isInRange = instance.isPointInside(x, y);
67
- if (isInRange) {
68
- const currentItem = {
69
- seriesId: series.id,
70
- dataIndex: i
71
- };
72
- const isItemHighlighted = isHighlighted(currentItem);
73
- temp.push({
74
- x,
75
- y,
76
- isHighlighted: isItemHighlighted,
77
- isFaded: !isItemHighlighted && isFaded(currentItem),
78
- id: scatterPoint.id,
79
- seriesId: series.id,
80
- type: 'scatter',
81
- dataIndex: i,
82
- color: colorGetter ? colorGetter(i) : color
83
- });
84
- }
85
- }
86
- return temp;
87
- }, [xScale, yScale, series.data, series.id, isHighlighted, isFaded, colorGetter, color, instance]);
88
- const interactionItemProps = (0, _useInteractionItemProps.useInteractionAllItemProps)(cleanData, skipInteractionHandlers);
58
+ const scatterPlotData = (0, _useScatterPlotData.useScatterPlotData)(series, xScale, yScale, instance.isPointInside);
89
59
  const Marker = slots?.marker ?? _ScatterMarker.ScatterMarker;
90
60
  const _useSlotProps = (0, _useSlotProps2.default)({
91
61
  elementType: Marker,
@@ -101,21 +71,25 @@ function Scatter(props) {
101
71
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
102
72
  "data-series": series.id,
103
73
  className: classes.root,
104
- children: cleanData.map((dataPoint, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Marker, (0, _extends2.default)({
105
- dataIndex: dataPoint.dataIndex,
106
- color: dataPoint.color,
107
- isHighlighted: dataPoint.isHighlighted,
108
- isFaded: dataPoint.isFaded,
109
- x: dataPoint.x,
110
- y: dataPoint.y,
111
- onClick: onItemClick && (event => onItemClick(event, {
112
- type: 'scatter',
113
- seriesId: series.id,
114
- dataIndex: dataPoint.dataIndex
115
- })),
116
- "data-highlighted": dataPoint.isHighlighted || undefined,
117
- "data-faded": dataPoint.isFaded || undefined
118
- }, interactionItemProps[i], markerProps), dataPoint.id ?? dataPoint.dataIndex))
74
+ children: scatterPlotData.map((dataPoint, i) => {
75
+ const isItemHighlighted = isHighlighted(dataPoint);
76
+ const isItemFaded = !isItemHighlighted && isFaded(dataPoint);
77
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Marker, (0, _extends2.default)({
78
+ dataIndex: dataPoint.dataIndex,
79
+ color: colorGetter ? colorGetter(i) : color,
80
+ isHighlighted: isItemHighlighted,
81
+ isFaded: isItemFaded,
82
+ x: dataPoint.x,
83
+ y: dataPoint.y,
84
+ onClick: onItemClick && (event => onItemClick(event, {
85
+ type: 'scatter',
86
+ seriesId: series.id,
87
+ dataIndex: dataPoint.dataIndex
88
+ })),
89
+ "data-highlighted": isItemHighlighted || undefined,
90
+ "data-faded": isItemFaded || undefined
91
+ }, skipInteractionHandlers ? undefined : (0, _useInteractionItemProps.getInteractionItemProps)(instance, dataPoint), markerProps), dataPoint.id ?? dataPoint.dataIndex);
92
+ })
119
93
  });
120
94
  }
121
95
  process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
@@ -0,0 +1,8 @@
1
+ import { SeriesId } from "../models/seriesType/common.js";
2
+ import { D3Scale } from "../models/axis.js";
3
+ import { DefaultizedScatterSeriesType, ScatterValueType } from "../models/index.js";
4
+ export declare function useScatterPlotData(series: DefaultizedScatterSeriesType, xScale: D3Scale, yScale: D3Scale, isPointInside: (x: number, y: number) => boolean): (ScatterValueType & {
5
+ dataIndex: number;
6
+ seriesId: SeriesId;
7
+ type: "scatter";
8
+ })[];
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useScatterPlotData = useScatterPlotData;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _hooks = require("../hooks");
10
+ function useScatterPlotData(series, xScale, yScale, isPointInside) {
11
+ return React.useMemo(() => {
12
+ const getXPosition = (0, _hooks.getValueToPositionMapper)(xScale);
13
+ const getYPosition = (0, _hooks.getValueToPositionMapper)(yScale);
14
+ const temp = [];
15
+ for (let i = 0; i < series.data.length; i += 1) {
16
+ const scatterPoint = series.data[i];
17
+ const x = getXPosition(scatterPoint.x);
18
+ const y = getYPosition(scatterPoint.y);
19
+ const isInRange = isPointInside(x, y);
20
+ if (isInRange) {
21
+ temp.push({
22
+ x,
23
+ y,
24
+ id: scatterPoint.id,
25
+ seriesId: series.id,
26
+ type: 'scatter',
27
+ dataIndex: i
28
+ });
29
+ }
30
+ }
31
+ return temp;
32
+ }, [xScale, yScale, series.data, series.id, isPointInside]);
33
+ }
@@ -51,10 +51,12 @@ process.env.NODE_ENV !== "production" ? ToolbarButton.propTypes = {
51
51
  // ----------------------------------------------------------------------
52
52
  className: _propTypes.default.string,
53
53
  disabled: _propTypes.default.bool,
54
+ id: _propTypes.default.string,
54
55
  /**
55
56
  * A function to customize the rendering of the component.
56
57
  */
57
58
  render: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func]),
59
+ size: _propTypes.default.oneOf(['large', 'medium', 'small']),
58
60
  style: _propTypes.default.object,
59
61
  tabIndex: _propTypes.default.number
60
62
  } : void 0;
@@ -0,0 +1,22 @@
1
+ import type { PieChartPluginSignatures } from "../PieChart/PieChart.plugins.js";
2
+ import type { BarChartPluginsSignatures } from "../BarChart/BarChart.plugins.js";
3
+ import type { ScatterChartPluginsSignatures } from "../ScatterChart/ScatterChart.plugins.js";
4
+ import type { LineChartPluginsSignatures } from "../LineChart/LineChart.plugins.js";
5
+ import type { AllPluginSignatures, DefaultPluginSignatures } from "../internals/plugins/allPlugins.js";
6
+ import type { ChartAnyPluginSignature } from "../internals/plugins/models/plugin.js";
7
+ import type { ChartPublicAPI } from "../internals/plugins/models/index.js";
8
+ export type PluginsPerSeriesType = {
9
+ line: LineChartPluginsSignatures;
10
+ scatter: ScatterChartPluginsSignatures;
11
+ bar: BarChartPluginsSignatures;
12
+ pie: PieChartPluginSignatures;
13
+ composition: DefaultPluginSignatures;
14
+ };
15
+ /**
16
+ * The API of the chart `apiRef` object.
17
+ * The chart type can be passed as the first generic parameter to narrow down the API to the specific chart type.
18
+ * @example ChartApi<'bar'>
19
+ * If the chart is being created using composition, the `composition` value can be used.
20
+ * @example ChartApi<'composition'>
21
+ */
22
+ export type ChartApi<TSeries extends keyof PluginsPerSeriesType | undefined = undefined, TSignatures extends readonly ChartAnyPluginSignature[] = (TSeries extends keyof PluginsPerSeriesType ? PluginsPerSeriesType[TSeries] : AllPluginSignatures)> = ChartPublicAPI<TSignatures>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ 'use client';
2
3
 
3
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
5
  Object.defineProperty(exports, "__esModule", {
@@ -1,2 +1,3 @@
1
1
  export type { HighlightScope, FadeOptions, HighlightItemData, HighlightOptions } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
2
- export * from "./useChartApiContext.js";
2
+ export * from "./useChartApiContext.js";
3
+ export type { ChartApi } from "./ChartApi.js";
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ChartApi } from "../ChartContainer/index.js";
2
+ import { ChartApi } from "./ChartApi.js";
3
3
  /**
4
4
  * The `useChartApiContext` hook provides access to the chart API.
5
5
  * This is only available when the chart is rendered within a chart or a `ChartDataProvider` component.
@@ -14,6 +14,8 @@ export function AnimatedBarElement(props) {
14
14
  const animatedProps = useAnimateBar(props);
15
15
  return /*#__PURE__*/_jsx("rect", _extends({}, other, {
16
16
  filter: ownerState.isHighlighted ? 'brightness(120%)' : undefined,
17
- opacity: ownerState.isFaded ? 0.3 : 1
17
+ opacity: ownerState.isFaded ? 0.3 : 1,
18
+ "data-highlighted": ownerState.isHighlighted || undefined,
19
+ "data-faded": ownerState.isFaded || undefined
18
20
  }, animatedProps));
19
21
  }
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
- import type { CompletedBarData } from "../types.js";
2
+ import type { ProcessedBarSeriesData } from "../types.js";
3
3
  import { BarLabelItemProps } from "./BarLabelItem.js";
4
4
  type BarLabelPlotProps = {
5
- bars: CompletedBarData[];
5
+ bars: ProcessedBarSeriesData[];
6
6
  skipAnimation?: boolean;
7
7
  barLabel?: BarLabelItemProps['barLabel'];
8
8
  };
@@ -3,6 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["bars", "skipAnimation"];
4
4
  import * as React from 'react';
5
5
  import { BarLabelItem } from "./BarLabelItem.js";
6
+ import { useUtilityClasses } from "../barClasses.js";
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  /**
8
9
  * @ignore - internal component.
@@ -13,33 +14,40 @@ function BarLabelPlot(props) {
13
14
  skipAnimation
14
15
  } = props,
15
16
  other = _objectWithoutPropertiesLoose(props, _excluded);
17
+ const classes = useUtilityClasses();
16
18
  return /*#__PURE__*/_jsx(React.Fragment, {
17
- children: bars.map(({
18
- xOrigin,
19
- yOrigin,
20
- x,
21
- y,
19
+ children: bars.flatMap(({
22
20
  seriesId,
23
- dataIndex,
24
- color,
25
- value,
26
- width,
27
- height,
28
- layout
29
- }) => /*#__PURE__*/_jsx(BarLabelItem, _extends({
30
- seriesId: seriesId,
31
- dataIndex: dataIndex,
32
- value: value,
33
- color: color,
34
- xOrigin: xOrigin,
35
- yOrigin: yOrigin,
36
- x: x,
37
- y: y,
38
- width: width,
39
- height: height,
40
- skipAnimation: skipAnimation ?? false,
41
- layout: layout ?? 'vertical'
42
- }, other), `${seriesId}-${dataIndex}`))
21
+ data
22
+ }) => /*#__PURE__*/_jsx("g", {
23
+ className: classes.seriesLabels,
24
+ "data-series": seriesId,
25
+ children: data.map(({
26
+ xOrigin,
27
+ yOrigin,
28
+ x,
29
+ y,
30
+ dataIndex,
31
+ color,
32
+ value,
33
+ width,
34
+ height,
35
+ layout
36
+ }) => /*#__PURE__*/_jsx(BarLabelItem, _extends({
37
+ seriesId: seriesId,
38
+ dataIndex: dataIndex,
39
+ value: value,
40
+ color: color,
41
+ xOrigin: xOrigin,
42
+ yOrigin: yOrigin,
43
+ x: x,
44
+ y: y,
45
+ width: width,
46
+ height: height,
47
+ skipAnimation: skipAnimation ?? false,
48
+ layout: layout ?? 'vertical'
49
+ }, other), dataIndex))
50
+ }, seriesId))
43
51
  });
44
52
  }
45
53
  export { BarLabelPlot };
@@ -8,155 +8,14 @@ import PropTypes from 'prop-types';
8
8
  import { styled } from '@mui/material/styles';
9
9
  import { barElementClasses } from "./barElementClasses.js";
10
10
  import { BarElement } from "./BarElement.js";
11
- import getColor from "./seriesConfig/getColor.js";
12
- import { useChartId, useDrawingArea, useXAxes, useYAxes } from "../hooks/index.js";
11
+ import { useDrawingArea, useXAxes, useYAxes } from "../hooks/index.js";
13
12
  import { BarClipPath } from "./BarClipPath.js";
14
13
  import { BarLabelPlot } from "./BarLabel/BarLabelPlot.js";
15
- import { checkScaleErrors } from "./checkScaleErrors.js";
16
- import { useBarSeriesContext } from "../hooks/useBarSeries.js";
17
14
  import { useSkipAnimation } from "../hooks/useSkipAnimation.js";
18
15
  import { useInternalIsZoomInteracting } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting.js";
19
-
20
- /**
21
- * Solution of the equations
22
- * W = barWidth * N + offset * (N-1)
23
- * offset / (offset + barWidth) = r
24
- * @param bandWidth The width available to place bars.
25
- * @param numberOfGroups The number of bars to place in that space.
26
- * @param gapRatio The ratio of the gap between bars over the bar width.
27
- * @returns The bar width and the offset between bars.
28
- */
16
+ import { useBarPlotData } from "./useBarPlotData.js";
17
+ import { useUtilityClasses } from "./barClasses.js";
29
18
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
30
- function getBandSize({
31
- bandWidth: W,
32
- numberOfGroups: N,
33
- gapRatio: r
34
- }) {
35
- if (r === 0) {
36
- return {
37
- barWidth: W / N,
38
- offset: 0
39
- };
40
- }
41
- const barWidth = W / (N + (N - 1) * r);
42
- const offset = r * barWidth;
43
- return {
44
- barWidth,
45
- offset
46
- };
47
- }
48
- const useAggregatedData = () => {
49
- const seriesData = useBarSeriesContext() ?? {
50
- series: {},
51
- stackingGroups: [],
52
- seriesOrder: []
53
- };
54
- const drawingArea = useDrawingArea();
55
- const chartId = useChartId();
56
- const {
57
- series,
58
- stackingGroups
59
- } = seriesData;
60
- const {
61
- xAxis,
62
- xAxisIds
63
- } = useXAxes();
64
- const {
65
- yAxis,
66
- yAxisIds
67
- } = useYAxes();
68
- const defaultXAxisId = xAxisIds[0];
69
- const defaultYAxisId = yAxisIds[0];
70
- const masks = {};
71
- const data = stackingGroups.flatMap(({
72
- ids: groupIds
73
- }, groupIndex) => {
74
- const xMin = drawingArea.left;
75
- const xMax = drawingArea.left + drawingArea.width;
76
- const yMin = drawingArea.top;
77
- const yMax = drawingArea.top + drawingArea.height;
78
- return groupIds.flatMap(seriesId => {
79
- const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
80
- const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
81
- const xAxisConfig = xAxis[xAxisId];
82
- const yAxisConfig = yAxis[yAxisId];
83
- const verticalLayout = series[seriesId].layout === 'vertical';
84
- checkScaleErrors(verticalLayout, seriesId, series[seriesId], xAxisId, xAxis, yAxisId, yAxis);
85
- const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
86
- const xScale = xAxisConfig.scale;
87
- const yScale = yAxisConfig.scale;
88
- const colorGetter = getColor(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
89
- const bandWidth = baseScaleConfig.scale.bandwidth();
90
- const {
91
- barWidth,
92
- offset
93
- } = getBandSize({
94
- bandWidth,
95
- numberOfGroups: stackingGroups.length,
96
- gapRatio: baseScaleConfig.barGapRatio
97
- });
98
- const barOffset = groupIndex * (barWidth + offset);
99
- const {
100
- stackedData,
101
- data: currentSeriesData,
102
- layout
103
- } = series[seriesId];
104
- return baseScaleConfig.data.map((baseValue, dataIndex) => {
105
- if (currentSeriesData[dataIndex] == null) {
106
- return null;
107
- }
108
- const values = stackedData[dataIndex];
109
- const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
110
- const minValueCoord = Math.round(Math.min(...valueCoordinates));
111
- const maxValueCoord = Math.round(Math.max(...valueCoordinates));
112
- const stackId = series[seriesId].stack;
113
- const result = {
114
- seriesId,
115
- dataIndex,
116
- layout,
117
- x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
118
- y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
119
- xOrigin: xScale(0) ?? 0,
120
- yOrigin: yScale(0) ?? 0,
121
- height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
122
- width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
123
- color: colorGetter(dataIndex),
124
- value: currentSeriesData[dataIndex],
125
- maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
126
- };
127
- if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
128
- return null;
129
- }
130
- if (!masks[result.maskId]) {
131
- masks[result.maskId] = {
132
- id: result.maskId,
133
- width: 0,
134
- height: 0,
135
- hasNegative: false,
136
- hasPositive: false,
137
- layout: result.layout,
138
- xOrigin: xScale(0),
139
- yOrigin: yScale(0),
140
- x: 0,
141
- y: 0
142
- };
143
- }
144
- const mask = masks[result.maskId];
145
- mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
146
- mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
147
- mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
148
- mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
149
- mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
150
- mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
151
- return result;
152
- }).filter(rectangle => rectangle !== null);
153
- });
154
- });
155
- return {
156
- completedData: data,
157
- masksData: Object.values(masks)
158
- };
159
- };
160
19
  const BarPlotRoot = styled('g', {
161
20
  name: 'MuiBarPlot',
162
21
  slot: 'Root'
@@ -178,10 +37,6 @@ const BarPlotRoot = styled('g', {
178
37
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
179
38
  */
180
39
  function BarPlot(props) {
181
- const {
182
- completedData,
183
- masksData
184
- } = useAggregatedData();
185
40
  const {
186
41
  skipAnimation: inSkipAnimation,
187
42
  onItemClick,
@@ -191,8 +46,20 @@ function BarPlot(props) {
191
46
  other = _objectWithoutPropertiesLoose(props, _excluded);
192
47
  const isZoomInteracting = useInternalIsZoomInteracting();
193
48
  const skipAnimation = useSkipAnimation(isZoomInteracting || inSkipAnimation);
49
+ const {
50
+ xAxis: xAxes
51
+ } = useXAxes();
52
+ const {
53
+ yAxis: yAxes
54
+ } = useYAxes();
55
+ const {
56
+ completedData,
57
+ masksData
58
+ } = useBarPlotData(useDrawingArea(), xAxes, yAxes);
194
59
  const withoutBorderRadius = !borderRadius || borderRadius <= 0;
60
+ const classes = useUtilityClasses();
195
61
  return /*#__PURE__*/_jsxs(BarPlotRoot, {
62
+ className: classes.root,
196
63
  children: [!withoutBorderRadius && masksData.map(({
197
64
  id,
198
65
  x,
@@ -217,45 +84,53 @@ function BarPlot(props) {
217
84
  }, id);
218
85
  }), completedData.map(({
219
86
  seriesId,
220
- dataIndex,
221
- color,
222
- maskId,
223
- layout,
224
- x,
225
- xOrigin,
226
- y,
227
- yOrigin,
228
- width,
229
- height
87
+ data
230
88
  }) => {
231
- const barElement = /*#__PURE__*/_jsx(BarElement, _extends({
232
- id: seriesId,
233
- dataIndex: dataIndex,
234
- color: color,
235
- skipAnimation: skipAnimation ?? false,
236
- layout: layout ?? 'vertical',
237
- x: x,
238
- xOrigin: xOrigin,
239
- y: y,
240
- yOrigin: yOrigin,
241
- width: width,
242
- height: height
243
- }, other, {
244
- onClick: onItemClick && (event => {
245
- onItemClick(event, {
246
- type: 'bar',
247
- seriesId,
248
- dataIndex
249
- });
250
- })
251
- }), `${seriesId}-${dataIndex}`);
252
- if (withoutBorderRadius) {
253
- return barElement;
254
- }
255
89
  return /*#__PURE__*/_jsx("g", {
256
- clipPath: `url(#${maskId})`,
257
- children: barElement
258
- }, `${seriesId}-${dataIndex}`);
90
+ "data-series": seriesId,
91
+ className: classes.series,
92
+ children: data.map(({
93
+ dataIndex,
94
+ color,
95
+ maskId,
96
+ layout,
97
+ x,
98
+ xOrigin,
99
+ y,
100
+ yOrigin,
101
+ width,
102
+ height
103
+ }) => {
104
+ const barElement = /*#__PURE__*/_jsx(BarElement, _extends({
105
+ id: seriesId,
106
+ dataIndex: dataIndex,
107
+ color: color,
108
+ skipAnimation: skipAnimation ?? false,
109
+ layout: layout ?? 'vertical',
110
+ x: x,
111
+ xOrigin: xOrigin,
112
+ y: y,
113
+ yOrigin: yOrigin,
114
+ width: width,
115
+ height: height
116
+ }, other, {
117
+ onClick: onItemClick && (event => {
118
+ onItemClick(event, {
119
+ type: 'bar',
120
+ seriesId,
121
+ dataIndex
122
+ });
123
+ })
124
+ }), dataIndex);
125
+ if (withoutBorderRadius) {
126
+ return barElement;
127
+ }
128
+ return /*#__PURE__*/_jsx("g", {
129
+ clipPath: `url(#${maskId})`,
130
+ children: barElement
131
+ }, dataIndex);
132
+ })
133
+ }, seriesId);
259
134
  }), barLabel && /*#__PURE__*/_jsx(BarLabelPlot, _extends({
260
135
  bars: completedData,
261
136
  skipAnimation: skipAnimation,
@@ -0,0 +1,12 @@
1
+ export interface BarClasses {
2
+ /** Styles applied to the bar plot element. */
3
+ root: string;
4
+ /** Styles applied to the group surrounding a series' bar elements. */
5
+ series: string;
6
+ /** Styles applied to the group surrounding a series' labels. */
7
+ seriesLabels: string;
8
+ }
9
+ export type BarClassKey = keyof BarClasses;
10
+ export declare function getBarUtilityClass(slot: string): string;
11
+ export declare const barClasses: BarClasses;
12
+ export declare const useUtilityClasses: (classes?: Partial<BarClasses>) => Record<"root" | "series" | "seriesLabels", string>;
@@ -0,0 +1,15 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import composeClasses from '@mui/utils/composeClasses';
3
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
4
+ export function getBarUtilityClass(slot) {
5
+ return generateUtilityClass('MuiBar', slot);
6
+ }
7
+ export const barClasses = generateUtilityClasses('MuiBar', ['root', 'series', 'seriesLabels']);
8
+ export const useUtilityClasses = classes => {
9
+ const slots = {
10
+ root: ['root'],
11
+ series: ['series'],
12
+ seriesLabels: ['seriesLabels']
13
+ };
14
+ return composeClasses(slots, getBarUtilityClass, classes);
15
+ };
@@ -2,4 +2,6 @@ export * from "./BarChart.js";
2
2
  export * from "./BarPlot.js";
3
3
  export * from "./BarElement.js";
4
4
  export * from "./BarLabel/index.js";
5
- export * from "./barElementClasses.js";
5
+ export * from "./barElementClasses.js";
6
+ export { barClasses, getBarUtilityClass } from "./barClasses.js";
7
+ export type { BarClassKey, BarClasses } from "./barClasses.js";
@@ -2,4 +2,5 @@ export * from "./BarChart.js";
2
2
  export * from "./BarPlot.js";
3
3
  export * from "./BarElement.js";
4
4
  export * from "./BarLabel/index.js";
5
- export * from "./barElementClasses.js";
5
+ export * from "./barElementClasses.js";
6
+ export { barClasses, getBarUtilityClass } from "./barClasses.js";
@@ -9,7 +9,11 @@ export type AnimationData = {
9
9
  xOrigin: number;
10
10
  layout: BarSeriesType['layout'];
11
11
  };
12
- export interface CompletedBarData extends AnimationData {
12
+ export interface ProcessedBarSeriesData {
13
+ seriesId: SeriesId;
14
+ data: ProcessedBarData[];
15
+ }
16
+ export interface ProcessedBarData extends AnimationData {
13
17
  seriesId: SeriesId;
14
18
  dataIndex: number;
15
19
  color: string;
@@ -0,0 +1,8 @@
1
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/axis.js";
2
+ import { ChartDrawingArea } from "../hooks/index.js";
3
+ import { MaskData, ProcessedBarSeriesData } from "./types.js";
4
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.js";
5
+ export declare function useBarPlotData(drawingArea: ChartDrawingArea, xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): {
6
+ completedData: ProcessedBarSeriesData[];
7
+ masksData: MaskData[];
8
+ };