@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
@@ -7,23 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  value: true
8
8
  });
9
9
  exports.LinePlot = LinePlot;
10
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _styles = require("@mui/material/styles");
15
- var _warning = require("@mui/x-internals/warning");
16
- var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
17
15
  var _LineElement = require("./LineElement");
18
- var _useScale = require("../hooks/useScale");
19
- var _getCurve = require("../internals/getCurve");
20
- var _isBandScale = require("../internals/isBandScale");
21
- var _constants = require("../constants");
22
- var _useLineSeries = require("../hooks/useLineSeries");
23
16
  var _useSkipAnimation = require("../hooks/useSkipAnimation");
24
- var _useChartGradientId = require("../hooks/useChartGradientId");
25
17
  var _hooks = require("../hooks");
26
18
  var _useInternalIsZoomInteracting = require("../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting");
19
+ var _useLinePlotData = require("./useLinePlotData");
27
20
  var _jsxRuntime = require("react/jsx-runtime");
28
21
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
29
22
  const LinePlotRoot = (0, _styles.styled)('g', {
@@ -35,100 +28,13 @@ const LinePlotRoot = (0, _styles.styled)('g', {
35
28
  }
36
29
  });
37
30
  const useAggregatedData = () => {
38
- const seriesData = (0, _useLineSeries.useLineSeriesContext)();
39
31
  const {
40
- xAxis,
41
- xAxisIds
32
+ xAxis: xAxes
42
33
  } = (0, _hooks.useXAxes)();
43
34
  const {
44
- yAxis,
45
- yAxisIds
35
+ yAxis: yAxes
46
36
  } = (0, _hooks.useYAxes)();
47
- const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
48
-
49
- // This memo prevents odd line chart behavior when hydrating.
50
- const allData = React.useMemo(() => {
51
- if (seriesData === undefined) {
52
- return [];
53
- }
54
- const {
55
- series,
56
- stackingGroups
57
- } = seriesData;
58
- const defaultXAxisId = xAxisIds[0];
59
- const defaultYAxisId = yAxisIds[0];
60
- return stackingGroups.flatMap(({
61
- ids: groupIds
62
- }) => {
63
- return groupIds.flatMap(seriesId => {
64
- const {
65
- xAxisId = defaultXAxisId,
66
- yAxisId = defaultYAxisId,
67
- stackedData,
68
- data,
69
- connectNulls,
70
- curve,
71
- strictStepCurve
72
- } = series[seriesId];
73
- const xScale = xAxis[xAxisId].scale;
74
- const xPosition = (0, _useScale.getValueToPositionMapper)(xScale);
75
- const yScale = yAxis[yAxisId].scale;
76
- const xData = xAxis[xAxisId].data;
77
- const gradientId = yAxis[yAxisId].colorScale && getGradientId(yAxisId) || xAxis[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
78
- if (process.env.NODE_ENV !== 'production') {
79
- if (xData === undefined) {
80
- throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
81
- }
82
- if (xData.length < stackedData.length) {
83
- (0, _warning.warnOnce)(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
84
- }
85
- }
86
- const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
87
- const formattedData = xData?.flatMap((x, index) => {
88
- const nullData = data[index] == null;
89
- if (shouldExpand) {
90
- const rep = [{
91
- x,
92
- y: stackedData[index],
93
- nullData,
94
- isExtension: false
95
- }];
96
- if (!nullData && (index === 0 || data[index - 1] == null)) {
97
- rep.unshift({
98
- x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
99
- y: stackedData[index],
100
- nullData,
101
- isExtension: true
102
- });
103
- }
104
- if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
105
- rep.push({
106
- x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
107
- y: stackedData[index],
108
- nullData,
109
- isExtension: true
110
- });
111
- }
112
- return rep;
113
- }
114
- return {
115
- x,
116
- y: stackedData[index],
117
- nullData
118
- };
119
- }) ?? [];
120
- const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
121
- const linePath = (0, _d3Shape.line)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y(d => yScale(d.y[1]));
122
- const d = linePath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
123
- return (0, _extends2.default)({}, series[seriesId], {
124
- gradientId,
125
- d,
126
- seriesId
127
- });
128
- });
129
- });
130
- }, [seriesData, xAxisIds, yAxisIds, xAxis, yAxis, getGradientId]);
131
- return allData;
37
+ return (0, _useLinePlotData.useLinePlotData)(xAxes, yAxes);
132
38
  };
133
39
 
134
40
  /**
@@ -84,7 +84,10 @@ function MarkElement(props) {
84
84
  d: (0, _d3Shape.symbol)(_d3Shape.symbolsFill[(0, _getSymbol.getSymbol)(shape)])(),
85
85
  onClick: onClick,
86
86
  cursor: onClick ? 'pointer' : 'unset'
87
- }, interactionProps));
87
+ }, interactionProps, {
88
+ "data-highlighted": isHighlighted || undefined,
89
+ "data-faded": isFaded || undefined
90
+ }));
88
91
  }
89
92
  process.env.NODE_ENV !== "production" ? MarkElement.propTypes = {
90
93
  // ----------------------------- Warning --------------------------------
@@ -109,6 +109,7 @@ function MarkPlot(props) {
109
109
  });
110
110
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
111
111
  clipPath: `url(#${clipId})`,
112
+ "data-series": seriesId,
112
113
  children: xData?.map((x, index) => {
113
114
  const value = data[index] == null ? null : stackedData[index][1];
114
115
  return {
@@ -0,0 +1,12 @@
1
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
2
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/index.js";
3
+ import { SeriesId } from "../models/seriesType/common.js";
4
+ interface AreaPlotDataPoint {
5
+ d: string;
6
+ seriesId: SeriesId;
7
+ color: string;
8
+ area?: boolean;
9
+ gradientId?: string;
10
+ }
11
+ export declare function useAreaPlotData(xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): AreaPlotDataPoint[];
12
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useAreaPlotData = useAreaPlotData;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
10
+ var _useChartGradientId = require("../hooks/useChartGradientId");
11
+ var _isBandScale = require("../internals/isBandScale");
12
+ var _getCurve = require("../internals/getCurve");
13
+ var _hooks = require("../hooks");
14
+ var _constants = require("../constants");
15
+ function useAreaPlotData(xAxes, yAxes) {
16
+ const seriesData = (0, _hooks.useLineSeriesContext)();
17
+ const defaultXAxisId = (0, _hooks.useXAxes)().xAxisIds[0];
18
+ const defaultYAxisId = (0, _hooks.useYAxes)().yAxisIds[0];
19
+ const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
20
+
21
+ // This memo prevents odd line chart behavior when hydrating.
22
+ const allData = React.useMemo(() => {
23
+ if (seriesData === undefined) {
24
+ return [];
25
+ }
26
+ const {
27
+ series,
28
+ stackingGroups
29
+ } = seriesData;
30
+ const areaPlotData = [];
31
+ for (const stackingGroup of stackingGroups) {
32
+ const groupIds = stackingGroup.ids;
33
+ for (let i = groupIds.length - 1; i >= 0; i -= 1) {
34
+ const seriesId = groupIds[i];
35
+ const {
36
+ xAxisId = defaultXAxisId,
37
+ yAxisId = defaultYAxisId,
38
+ stackedData,
39
+ data,
40
+ connectNulls,
41
+ baseline,
42
+ curve,
43
+ strictStepCurve
44
+ } = series[seriesId];
45
+ if (!(xAxisId in xAxes) || !(yAxisId in yAxes)) {
46
+ continue;
47
+ }
48
+ const xScale = xAxes[xAxisId].scale;
49
+ const xPosition = (0, _hooks.getValueToPositionMapper)(xScale);
50
+ const yScale = yAxes[yAxisId].scale;
51
+ const xData = xAxes[xAxisId].data;
52
+ const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
53
+ if (process.env.NODE_ENV !== 'production') {
54
+ if (xData === undefined) {
55
+ throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
56
+ }
57
+ if (xData.length < stackedData.length) {
58
+ throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
59
+ }
60
+ }
61
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
62
+ const formattedData = xData?.flatMap((x, index) => {
63
+ const nullData = data[index] == null;
64
+ if (shouldExpand) {
65
+ const rep = [{
66
+ x,
67
+ y: stackedData[index],
68
+ nullData,
69
+ isExtension: false
70
+ }];
71
+ if (!nullData && (index === 0 || data[index - 1] == null)) {
72
+ rep.unshift({
73
+ x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
74
+ y: stackedData[index],
75
+ nullData,
76
+ isExtension: true
77
+ });
78
+ }
79
+ if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
80
+ rep.push({
81
+ x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
82
+ y: stackedData[index],
83
+ nullData,
84
+ isExtension: true
85
+ });
86
+ }
87
+ return rep;
88
+ }
89
+ return {
90
+ x,
91
+ y: stackedData[index],
92
+ nullData
93
+ };
94
+ }) ?? [];
95
+ const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
96
+ const areaPath = (0, _d3Shape.area)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y0(d => {
97
+ if (typeof baseline === 'number') {
98
+ return yScale(baseline);
99
+ }
100
+ if (baseline === 'max') {
101
+ return yScale.range()[1];
102
+ }
103
+ if (baseline === 'min') {
104
+ return yScale.range()[0];
105
+ }
106
+ const value = d.y && yScale(d.y[0]);
107
+ if (Number.isNaN(value)) {
108
+ return yScale.range()[0];
109
+ }
110
+ return value;
111
+ }).y1(d => d.y && yScale(d.y[1]));
112
+ const d = areaPath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
113
+ areaPlotData.push({
114
+ area: series[seriesId].area,
115
+ color: series[seriesId].color,
116
+ gradientId,
117
+ d,
118
+ seriesId
119
+ });
120
+ }
121
+ }
122
+ return areaPlotData;
123
+ }, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
124
+ return allData;
125
+ }
@@ -0,0 +1,11 @@
1
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
2
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/index.js";
3
+ import { SeriesId } from "../models/seriesType/common.js";
4
+ interface LinePlotDataPoint {
5
+ d: string;
6
+ seriesId: SeriesId;
7
+ color: string;
8
+ gradientId?: string;
9
+ }
10
+ export declare function useLinePlotData(xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): LinePlotDataPoint[];
11
+ export {};
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useLinePlotData = useLinePlotData;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _warning = require("@mui/x-internals/warning");
10
+ var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
11
+ var _useChartGradientId = require("../hooks/useChartGradientId");
12
+ var _isBandScale = require("../internals/isBandScale");
13
+ var _getCurve = require("../internals/getCurve");
14
+ var _hooks = require("../hooks");
15
+ var _constants = require("../constants");
16
+ function useLinePlotData(xAxes, yAxes) {
17
+ const seriesData = (0, _hooks.useLineSeriesContext)();
18
+ const defaultXAxisId = (0, _hooks.useXAxes)().xAxisIds[0];
19
+ const defaultYAxisId = (0, _hooks.useYAxes)().yAxisIds[0];
20
+ const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
21
+
22
+ // This memo prevents odd line chart behavior when hydrating.
23
+ const allData = React.useMemo(() => {
24
+ if (seriesData === undefined) {
25
+ return [];
26
+ }
27
+ const {
28
+ series,
29
+ stackingGroups
30
+ } = seriesData;
31
+ const linePlotData = [];
32
+ for (const stackingGroup of stackingGroups) {
33
+ const groupIds = stackingGroup.ids;
34
+ for (const seriesId of groupIds) {
35
+ const {
36
+ xAxisId = defaultXAxisId,
37
+ yAxisId = defaultYAxisId,
38
+ stackedData,
39
+ data,
40
+ connectNulls,
41
+ curve,
42
+ strictStepCurve
43
+ } = series[seriesId];
44
+ if (!(xAxisId in xAxes) || !(yAxisId in yAxes)) {
45
+ continue;
46
+ }
47
+ const xScale = xAxes[xAxisId].scale;
48
+ const xPosition = (0, _hooks.getValueToPositionMapper)(xScale);
49
+ const yScale = yAxes[yAxisId].scale;
50
+ const xData = xAxes[xAxisId].data;
51
+ const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
52
+ if (process.env.NODE_ENV !== 'production') {
53
+ if (xData === undefined) {
54
+ throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
55
+ }
56
+ if (xData.length < stackedData.length) {
57
+ (0, _warning.warnOnce)(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
58
+ }
59
+ }
60
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
61
+ const formattedData = xData?.flatMap((x, index) => {
62
+ const nullData = data[index] == null;
63
+ if (shouldExpand) {
64
+ const rep = [{
65
+ x,
66
+ y: stackedData[index],
67
+ nullData,
68
+ isExtension: false
69
+ }];
70
+ if (!nullData && (index === 0 || data[index - 1] == null)) {
71
+ rep.unshift({
72
+ x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
73
+ y: stackedData[index],
74
+ nullData,
75
+ isExtension: true
76
+ });
77
+ }
78
+ if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
79
+ rep.push({
80
+ x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
81
+ y: stackedData[index],
82
+ nullData,
83
+ isExtension: true
84
+ });
85
+ }
86
+ return rep;
87
+ }
88
+ return {
89
+ x,
90
+ y: stackedData[index],
91
+ nullData
92
+ };
93
+ }) ?? [];
94
+ const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
95
+ const linePath = (0, _d3Shape.line)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y(d => yScale(d.y[1]));
96
+ const d = linePath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
97
+ linePlotData.push({
98
+ color: series[seriesId].color,
99
+ gradientId,
100
+ d,
101
+ seriesId
102
+ });
103
+ }
104
+ }
105
+ return linePlotData;
106
+ }, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
107
+ return allData;
108
+ }
@@ -103,7 +103,9 @@ const PieArc = exports.PieArc = /*#__PURE__*/React.forwardRef(function PieArc(pr
103
103
  opacity: ownerState.isFaded ? 0.3 : 1,
104
104
  filter: ownerState.isHighlighted ? 'brightness(120%)' : 'none',
105
105
  strokeWidth: 1,
106
- strokeLinejoin: "round"
106
+ strokeLinejoin: "round",
107
+ "data-highlighted": ownerState.isHighlighted || undefined,
108
+ "data-faded": ownerState.isFaded || undefined
107
109
  }, other, interactionProps, animatedProps));
108
110
  });
109
111
  if (process.env.NODE_ENV !== "production") PieArc.displayName = "PieArc";
@@ -16,6 +16,7 @@ var _getPieCoordinates = require("./getPieCoordinates");
16
16
  var _usePieSeries = require("../hooks/usePieSeries");
17
17
  var _useSkipAnimation = require("../hooks/useSkipAnimation");
18
18
  var _hooks = require("../hooks");
19
+ var _pieClasses = require("./pieClasses");
19
20
  var _jsxRuntime = require("react/jsx-runtime");
20
21
  /**
21
22
  * Demos:
@@ -42,6 +43,7 @@ function PiePlot(props) {
42
43
  height
43
44
  } = (0, _hooks.useDrawingArea)();
44
45
  const skipAnimation = (0, _useSkipAnimation.useSkipAnimation)(inSkipAnimation);
46
+ const classes = (0, _pieClasses.useUtilityClasses)();
45
47
  if (seriesData === undefined) {
46
48
  return null;
47
49
  }
@@ -76,7 +78,9 @@ function PiePlot(props) {
76
78
  const outerRadius = (0, _getPercentageValue.getPercentageValue)(outerRadiusParam ?? availableRadius, availableRadius);
77
79
  const innerRadius = (0, _getPercentageValue.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
78
80
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
81
+ className: classes.series,
79
82
  transform: `translate(${left + cx}, ${top + cy})`,
83
+ "data-series": seriesId,
80
84
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcPlot.PieArcPlot, {
81
85
  innerRadius: innerRadius,
82
86
  outerRadius: outerRadius,
@@ -120,7 +124,9 @@ function PiePlot(props) {
120
124
  const innerRadius = (0, _getPercentageValue.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
121
125
  const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : (0, _getPercentageValue.getPercentageValue)(arcLabelRadiusParam, availableRadius);
122
126
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
127
+ className: classes.seriesLabels,
123
128
  transform: `translate(${left + cx}, ${top + cy})`,
129
+ "data-series": seriesId,
124
130
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcLabelPlot.PieArcLabelPlot, {
125
131
  innerRadius: innerRadius,
126
132
  outerRadius: outerRadius ?? availableRadius,
@@ -4,4 +4,6 @@ export * from "./PieArcPlot.js";
4
4
  export * from "./PieArcLabelPlot.js";
5
5
  export * from "./PieArc.js";
6
6
  export * from "./PieArcLabel.js";
7
- export * from "./getPieCoordinates.js";
7
+ export * from "./getPieCoordinates.js";
8
+ export { pieClasses } from "./pieClasses.js";
9
+ export type { PieClasses, PieClassKey } from "./pieClasses.js";
package/PieChart/index.js CHANGED
@@ -3,9 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ pieClasses: true
8
+ };
9
+ Object.defineProperty(exports, "pieClasses", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _pieClasses.pieClasses;
13
+ }
14
+ });
6
15
  var _PieChart = require("./PieChart");
7
16
  Object.keys(_PieChart).forEach(function (key) {
8
17
  if (key === "default" || key === "__esModule") return;
18
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
9
19
  if (key in exports && exports[key] === _PieChart[key]) return;
10
20
  Object.defineProperty(exports, key, {
11
21
  enumerable: true,
@@ -17,6 +27,7 @@ Object.keys(_PieChart).forEach(function (key) {
17
27
  var _PiePlot = require("./PiePlot");
18
28
  Object.keys(_PiePlot).forEach(function (key) {
19
29
  if (key === "default" || key === "__esModule") return;
30
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
31
  if (key in exports && exports[key] === _PiePlot[key]) return;
21
32
  Object.defineProperty(exports, key, {
22
33
  enumerable: true,
@@ -28,6 +39,7 @@ Object.keys(_PiePlot).forEach(function (key) {
28
39
  var _PieArcPlot = require("./PieArcPlot");
29
40
  Object.keys(_PieArcPlot).forEach(function (key) {
30
41
  if (key === "default" || key === "__esModule") return;
42
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
43
  if (key in exports && exports[key] === _PieArcPlot[key]) return;
32
44
  Object.defineProperty(exports, key, {
33
45
  enumerable: true,
@@ -39,6 +51,7 @@ Object.keys(_PieArcPlot).forEach(function (key) {
39
51
  var _PieArcLabelPlot = require("./PieArcLabelPlot");
40
52
  Object.keys(_PieArcLabelPlot).forEach(function (key) {
41
53
  if (key === "default" || key === "__esModule") return;
54
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
55
  if (key in exports && exports[key] === _PieArcLabelPlot[key]) return;
43
56
  Object.defineProperty(exports, key, {
44
57
  enumerable: true,
@@ -50,6 +63,7 @@ Object.keys(_PieArcLabelPlot).forEach(function (key) {
50
63
  var _PieArc = require("./PieArc");
51
64
  Object.keys(_PieArc).forEach(function (key) {
52
65
  if (key === "default" || key === "__esModule") return;
66
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
53
67
  if (key in exports && exports[key] === _PieArc[key]) return;
54
68
  Object.defineProperty(exports, key, {
55
69
  enumerable: true,
@@ -61,6 +75,7 @@ Object.keys(_PieArc).forEach(function (key) {
61
75
  var _PieArcLabel = require("./PieArcLabel");
62
76
  Object.keys(_PieArcLabel).forEach(function (key) {
63
77
  if (key === "default" || key === "__esModule") return;
78
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
64
79
  if (key in exports && exports[key] === _PieArcLabel[key]) return;
65
80
  Object.defineProperty(exports, key, {
66
81
  enumerable: true,
@@ -72,6 +87,7 @@ Object.keys(_PieArcLabel).forEach(function (key) {
72
87
  var _getPieCoordinates = require("./getPieCoordinates");
73
88
  Object.keys(_getPieCoordinates).forEach(function (key) {
74
89
  if (key === "default" || key === "__esModule") return;
90
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
75
91
  if (key in exports && exports[key] === _getPieCoordinates[key]) return;
76
92
  Object.defineProperty(exports, key, {
77
93
  enumerable: true,
@@ -79,4 +95,5 @@ Object.keys(_getPieCoordinates).forEach(function (key) {
79
95
  return _getPieCoordinates[key];
80
96
  }
81
97
  });
82
- });
98
+ });
99
+ var _pieClasses = require("./pieClasses");
@@ -0,0 +1,12 @@
1
+ export interface PieClasses {
2
+ /** Styles applied to the root element. */
3
+ root: string;
4
+ /** Styles applied to the `g` element that contains all pie arcs of a series. */
5
+ series: string;
6
+ /** Styles applied to the `g` element that contains all pie arc labels of a series. */
7
+ seriesLabels: string;
8
+ }
9
+ export type PieClassKey = keyof PieClasses;
10
+ export declare function getPieUtilityClass(slot: string): string;
11
+ export declare const pieClasses: PieClasses;
12
+ export declare const useUtilityClasses: (classes?: Partial<PieClasses>) => Record<"root" | "series" | "seriesLabels", string>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getPieUtilityClass = getPieUtilityClass;
8
+ exports.useUtilityClasses = exports.pieClasses = void 0;
9
+ var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
10
+ var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
11
+ var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
12
+ function getPieUtilityClass(slot) {
13
+ return (0, _generateUtilityClass.default)('MuiPieChart', slot);
14
+ }
15
+ const pieClasses = exports.pieClasses = (0, _generateUtilityClasses.default)('MuiPieChart', ['root', 'series', 'seriesLabels']);
16
+ const useUtilityClasses = classes => {
17
+ const slots = {
18
+ root: ['root'],
19
+ series: ['series'],
20
+ seriesLabels: ['seriesLabels']
21
+ };
22
+ return (0, _composeClasses.default)(slots, getPieUtilityClass, classes);
23
+ };
24
+ exports.useUtilityClasses = useUtilityClasses;