@mui/x-charts 6.0.0-alpha.8 → 6.18.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 (286) hide show
  1. package/BarChart/BarChart.d.ts +19 -5
  2. package/BarChart/BarChart.js +52 -13
  3. package/BarChart/BarElement.d.ts +1319 -4
  4. package/BarChart/BarElement.js +10 -10
  5. package/BarChart/BarPlot.d.ts +17 -1
  6. package/BarChart/BarPlot.js +152 -66
  7. package/BarChart/formatter.js +2 -3
  8. package/BarChart/legend.js +1 -2
  9. package/CHANGELOG.md +786 -48
  10. package/ChartContainer/index.js +7 -5
  11. package/ChartsAxis/ChartsAxis.d.ts +9 -0
  12. package/ChartsAxis/ChartsAxis.js +28 -2
  13. package/ChartsAxis/axisClasses.d.ts +1 -1
  14. package/ChartsAxis/axisClasses.js +1 -2
  15. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +21 -0
  16. package/ChartsAxisHighlight/ChartsAxisHighlight.js +61 -22
  17. package/ChartsClipPath/ChartsClipPath.d.ts +5 -0
  18. package/ChartsClipPath/ChartsClipPath.js +7 -2
  19. package/ChartsLegend/ChartsLegend.d.ts +44 -24
  20. package/ChartsLegend/ChartsLegend.js +192 -150
  21. package/ChartsLegend/chartsLegendClasses.js +1 -2
  22. package/ChartsLegend/utils.d.ts +1 -6
  23. package/ChartsSurface.d.ts +1 -1
  24. package/ChartsSurface.js +9 -18
  25. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
  26. package/ChartsTooltip/ChartsAxisTooltipContent.js +46 -32
  27. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
  28. package/ChartsTooltip/ChartsItemTooltipContent.js +18 -9
  29. package/ChartsTooltip/ChartsTooltip.d.ts +32 -0
  30. package/ChartsTooltip/ChartsTooltip.js +62 -18
  31. package/ChartsTooltip/ChartsTooltipTable.d.ts +3 -10
  32. package/ChartsTooltip/ChartsTooltipTable.js +22 -20
  33. package/ChartsTooltip/tooltipClasses.js +1 -2
  34. package/ChartsTooltip/utils.js +2 -2
  35. package/ChartsXAxis/ChartsXAxis.d.ts +9 -0
  36. package/ChartsXAxis/ChartsXAxis.js +161 -40
  37. package/ChartsYAxis/ChartsYAxis.d.ts +9 -0
  38. package/ChartsYAxis/ChartsYAxis.js +86 -33
  39. package/LineChart/AreaElement.d.ts +12 -2
  40. package/LineChart/AreaElement.js +14 -6
  41. package/LineChart/AreaPlot.d.ts +11 -0
  42. package/LineChart/AreaPlot.js +27 -8
  43. package/LineChart/LineChart.d.ts +21 -3
  44. package/LineChart/LineChart.js +61 -14
  45. package/LineChart/LineElement.d.ts +12 -2
  46. package/LineChart/LineElement.js +14 -6
  47. package/LineChart/LineHighlightElement.d.ts +31 -0
  48. package/LineChart/LineHighlightElement.js +88 -0
  49. package/LineChart/LineHighlightPlot.d.ts +35 -0
  50. package/LineChart/LineHighlightPlot.js +110 -0
  51. package/LineChart/LinePlot.d.ts +10 -0
  52. package/LineChart/LinePlot.js +25 -12
  53. package/LineChart/MarkElement.d.ts +11 -1
  54. package/LineChart/MarkElement.js +15 -9
  55. package/LineChart/MarkPlot.d.ts +10 -0
  56. package/LineChart/MarkPlot.js +62 -15
  57. package/LineChart/formatter.js +5 -5
  58. package/LineChart/index.d.ts +2 -0
  59. package/LineChart/index.js +20 -0
  60. package/LineChart/legend.js +1 -2
  61. package/PieChart/PieArc.d.ts +12 -14
  62. package/PieChart/PieArc.js +28 -60
  63. package/PieChart/PieArcLabel.d.ts +9 -10
  64. package/PieChart/PieArcLabel.js +46 -38
  65. package/PieChart/PieArcLabelPlot.d.ts +28 -0
  66. package/PieChart/PieArcLabelPlot.js +99 -0
  67. package/PieChart/PieArcPlot.d.ts +35 -0
  68. package/PieChart/PieArcPlot.js +92 -0
  69. package/PieChart/PieChart.d.ts +19 -5
  70. package/PieChart/PieChart.js +61 -14
  71. package/PieChart/PiePlot.d.ts +15 -9
  72. package/PieChart/PiePlot.js +77 -55
  73. package/PieChart/dataTransform/transition.d.ts +4 -0
  74. package/PieChart/dataTransform/transition.js +136 -0
  75. package/PieChart/dataTransform/useTransformData.d.ts +15 -0
  76. package/PieChart/dataTransform/useTransformData.js +67 -0
  77. package/PieChart/formatter.js +1 -2
  78. package/PieChart/legend.js +1 -2
  79. package/README.md +8 -14
  80. package/ResponsiveChartContainer/index.js +7 -8
  81. package/ScatterChart/Scatter.d.ts +10 -0
  82. package/ScatterChart/Scatter.js +12 -2
  83. package/ScatterChart/ScatterChart.d.ts +16 -3
  84. package/ScatterChart/ScatterChart.js +43 -12
  85. package/ScatterChart/ScatterPlot.d.ts +10 -0
  86. package/ScatterChart/ScatterPlot.js +12 -2
  87. package/ScatterChart/formatter.js +1 -2
  88. package/ScatterChart/legend.js +1 -2
  89. package/SparkLineChart/SparkLineChart.d.ts +13 -3
  90. package/SparkLineChart/SparkLineChart.js +34 -18
  91. package/colorPalettes/colorPalettes.js +6 -12
  92. package/constants.js +5 -8
  93. package/context/CartesianContextProvider.d.ts +5 -0
  94. package/context/CartesianContextProvider.js +31 -16
  95. package/context/DrawingProvider.d.ts +7 -0
  96. package/context/DrawingProvider.js +12 -6
  97. package/context/HighlightProvider.js +3 -4
  98. package/context/InteractionProvider.js +3 -4
  99. package/context/SeriesContextProvider.js +3 -4
  100. package/esm/BarChart/BarChart.js +49 -9
  101. package/esm/BarChart/BarElement.js +7 -4
  102. package/esm/BarChart/BarPlot.js +152 -67
  103. package/esm/BarChart/formatter.js +1 -1
  104. package/esm/ChartContainer/index.js +3 -0
  105. package/esm/ChartsAxis/ChartsAxis.js +26 -0
  106. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
  107. package/esm/ChartsClipPath/ChartsClipPath.js +5 -0
  108. package/esm/ChartsLegend/ChartsLegend.js +188 -142
  109. package/esm/ChartsSurface.js +4 -12
  110. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
  111. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  112. package/esm/ChartsTooltip/ChartsTooltip.js +59 -14
  113. package/esm/ChartsTooltip/ChartsTooltipTable.js +17 -10
  114. package/esm/ChartsXAxis/ChartsXAxis.js +158 -37
  115. package/esm/ChartsYAxis/ChartsYAxis.js +83 -30
  116. package/esm/LineChart/AreaElement.js +10 -0
  117. package/esm/LineChart/AreaPlot.js +26 -6
  118. package/esm/LineChart/LineChart.js +58 -10
  119. package/esm/LineChart/LineElement.js +10 -0
  120. package/esm/LineChart/LineHighlightElement.js +78 -0
  121. package/esm/LineChart/LineHighlightPlot.js +103 -0
  122. package/esm/LineChart/LinePlot.js +25 -14
  123. package/esm/LineChart/MarkElement.js +12 -5
  124. package/esm/LineChart/MarkPlot.js +60 -13
  125. package/esm/LineChart/formatter.js +7 -3
  126. package/esm/LineChart/index.js +3 -1
  127. package/esm/PieChart/PieArc.js +26 -58
  128. package/esm/PieChart/PieArcLabel.js +43 -34
  129. package/esm/PieChart/PieArcLabelPlot.js +92 -0
  130. package/esm/PieChart/PieArcPlot.js +84 -0
  131. package/esm/PieChart/PieChart.js +59 -12
  132. package/esm/PieChart/PiePlot.js +76 -57
  133. package/esm/PieChart/dataTransform/transition.js +130 -0
  134. package/esm/PieChart/dataTransform/useTransformData.js +59 -0
  135. package/esm/ResponsiveChartContainer/index.js +3 -3
  136. package/esm/ScatterChart/Scatter.js +10 -0
  137. package/esm/ScatterChart/ScatterChart.js +40 -8
  138. package/esm/ScatterChart/ScatterPlot.js +10 -0
  139. package/esm/SparkLineChart/SparkLineChart.js +32 -15
  140. package/esm/constants.js +1 -1
  141. package/esm/context/CartesianContextProvider.js +30 -14
  142. package/esm/context/DrawingProvider.js +8 -0
  143. package/esm/hooks/useChartDimensions.js +2 -0
  144. package/esm/hooks/useMounted.js +16 -0
  145. package/esm/hooks/useReducedMotion.js +27 -0
  146. package/esm/hooks/useTicks.js +15 -9
  147. package/esm/internals/components/AxisSharedComponents.js +15 -70
  148. package/esm/internals/components/ChartsText.js +77 -0
  149. package/esm/internals/domUtils.js +113 -0
  150. package/esm/internals/geometry.js +36 -0
  151. package/hooks/useAxisEvents.js +2 -2
  152. package/hooks/useChartDimensions.d.ts +2 -0
  153. package/hooks/useChartDimensions.js +5 -4
  154. package/hooks/useDrawingArea.js +2 -2
  155. package/hooks/useInteractionItemProps.js +2 -2
  156. package/hooks/useMounted.d.ts +1 -0
  157. package/hooks/useMounted.js +25 -0
  158. package/hooks/useReducedMotion.d.ts +8 -0
  159. package/hooks/useReducedMotion.js +33 -0
  160. package/hooks/useScale.d.ts +2 -2
  161. package/hooks/useScale.js +2 -2
  162. package/hooks/useTicks.d.ts +19 -11
  163. package/hooks/useTicks.js +19 -14
  164. package/index.js +1 -1
  165. package/internals/components/AxisSharedComponents.d.ts +0 -4
  166. package/internals/components/AxisSharedComponents.js +18 -78
  167. package/internals/components/ChartsText.d.ts +35 -0
  168. package/internals/components/ChartsText.js +87 -0
  169. package/internals/defaultizeColor.d.ts +8 -1
  170. package/internals/defaultizeValueFormatter.js +1 -2
  171. package/internals/domUtils.d.ts +13 -0
  172. package/internals/domUtils.js +122 -0
  173. package/internals/geometry.d.ts +9 -0
  174. package/internals/geometry.js +42 -0
  175. package/internals/stackSeries.js +2 -4
  176. package/legacy/BarChart/BarChart.js +49 -9
  177. package/legacy/BarChart/BarElement.js +6 -3
  178. package/legacy/BarChart/BarPlot.js +151 -63
  179. package/legacy/BarChart/formatter.js +1 -1
  180. package/legacy/ChartContainer/index.js +3 -0
  181. package/legacy/ChartsAxis/ChartsAxis.js +26 -0
  182. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +60 -20
  183. package/legacy/ChartsClipPath/ChartsClipPath.js +5 -0
  184. package/legacy/ChartsLegend/ChartsLegend.js +203 -140
  185. package/legacy/ChartsSurface.js +3 -12
  186. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +22 -10
  187. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  188. package/legacy/ChartsTooltip/ChartsTooltip.js +62 -14
  189. package/legacy/ChartsTooltip/ChartsTooltipTable.js +34 -26
  190. package/legacy/ChartsXAxis/ChartsXAxis.js +162 -39
  191. package/legacy/ChartsYAxis/ChartsYAxis.js +83 -30
  192. package/legacy/LineChart/AreaElement.js +10 -0
  193. package/legacy/LineChart/AreaPlot.js +31 -7
  194. package/legacy/LineChart/LineChart.js +58 -10
  195. package/legacy/LineChart/LineElement.js +10 -0
  196. package/legacy/LineChart/LineHighlightElement.js +77 -0
  197. package/legacy/LineChart/LineHighlightPlot.js +96 -0
  198. package/legacy/LineChart/LinePlot.js +29 -12
  199. package/legacy/LineChart/MarkElement.js +12 -5
  200. package/legacy/LineChart/MarkPlot.js +50 -5
  201. package/legacy/LineChart/formatter.js +7 -3
  202. package/legacy/LineChart/index.js +3 -1
  203. package/legacy/PieChart/PieArc.js +30 -62
  204. package/legacy/PieChart/PieArcLabel.js +48 -34
  205. package/legacy/PieChart/PieArcLabelPlot.js +93 -0
  206. package/legacy/PieChart/PieArcPlot.js +84 -0
  207. package/legacy/PieChart/PieChart.js +59 -12
  208. package/legacy/PieChart/PiePlot.js +76 -59
  209. package/legacy/PieChart/dataTransform/transition.js +142 -0
  210. package/legacy/PieChart/dataTransform/useTransformData.js +60 -0
  211. package/legacy/ResponsiveChartContainer/index.js +3 -3
  212. package/legacy/ScatterChart/Scatter.js +10 -0
  213. package/legacy/ScatterChart/ScatterChart.js +40 -8
  214. package/legacy/ScatterChart/ScatterPlot.js +10 -0
  215. package/legacy/SparkLineChart/SparkLineChart.js +32 -13
  216. package/legacy/constants.js +1 -1
  217. package/legacy/context/CartesianContextProvider.js +30 -14
  218. package/legacy/context/DrawingProvider.js +8 -0
  219. package/legacy/hooks/useChartDimensions.js +2 -0
  220. package/legacy/hooks/useMounted.js +21 -0
  221. package/legacy/hooks/useReducedMotion.js +27 -0
  222. package/legacy/hooks/useTicks.js +16 -9
  223. package/legacy/index.js +1 -1
  224. package/legacy/internals/components/AxisSharedComponents.js +11 -65
  225. package/legacy/internals/components/ChartsText.js +79 -0
  226. package/legacy/internals/domUtils.js +121 -0
  227. package/legacy/internals/geometry.js +37 -0
  228. package/models/axis.d.ts +27 -9
  229. package/models/layout.d.ts +7 -6
  230. package/models/seriesType/line.d.ts +39 -1
  231. package/models/seriesType/pie.d.ts +5 -1
  232. package/modern/BarChart/BarChart.js +49 -9
  233. package/modern/BarChart/BarElement.js +7 -4
  234. package/modern/BarChart/BarPlot.js +149 -65
  235. package/modern/BarChart/formatter.js +1 -1
  236. package/modern/ChartContainer/index.js +3 -0
  237. package/modern/ChartsAxis/ChartsAxis.js +26 -0
  238. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
  239. package/modern/ChartsClipPath/ChartsClipPath.js +5 -0
  240. package/modern/ChartsLegend/ChartsLegend.js +188 -142
  241. package/modern/ChartsSurface.js +4 -12
  242. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
  243. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  244. package/modern/ChartsTooltip/ChartsTooltip.js +58 -14
  245. package/modern/ChartsTooltip/ChartsTooltipTable.js +17 -10
  246. package/modern/ChartsXAxis/ChartsXAxis.js +158 -37
  247. package/modern/ChartsYAxis/ChartsYAxis.js +83 -30
  248. package/modern/LineChart/AreaElement.js +10 -0
  249. package/modern/LineChart/AreaPlot.js +25 -6
  250. package/modern/LineChart/LineChart.js +58 -10
  251. package/modern/LineChart/LineElement.js +10 -0
  252. package/modern/LineChart/LineHighlightElement.js +78 -0
  253. package/modern/LineChart/LineHighlightPlot.js +102 -0
  254. package/modern/LineChart/LinePlot.js +23 -10
  255. package/modern/LineChart/MarkElement.js +12 -5
  256. package/modern/LineChart/MarkPlot.js +60 -13
  257. package/modern/LineChart/formatter.js +4 -3
  258. package/modern/LineChart/index.js +3 -1
  259. package/modern/PieChart/PieArc.js +26 -57
  260. package/modern/PieChart/PieArcLabel.js +43 -34
  261. package/modern/PieChart/PieArcLabelPlot.js +90 -0
  262. package/modern/PieChart/PieArcPlot.js +83 -0
  263. package/modern/PieChart/PieChart.js +59 -12
  264. package/modern/PieChart/PiePlot.js +76 -55
  265. package/modern/PieChart/dataTransform/transition.js +130 -0
  266. package/modern/PieChart/dataTransform/useTransformData.js +58 -0
  267. package/modern/ResponsiveChartContainer/index.js +3 -3
  268. package/modern/ScatterChart/Scatter.js +10 -0
  269. package/modern/ScatterChart/ScatterChart.js +40 -8
  270. package/modern/ScatterChart/ScatterPlot.js +10 -0
  271. package/modern/SparkLineChart/SparkLineChart.js +32 -15
  272. package/modern/constants.js +1 -1
  273. package/modern/context/CartesianContextProvider.js +29 -13
  274. package/modern/context/DrawingProvider.js +8 -0
  275. package/modern/hooks/useChartDimensions.js +2 -0
  276. package/modern/hooks/useMounted.js +16 -0
  277. package/modern/hooks/useReducedMotion.js +27 -0
  278. package/modern/hooks/useTicks.js +15 -9
  279. package/modern/index.js +1 -1
  280. package/modern/internals/components/AxisSharedComponents.js +15 -70
  281. package/modern/internals/components/ChartsText.js +77 -0
  282. package/modern/internals/domUtils.js +113 -0
  283. package/modern/internals/geometry.js +36 -0
  284. package/package.json +9 -6
  285. package/themeAugmentation/components.d.ts +1 -0
  286. package/themeAugmentation/overrides.d.ts +2 -0
@@ -1,29 +1,37 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import Box from '@mui/material/Box';
3
- import Paper from '@mui/material/Paper';
2
+ import Box from '@mui/system/Box';
4
3
  import { styled } from '@mui/material/styles';
5
4
  import { tooltipClasses } from './tooltipClasses';
6
- export var ChartsTooltipPaper = styled(Paper, {
5
+ export var ChartsTooltipPaper = styled('div', {
7
6
  name: 'MuiChartsTooltip',
8
- slot: 'Table'
9
- })({});
7
+ slot: 'Container'
8
+ })(function (_ref) {
9
+ var theme = _ref.theme;
10
+ return {
11
+ backgroundColor: (theme.vars || theme).palette.background.paper,
12
+ color: (theme.vars || theme).palette.text.primary,
13
+ transition: theme.transitions.create('box-shadow'),
14
+ border: "1px solid ".concat((theme.vars || theme).palette.divider),
15
+ borderRadius: theme.shape.borderRadius
16
+ };
17
+ });
10
18
  export var ChartsTooltipTable = styled('table', {
11
19
  name: 'MuiChartsTooltip',
12
20
  slot: 'Table'
13
- })(function (_ref) {
14
- var theme = _ref.theme;
21
+ })(function (_ref2) {
22
+ var theme = _ref2.theme;
15
23
  return {
16
24
  borderSpacing: 0,
17
25
  '& thead td': {
18
- borderBottom: "solid ".concat(theme.palette.divider, " 1px")
26
+ borderBottom: "solid ".concat((theme.vars || theme).palette.divider, " 1px")
19
27
  }
20
28
  };
21
29
  });
22
30
  export var ChartsTooltipRow = styled('tr', {
23
31
  name: 'MuiChartsTooltip',
24
32
  slot: 'Row'
25
- })(function (_ref2) {
26
- var theme = _ref2.theme;
33
+ })(function (_ref3) {
34
+ var theme = _ref3.theme;
27
35
  return {
28
36
  'tr:first-of-type& td': {
29
37
  paddingTop: theme.spacing(1)
@@ -36,36 +44,36 @@ export var ChartsTooltipRow = styled('tr', {
36
44
  export var ChartsTooltipCell = styled('td', {
37
45
  name: 'MuiChartsTooltip',
38
46
  slot: 'Cell'
39
- })(function (_ref3) {
40
- var _ref4;
41
- var theme = _ref3.theme;
42
- return _ref4 = {
47
+ })(function (_ref4) {
48
+ var _ref5;
49
+ var theme = _ref4.theme;
50
+ return _ref5 = {
43
51
  verticalAlign: 'middle',
44
- color: theme.palette.text.secondary
45
- }, _defineProperty(_ref4, "&.".concat(tooltipClasses.labelCell), {
52
+ color: (theme.vars || theme).palette.text.secondary
53
+ }, _defineProperty(_ref5, "&.".concat(tooltipClasses.labelCell), {
46
54
  paddingLeft: theme.spacing(1)
47
- }), _defineProperty(_ref4, "&.".concat(tooltipClasses.valueCell), {
55
+ }), _defineProperty(_ref5, "&.".concat(tooltipClasses.valueCell), {
48
56
  paddingLeft: theme.spacing(4),
49
- color: theme.palette.text.primary
50
- }), _defineProperty(_ref4, 'td:first-of-type&', {
57
+ color: (theme.vars || theme).palette.text.primary
58
+ }), _defineProperty(_ref5, 'td:first-of-type&', {
51
59
  paddingLeft: theme.spacing(2)
52
- }), _defineProperty(_ref4, 'td:last-of-type&', {
60
+ }), _defineProperty(_ref5, 'td:last-of-type&', {
53
61
  paddingRight: theme.spacing(2)
54
- }), _ref4;
62
+ }), _ref5;
55
63
  });
56
64
  export var ChartsTooltipMark = styled(Box, {
57
65
  name: 'MuiChartsTooltip',
58
66
  slot: 'Mark'
59
- })(function (_ref5) {
60
- var theme = _ref5.theme,
61
- ownerState = _ref5.ownerState;
67
+ })(function (_ref6) {
68
+ var theme = _ref6.theme,
69
+ ownerState = _ref6.ownerState;
62
70
  return {
63
71
  width: theme.spacing(1),
64
72
  height: theme.spacing(1),
65
73
  borderRadius: '50%',
66
74
  backgroundColor: ownerState.color,
67
- borderColor: theme.palette.background.paper,
68
- border: "solid ".concat(theme.palette.background.paper, " ").concat(theme.spacing(0.25)),
75
+ borderColor: (theme.vars || theme).palette.background.paper,
76
+ border: "solid ".concat((theme.vars || theme).palette.background.paper, " ").concat(theme.spacing(0.25)),
69
77
  boxSizing: 'content-box'
70
78
  };
71
79
  });
@@ -1,15 +1,20 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- var _excluded = ["scale", "ticksNumber"];
4
+ var _excluded = ["scale", "tickNumber"];
4
5
  import * as React from 'react';
5
6
  import PropTypes from 'prop-types';
7
+ import { useSlotProps } from '@mui/base/utils';
6
8
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
9
  import { useThemeProps, useTheme } from '@mui/material/styles';
8
10
  import { CartesianContext } from '../context/CartesianContextProvider';
9
11
  import { DrawingContext } from '../context/DrawingProvider';
10
12
  import useTicks from '../hooks/useTicks';
11
13
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
12
- import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
14
+ import { AxisRoot } from '../internals/components/AxisSharedComponents';
15
+ import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
16
+ import { getMinXTranslation } from '../internals/geometry';
17
+ import { useMounted } from '../hooks/useMounted';
13
18
  import { jsx as _jsx } from "react/jsx-runtime";
14
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
20
  var useUtilityClasses = function useUtilityClasses(ownerState) {
@@ -25,14 +30,77 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
25
30
  };
26
31
  return composeClasses(slots, getAxisUtilityClass, classes);
27
32
  };
33
+ function addLabelDimension(xTicks, _ref) {
34
+ var style = _ref.tickLabelStyle,
35
+ tickLabelInterval = _ref.tickLabelInterval,
36
+ isMounted = _ref.isMounted;
37
+ var withDimension = xTicks.map(function (tick) {
38
+ if (!isMounted || tick.formattedValue === undefined) {
39
+ return _extends({}, tick, {
40
+ width: 0,
41
+ height: 0
42
+ });
43
+ }
44
+ var tickSizes = getWordsByLines({
45
+ style: style,
46
+ needsComputation: true,
47
+ text: tick.formattedValue
48
+ });
49
+ return _extends({}, tick, {
50
+ width: Math.max.apply(Math, _toConsumableArray(tickSizes.map(function (size) {
51
+ return size.width;
52
+ }))),
53
+ height: Math.max(tickSizes.length * tickSizes[0].height)
54
+ });
55
+ });
56
+ if (typeof tickLabelInterval === 'function') {
57
+ return withDimension.map(function (item, index) {
58
+ return _extends({}, item, {
59
+ skipLabel: !tickLabelInterval(item.value, index)
60
+ });
61
+ });
62
+ }
63
+
64
+ // Filter label to avoid overlap
65
+ var textStart = 0;
66
+ var textEnd = 0;
67
+ return withDimension.map(function (item, labelIndex) {
68
+ var width = item.width,
69
+ offset = item.offset,
70
+ labelOffset = item.labelOffset,
71
+ height = item.height;
72
+ var distance = getMinXTranslation(width, height, style == null ? void 0 : style.angle);
73
+ var textPosition = offset + labelOffset;
74
+ var gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
75
+
76
+ textStart = textPosition - gapRatio * distance / 2;
77
+ if (labelIndex > 0 && textStart < textEnd) {
78
+ // Except for the first label, we skip all label that overlap with the last accepted.
79
+ // Notice that the early return prevents `textEnd` from being updated.
80
+ return _extends({}, item, {
81
+ skipLabel: true
82
+ });
83
+ }
84
+ textEnd = textPosition + gapRatio * distance / 2;
85
+ return item;
86
+ });
87
+ }
28
88
  var defaultProps = {
29
89
  position: 'bottom',
30
90
  disableLine: false,
31
91
  disableTicks: false,
32
- tickFontSize: 12,
33
- labelFontSize: 14,
34
92
  tickSize: 6
35
93
  };
94
+
95
+ /**
96
+ * Demos:
97
+ *
98
+ * - [Axis](https://mui.com/x/react-charts/axis/)
99
+ *
100
+ * API:
101
+ *
102
+ * - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
103
+ */
36
104
  function ChartsXAxis(inProps) {
37
105
  var _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
38
106
  var props = useThemeProps({
@@ -42,19 +110,24 @@ function ChartsXAxis(inProps) {
42
110
  var _React$useContext = React.useContext(CartesianContext),
43
111
  _React$useContext$xAx = _React$useContext.xAxis[props.axisId],
44
112
  xScale = _React$useContext$xAx.scale,
45
- ticksNumber = _React$useContext$xAx.ticksNumber,
113
+ tickNumber = _React$useContext$xAx.tickNumber,
46
114
  settings = _objectWithoutProperties(_React$useContext$xAx, _excluded);
115
+ var isMounted = useMounted();
47
116
  var defaultizedProps = _extends({}, defaultProps, settings, props);
48
117
  var position = defaultizedProps.position,
49
118
  disableLine = defaultizedProps.disableLine,
50
119
  disableTicks = defaultizedProps.disableTicks,
51
- tickFontSize = defaultizedProps.tickFontSize,
120
+ tickLabelStyle = defaultizedProps.tickLabelStyle,
52
121
  label = defaultizedProps.label,
122
+ labelStyle = defaultizedProps.labelStyle,
123
+ tickFontSize = defaultizedProps.tickFontSize,
53
124
  labelFontSize = defaultizedProps.labelFontSize,
54
125
  tickSizeProp = defaultizedProps.tickSize,
55
126
  valueFormatter = defaultizedProps.valueFormatter,
56
127
  slots = defaultizedProps.slots,
57
- slotProps = defaultizedProps.slotProps;
128
+ slotProps = defaultizedProps.slotProps,
129
+ tickInterval = defaultizedProps.tickInterval,
130
+ tickLabelInterval = defaultizedProps.tickLabelInterval;
58
131
  var theme = useTheme();
59
132
  var classes = useUtilityClasses(_extends({}, defaultizedProps, {
60
133
  theme: theme
@@ -65,20 +138,52 @@ function ChartsXAxis(inProps) {
65
138
  width = _React$useContext2.width,
66
139
  height = _React$useContext2.height;
67
140
  var tickSize = disableTicks ? 4 : tickSizeProp;
141
+ var positionSign = position === 'bottom' ? 1 : -1;
142
+ var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
143
+ var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
144
+ var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
145
+ var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
146
+ var axisTickLabelProps = useSlotProps({
147
+ elementType: TickLabel,
148
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
149
+ additionalProps: {
150
+ style: _extends({
151
+ textAnchor: 'middle',
152
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
153
+ fontSize: tickFontSize != null ? tickFontSize : 12
154
+ }, tickLabelStyle),
155
+ className: classes.tickLabel
156
+ },
157
+ className: classes.tickLabel,
158
+ ownerState: {}
159
+ });
68
160
  var xTicks = useTicks({
69
161
  scale: xScale,
70
- ticksNumber: ticksNumber,
71
- valueFormatter: valueFormatter
162
+ tickNumber: tickNumber,
163
+ valueFormatter: valueFormatter,
164
+ tickInterval: tickInterval
165
+ });
166
+ var xTicksWithDimension = addLabelDimension(xTicks, {
167
+ tickLabelStyle: axisTickLabelProps.style,
168
+ tickLabelInterval: tickLabelInterval,
169
+ isMounted: isMounted
72
170
  });
73
- var positionSigne = position === 'bottom' ? 1 : -1;
74
171
  var labelRefPoint = {
75
172
  x: left + width / 2,
76
- y: positionSigne * (tickFontSize + tickSize + 10)
173
+ y: positionSign * (tickSize + 22)
77
174
  };
78
- var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
79
- var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
80
- var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
81
- var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
175
+ var axisLabelProps = useSlotProps({
176
+ elementType: Label,
177
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
178
+ additionalProps: {
179
+ style: _extends({
180
+ fontSize: labelFontSize != null ? labelFontSize : 14,
181
+ textAnchor: 'middle',
182
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
183
+ }, labelStyle)
184
+ },
185
+ ownerState: {}
186
+ });
82
187
  return /*#__PURE__*/_jsxs(AxisRoot, {
83
188
  transform: "translate(0, ".concat(position === 'bottom' ? top + height : top, ")"),
84
189
  className: classes.root,
@@ -86,39 +191,32 @@ function ChartsXAxis(inProps) {
86
191
  x1: xScale.range()[0],
87
192
  x2: xScale.range()[1],
88
193
  className: classes.line
89
- }, slotProps == null ? void 0 : slotProps.axisLine)), xTicks.map(function (_ref, index) {
90
- var formattedValue = _ref.formattedValue,
91
- offset = _ref.offset,
92
- labelOffset = _ref.labelOffset;
194
+ }, slotProps == null ? void 0 : slotProps.axisLine)), xTicksWithDimension.map(function (_ref2, index) {
195
+ var formattedValue = _ref2.formattedValue,
196
+ offset = _ref2.offset,
197
+ labelOffset = _ref2.labelOffset,
198
+ skipLabel = _ref2.skipLabel;
93
199
  var xTickLabel = labelOffset != null ? labelOffset : 0;
94
- var yTickLabel = positionSigne * (tickSize + 3);
200
+ var yTickLabel = positionSign * (tickSize + 3);
95
201
  return /*#__PURE__*/_jsxs("g", {
96
202
  transform: "translate(".concat(offset, ", 0)"),
97
203
  className: classes.tickContainer,
98
204
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
99
- y2: positionSigne * tickSize,
205
+ y2: positionSign * tickSize,
100
206
  className: classes.tick
101
- }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
207
+ }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
102
208
  x: xTickLabel,
103
- y: yTickLabel,
104
- "transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px"),
105
- sx: {
106
- fontSize: tickFontSize
107
- },
108
- className: classes.tickLabel
109
- }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
110
- children: formattedValue
209
+ y: yTickLabel
210
+ }, axisTickLabelProps, {
211
+ text: formattedValue.toString()
111
212
  }))]
112
213
  }, index);
113
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
114
- sx: {
115
- fontSize: labelFontSize,
116
- transformOrigin: "".concat(labelRefPoint.x, "px ").concat(labelRefPoint.y, "px")
117
- },
118
- className: classes.label
119
- }, slotProps == null ? void 0 : slotProps.axisLabel, {
120
- children: label
121
- }))]
214
+ }), label && /*#__PURE__*/_jsx("g", {
215
+ className: classes.label,
216
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
217
+ text: label
218
+ }))
219
+ })]
122
220
  });
123
221
  }
124
222
  process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
@@ -156,8 +254,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
156
254
  /**
157
255
  * The font size of the axis label.
158
256
  * @default 14
257
+ * @deprecated Consider using `labelStyle.fontSize` instead.
159
258
  */
160
259
  labelFontSize: PropTypes.number,
260
+ /**
261
+ * The style applied to the axis label.
262
+ */
263
+ labelStyle: PropTypes.object,
161
264
  /**
162
265
  * Position of the axis.
163
266
  */
@@ -180,8 +283,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
180
283
  /**
181
284
  * The font size of the axis ticks text.
182
285
  * @default 12
286
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
183
287
  */
184
288
  tickFontSize: PropTypes.number,
289
+ /**
290
+ * Defines which ticks are displayed. Its value can be:
291
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
292
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
293
+ * - an array containing the values where ticks should be displayed.
294
+ * @default 'auto'
295
+ */
296
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
297
+ /**
298
+ * Defines which ticks get its label displayed. Its value can be:
299
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
300
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
301
+ * @default 'auto'
302
+ */
303
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
304
+ /**
305
+ * The style applied to ticks text.
306
+ */
307
+ tickLabelStyle: PropTypes.object,
185
308
  /**
186
309
  * Maximal step between two ticks.
187
310
  * When using time data, the value is assumed to be in ms.
@@ -1,14 +1,16 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- var _excluded = ["scale", "ticksNumber"];
3
+ var _excluded = ["scale", "tickNumber"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
+ import { useSlotProps } from '@mui/base/utils';
6
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
8
9
  import { CartesianContext } from '../context/CartesianContextProvider';
9
10
  import { DrawingContext } from '../context/DrawingProvider';
10
11
  import useTicks from '../hooks/useTicks';
11
- import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
12
+ import { AxisRoot } from '../internals/components/AxisSharedComponents';
13
+ import { ChartsText } from '../internals/components/ChartsText';
12
14
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
15
  import { jsx as _jsx } from "react/jsx-runtime";
14
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -33,6 +35,16 @@ var defaultProps = {
33
35
  labelFontSize: 14,
34
36
  tickSize: 6
35
37
  };
38
+
39
+ /**
40
+ * Demos:
41
+ *
42
+ * - [Axis](https://mui.com/x/react-charts/axis/)
43
+ *
44
+ * API:
45
+ *
46
+ * - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
47
+ */
36
48
  function ChartsYAxis(inProps) {
37
49
  var _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
38
50
  var props = useThemeProps({
@@ -42,7 +54,7 @@ function ChartsYAxis(inProps) {
42
54
  var _React$useContext = React.useContext(CartesianContext),
43
55
  _React$useContext$yAx = _React$useContext.yAxis[props.axisId],
44
56
  yScale = _React$useContext$yAx.scale,
45
- ticksNumber = _React$useContext$yAx.ticksNumber,
57
+ tickNumber = _React$useContext$yAx.tickNumber,
46
58
  settings = _objectWithoutProperties(_React$useContext$yAx, _excluded);
47
59
  var defaultizedProps = _extends({}, defaultProps, settings, props);
48
60
  var position = defaultizedProps.position,
@@ -67,18 +79,44 @@ function ChartsYAxis(inProps) {
67
79
  var tickSize = disableTicks ? 4 : tickSizeProp;
68
80
  var yTicks = useTicks({
69
81
  scale: yScale,
70
- ticksNumber: ticksNumber,
82
+ tickNumber: tickNumber,
71
83
  valueFormatter: valueFormatter
72
84
  });
73
- var positionSigne = position === 'right' ? 1 : -1;
85
+ var positionSign = position === 'right' ? 1 : -1;
74
86
  var labelRefPoint = {
75
- x: positionSigne * (tickFontSize + tickSize + 10),
87
+ x: positionSign * (tickFontSize + tickSize + 10),
76
88
  y: top + height / 2
77
89
  };
78
- var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
79
- var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
80
- var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
81
- var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
90
+ var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
91
+ var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
92
+ var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
93
+ var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
94
+ var axisTickLabelProps = useSlotProps({
95
+ elementType: TickLabel,
96
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
97
+ additionalProps: {
98
+ style: {
99
+ fontSize: tickFontSize,
100
+ textAnchor: position === 'right' ? 'start' : 'end',
101
+ dominantBaseline: 'central'
102
+ },
103
+ className: classes.tickLabel
104
+ },
105
+ ownerState: {}
106
+ });
107
+ var axisLabelProps = useSlotProps({
108
+ elementType: Label,
109
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
110
+ additionalProps: {
111
+ style: {
112
+ fontSize: labelFontSize,
113
+ angle: positionSign * 90,
114
+ textAnchor: 'middle',
115
+ dominantBaseline: 'auto'
116
+ }
117
+ },
118
+ ownerState: {}
119
+ });
82
120
  return /*#__PURE__*/_jsxs(AxisRoot, {
83
121
  transform: "translate(".concat(position === 'right' ? left + width : left, ", 0)"),
84
122
  className: classes.root,
@@ -90,36 +128,26 @@ function ChartsYAxis(inProps) {
90
128
  var formattedValue = _ref.formattedValue,
91
129
  offset = _ref.offset,
92
130
  labelOffset = _ref.labelOffset;
93
- var xTickLabel = positionSigne * (tickSize + 2);
131
+ var xTickLabel = positionSign * (tickSize + 2);
94
132
  var yTickLabel = labelOffset;
95
133
  return /*#__PURE__*/_jsxs("g", {
96
134
  transform: "translate(0, ".concat(offset, ")"),
97
135
  className: classes.tickContainer,
98
136
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
99
- x2: positionSigne * tickSize,
137
+ x2: positionSign * tickSize,
100
138
  className: classes.tick
101
139
  }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
102
140
  x: xTickLabel,
103
141
  y: yTickLabel,
104
- "transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px"),
105
- sx: {
106
- fontSize: tickFontSize
107
- },
108
- className: classes.tickLabel
109
- }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
110
- children: formattedValue.toLocaleString()
111
- }))]
142
+ text: formattedValue.toString()
143
+ }, axisTickLabelProps))]
112
144
  }, index);
113
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
114
- sx: {
115
- fontSize: labelFontSize,
116
- transform: "rotate(".concat(positionSigne * 90, "deg)"),
117
- transformOrigin: "".concat(labelRefPoint.x, "px ").concat(labelRefPoint.y, "px")
118
- },
119
- className: classes.label
120
- }, slotProps == null ? void 0 : slotProps.axisLabel, {
121
- children: label
122
- }))]
145
+ }), label && /*#__PURE__*/_jsx("g", {
146
+ className: classes.label,
147
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
148
+ text: label
149
+ }))
150
+ })]
123
151
  });
124
152
  }
125
153
  process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
@@ -157,8 +185,13 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
157
185
  /**
158
186
  * The font size of the axis label.
159
187
  * @default 14
188
+ * @deprecated Consider using `labelStyle.fontSize` instead.
160
189
  */
161
190
  labelFontSize: PropTypes.number,
191
+ /**
192
+ * The style applied to the axis label.
193
+ */
194
+ labelStyle: PropTypes.object,
162
195
  /**
163
196
  * Position of the axis.
164
197
  */
@@ -181,8 +214,28 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
181
214
  /**
182
215
  * The font size of the axis ticks text.
183
216
  * @default 12
217
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
184
218
  */
185
219
  tickFontSize: PropTypes.number,
220
+ /**
221
+ * Defines which ticks are displayed. Its value can be:
222
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
223
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
224
+ * - an array containing the values where ticks should be displayed.
225
+ * @default 'auto'
226
+ */
227
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
228
+ /**
229
+ * Defines which ticks get its label displayed. Its value can be:
230
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
231
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
232
+ * @default 'auto'
233
+ */
234
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
235
+ /**
236
+ * The style applied to ticks text.
237
+ */
238
+ tickLabelStyle: PropTypes.object,
186
239
  /**
187
240
  * Maximal step between two ticks.
188
241
  * When using time data, the value is assumed to be in ms.
@@ -56,6 +56,16 @@ AreaElementPath.propTypes = {
56
56
  }).isRequired,
57
57
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
58
58
  };
59
+ /**
60
+ * Demos:
61
+ *
62
+ * - [Lines](https://mui.com/x/react-charts/lines/)
63
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
64
+ *
65
+ * API:
66
+ *
67
+ * - [AreaElement API](https://mui.com/x/api/charts/area-element/)
68
+ */
59
69
  function AreaElement(props) {
60
70
  var _slots$area;
61
71
  var id = props.id,
@@ -10,6 +10,17 @@ import { AreaElement } from './AreaElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ /**
14
+ * Demos:
15
+ *
16
+ * - [Lines](https://mui.com/x/react-charts/lines/)
17
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
18
+ * - [Stacking](https://mui.com/x/react-charts/stacking/)
19
+ *
20
+ * API:
21
+ *
22
+ * - [AreaPlot API](https://mui.com/x/api/charts/area-plot/)
23
+ */
13
24
  function AreaPlot(props) {
14
25
  var slots = props.slots,
15
26
  slotProps = props.slotProps,
@@ -31,32 +42,45 @@ function AreaPlot(props) {
31
42
  children: stackingGroups.flatMap(function (_ref) {
32
43
  var groupIds = _ref.ids;
33
44
  return groupIds.flatMap(function (seriesId) {
45
+ var _xData$map;
34
46
  var _series$seriesId = series[seriesId],
35
47
  _series$seriesId$xAxi = _series$seriesId.xAxisKey,
36
48
  xAxisKey = _series$seriesId$xAxi === void 0 ? defaultXAxisId : _series$seriesId$xAxi,
37
49
  _series$seriesId$yAxi = _series$seriesId.yAxisKey,
38
50
  yAxisKey = _series$seriesId$yAxi === void 0 ? defaultYAxisId : _series$seriesId$yAxi,
39
- stackedData = _series$seriesId.stackedData;
51
+ stackedData = _series$seriesId.stackedData,
52
+ data = _series$seriesId.data,
53
+ connectNulls = _series$seriesId.connectNulls;
40
54
  var xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
41
55
  var yScale = yAxis[yAxisKey].scale;
42
56
  var xData = xAxis[xAxisKey].data;
43
- if (xData === undefined) {
44
- throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot."));
57
+ if (process.env.NODE_ENV !== 'production') {
58
+ if (xData === undefined) {
59
+ throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot."));
60
+ }
61
+ if (xData.length < stackedData.length) {
62
+ throw new Error("MUI: data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
63
+ }
45
64
  }
46
65
  var areaPath = d3Area().x(function (d) {
47
66
  return xScale(d.x);
67
+ }).defined(function (_, i) {
68
+ return connectNulls || data[i] != null;
48
69
  }).y0(function (d) {
49
- return yScale(d.y[0]);
70
+ return d.y && yScale(d.y[0]);
50
71
  }).y1(function (d) {
51
- return yScale(d.y[1]);
72
+ return d.y && yScale(d.y[1]);
52
73
  });
53
74
  var curve = getCurveFactory(series[seriesId].curve);
54
- var d3Data = xData == null ? void 0 : xData.map(function (x, index) {
75
+ var formattedData = (_xData$map = xData == null ? void 0 : xData.map(function (x, index) {
55
76
  return {
56
77
  x: x,
57
78
  y: stackedData[index]
58
79
  };
59
- });
80
+ })) != null ? _xData$map : [];
81
+ var d3Data = connectNulls ? formattedData.filter(function (_, i) {
82
+ return data[i] != null;
83
+ }) : formattedData;
60
84
  return !!series[seriesId].area && /*#__PURE__*/_jsx(AreaElement, {
61
85
  id: seriesId,
62
86
  d: areaPath.curve(curve)(d3Data) || undefined,