@mui/x-charts 6.0.0-alpha.9 → 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 (281) 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 +735 -55
  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 +11 -1
  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 +16 -3
  44. package/LineChart/LineChart.js +48 -13
  45. package/LineChart/LineElement.d.ts +11 -1
  46. package/LineChart/LineElement.js +14 -6
  47. package/LineChart/LineHighlightElement.d.ts +10 -0
  48. package/LineChart/LineHighlightElement.js +13 -4
  49. package/LineChart/LineHighlightPlot.d.ts +10 -0
  50. package/LineChart/LineHighlightPlot.js +14 -3
  51. package/LineChart/LinePlot.d.ts +10 -0
  52. package/LineChart/LinePlot.js +25 -12
  53. package/LineChart/MarkElement.d.ts +10 -0
  54. package/LineChart/MarkElement.js +14 -5
  55. package/LineChart/MarkPlot.d.ts +10 -0
  56. package/LineChart/MarkPlot.js +40 -9
  57. package/LineChart/formatter.js +5 -5
  58. package/LineChart/legend.js +1 -2
  59. package/PieChart/PieArc.d.ts +11 -13
  60. package/PieChart/PieArc.js +28 -60
  61. package/PieChart/PieArcLabel.d.ts +8 -9
  62. package/PieChart/PieArcLabel.js +46 -38
  63. package/PieChart/PieArcLabelPlot.d.ts +28 -0
  64. package/PieChart/PieArcLabelPlot.js +99 -0
  65. package/PieChart/PieArcPlot.d.ts +35 -0
  66. package/PieChart/PieArcPlot.js +92 -0
  67. package/PieChart/PieChart.d.ts +19 -5
  68. package/PieChart/PieChart.js +61 -14
  69. package/PieChart/PiePlot.d.ts +15 -9
  70. package/PieChart/PiePlot.js +77 -55
  71. package/PieChart/dataTransform/transition.d.ts +4 -0
  72. package/PieChart/dataTransform/transition.js +136 -0
  73. package/PieChart/dataTransform/useTransformData.d.ts +15 -0
  74. package/PieChart/dataTransform/useTransformData.js +67 -0
  75. package/PieChart/formatter.js +1 -2
  76. package/PieChart/legend.js +1 -2
  77. package/README.md +8 -14
  78. package/ResponsiveChartContainer/index.js +7 -8
  79. package/ScatterChart/Scatter.d.ts +10 -0
  80. package/ScatterChart/Scatter.js +12 -2
  81. package/ScatterChart/ScatterChart.d.ts +16 -3
  82. package/ScatterChart/ScatterChart.js +43 -12
  83. package/ScatterChart/ScatterPlot.d.ts +10 -0
  84. package/ScatterChart/ScatterPlot.js +12 -2
  85. package/ScatterChart/formatter.js +1 -2
  86. package/ScatterChart/legend.js +1 -2
  87. package/SparkLineChart/SparkLineChart.d.ts +12 -3
  88. package/SparkLineChart/SparkLineChart.js +28 -7
  89. package/colorPalettes/colorPalettes.js +6 -12
  90. package/constants.js +5 -8
  91. package/context/CartesianContextProvider.d.ts +5 -0
  92. package/context/CartesianContextProvider.js +31 -16
  93. package/context/DrawingProvider.d.ts +7 -0
  94. package/context/DrawingProvider.js +12 -6
  95. package/context/HighlightProvider.js +3 -4
  96. package/context/InteractionProvider.js +3 -4
  97. package/context/SeriesContextProvider.js +3 -4
  98. package/esm/BarChart/BarChart.js +49 -9
  99. package/esm/BarChart/BarElement.js +7 -4
  100. package/esm/BarChart/BarPlot.js +152 -67
  101. package/esm/BarChart/formatter.js +1 -1
  102. package/esm/ChartContainer/index.js +3 -0
  103. package/esm/ChartsAxis/ChartsAxis.js +26 -0
  104. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
  105. package/esm/ChartsClipPath/ChartsClipPath.js +5 -0
  106. package/esm/ChartsLegend/ChartsLegend.js +188 -142
  107. package/esm/ChartsSurface.js +4 -12
  108. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
  109. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  110. package/esm/ChartsTooltip/ChartsTooltip.js +59 -14
  111. package/esm/ChartsTooltip/ChartsTooltipTable.js +17 -10
  112. package/esm/ChartsXAxis/ChartsXAxis.js +158 -37
  113. package/esm/ChartsYAxis/ChartsYAxis.js +83 -30
  114. package/esm/LineChart/AreaElement.js +10 -0
  115. package/esm/LineChart/AreaPlot.js +26 -6
  116. package/esm/LineChart/LineChart.js +45 -9
  117. package/esm/LineChart/LineElement.js +10 -0
  118. package/esm/LineChart/LineHighlightElement.js +10 -0
  119. package/esm/LineChart/LineHighlightPlot.js +12 -1
  120. package/esm/LineChart/LinePlot.js +25 -14
  121. package/esm/LineChart/MarkElement.js +11 -1
  122. package/esm/LineChart/MarkPlot.js +38 -7
  123. package/esm/LineChart/formatter.js +7 -3
  124. package/esm/PieChart/PieArc.js +26 -58
  125. package/esm/PieChart/PieArcLabel.js +43 -34
  126. package/esm/PieChart/PieArcLabelPlot.js +92 -0
  127. package/esm/PieChart/PieArcPlot.js +84 -0
  128. package/esm/PieChart/PieChart.js +59 -12
  129. package/esm/PieChart/PiePlot.js +76 -57
  130. package/esm/PieChart/dataTransform/transition.js +130 -0
  131. package/esm/PieChart/dataTransform/useTransformData.js +59 -0
  132. package/esm/ResponsiveChartContainer/index.js +3 -3
  133. package/esm/ScatterChart/Scatter.js +10 -0
  134. package/esm/ScatterChart/ScatterChart.js +40 -8
  135. package/esm/ScatterChart/ScatterPlot.js +10 -0
  136. package/esm/SparkLineChart/SparkLineChart.js +25 -3
  137. package/esm/constants.js +1 -1
  138. package/esm/context/CartesianContextProvider.js +30 -14
  139. package/esm/context/DrawingProvider.js +8 -0
  140. package/esm/hooks/useChartDimensions.js +2 -0
  141. package/esm/hooks/useMounted.js +16 -0
  142. package/esm/hooks/useReducedMotion.js +27 -0
  143. package/esm/hooks/useTicks.js +15 -9
  144. package/esm/internals/components/AxisSharedComponents.js +15 -70
  145. package/esm/internals/components/ChartsText.js +77 -0
  146. package/esm/internals/domUtils.js +113 -0
  147. package/esm/internals/geometry.js +36 -0
  148. package/hooks/useAxisEvents.js +2 -2
  149. package/hooks/useChartDimensions.d.ts +2 -0
  150. package/hooks/useChartDimensions.js +5 -4
  151. package/hooks/useDrawingArea.js +2 -2
  152. package/hooks/useInteractionItemProps.js +2 -2
  153. package/hooks/useMounted.d.ts +1 -0
  154. package/hooks/useMounted.js +25 -0
  155. package/hooks/useReducedMotion.d.ts +8 -0
  156. package/hooks/useReducedMotion.js +33 -0
  157. package/hooks/useScale.d.ts +2 -2
  158. package/hooks/useScale.js +2 -2
  159. package/hooks/useTicks.d.ts +19 -11
  160. package/hooks/useTicks.js +19 -14
  161. package/index.js +1 -1
  162. package/internals/components/AxisSharedComponents.d.ts +0 -4
  163. package/internals/components/AxisSharedComponents.js +18 -78
  164. package/internals/components/ChartsText.d.ts +35 -0
  165. package/internals/components/ChartsText.js +87 -0
  166. package/internals/defaultizeColor.d.ts +7 -2
  167. package/internals/defaultizeValueFormatter.js +1 -2
  168. package/internals/domUtils.d.ts +13 -0
  169. package/internals/domUtils.js +122 -0
  170. package/internals/geometry.d.ts +9 -0
  171. package/internals/geometry.js +42 -0
  172. package/internals/stackSeries.js +2 -4
  173. package/legacy/BarChart/BarChart.js +49 -9
  174. package/legacy/BarChart/BarElement.js +6 -3
  175. package/legacy/BarChart/BarPlot.js +151 -63
  176. package/legacy/BarChart/formatter.js +1 -1
  177. package/legacy/ChartContainer/index.js +3 -0
  178. package/legacy/ChartsAxis/ChartsAxis.js +26 -0
  179. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +60 -20
  180. package/legacy/ChartsClipPath/ChartsClipPath.js +5 -0
  181. package/legacy/ChartsLegend/ChartsLegend.js +203 -140
  182. package/legacy/ChartsSurface.js +3 -12
  183. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +22 -10
  184. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  185. package/legacy/ChartsTooltip/ChartsTooltip.js +62 -14
  186. package/legacy/ChartsTooltip/ChartsTooltipTable.js +34 -26
  187. package/legacy/ChartsXAxis/ChartsXAxis.js +162 -39
  188. package/legacy/ChartsYAxis/ChartsYAxis.js +83 -30
  189. package/legacy/LineChart/AreaElement.js +10 -0
  190. package/legacy/LineChart/AreaPlot.js +31 -7
  191. package/legacy/LineChart/LineChart.js +45 -9
  192. package/legacy/LineChart/LineElement.js +10 -0
  193. package/legacy/LineChart/LineHighlightElement.js +10 -0
  194. package/legacy/LineChart/LineHighlightPlot.js +12 -1
  195. package/legacy/LineChart/LinePlot.js +29 -12
  196. package/legacy/LineChart/MarkElement.js +11 -1
  197. package/legacy/LineChart/MarkPlot.js +37 -7
  198. package/legacy/LineChart/formatter.js +7 -3
  199. package/legacy/PieChart/PieArc.js +30 -62
  200. package/legacy/PieChart/PieArcLabel.js +48 -34
  201. package/legacy/PieChart/PieArcLabelPlot.js +93 -0
  202. package/legacy/PieChart/PieArcPlot.js +84 -0
  203. package/legacy/PieChart/PieChart.js +59 -12
  204. package/legacy/PieChart/PiePlot.js +76 -59
  205. package/legacy/PieChart/dataTransform/transition.js +142 -0
  206. package/legacy/PieChart/dataTransform/useTransformData.js +60 -0
  207. package/legacy/ResponsiveChartContainer/index.js +3 -3
  208. package/legacy/ScatterChart/Scatter.js +10 -0
  209. package/legacy/ScatterChart/ScatterChart.js +40 -8
  210. package/legacy/ScatterChart/ScatterPlot.js +10 -0
  211. package/legacy/SparkLineChart/SparkLineChart.js +25 -3
  212. package/legacy/constants.js +1 -1
  213. package/legacy/context/CartesianContextProvider.js +30 -14
  214. package/legacy/context/DrawingProvider.js +8 -0
  215. package/legacy/hooks/useChartDimensions.js +2 -0
  216. package/legacy/hooks/useMounted.js +21 -0
  217. package/legacy/hooks/useReducedMotion.js +27 -0
  218. package/legacy/hooks/useTicks.js +16 -9
  219. package/legacy/index.js +1 -1
  220. package/legacy/internals/components/AxisSharedComponents.js +11 -65
  221. package/legacy/internals/components/ChartsText.js +79 -0
  222. package/legacy/internals/domUtils.js +121 -0
  223. package/legacy/internals/geometry.js +37 -0
  224. package/models/axis.d.ts +27 -9
  225. package/models/layout.d.ts +7 -6
  226. package/models/seriesType/line.d.ts +8 -3
  227. package/models/seriesType/pie.d.ts +5 -1
  228. package/modern/BarChart/BarChart.js +49 -9
  229. package/modern/BarChart/BarElement.js +7 -4
  230. package/modern/BarChart/BarPlot.js +149 -65
  231. package/modern/BarChart/formatter.js +1 -1
  232. package/modern/ChartContainer/index.js +3 -0
  233. package/modern/ChartsAxis/ChartsAxis.js +26 -0
  234. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
  235. package/modern/ChartsClipPath/ChartsClipPath.js +5 -0
  236. package/modern/ChartsLegend/ChartsLegend.js +188 -142
  237. package/modern/ChartsSurface.js +4 -12
  238. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
  239. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  240. package/modern/ChartsTooltip/ChartsTooltip.js +58 -14
  241. package/modern/ChartsTooltip/ChartsTooltipTable.js +17 -10
  242. package/modern/ChartsXAxis/ChartsXAxis.js +158 -37
  243. package/modern/ChartsYAxis/ChartsYAxis.js +83 -30
  244. package/modern/LineChart/AreaElement.js +10 -0
  245. package/modern/LineChart/AreaPlot.js +25 -6
  246. package/modern/LineChart/LineChart.js +45 -9
  247. package/modern/LineChart/LineElement.js +10 -0
  248. package/modern/LineChart/LineHighlightElement.js +10 -0
  249. package/modern/LineChart/LineHighlightPlot.js +12 -1
  250. package/modern/LineChart/LinePlot.js +23 -10
  251. package/modern/LineChart/MarkElement.js +11 -1
  252. package/modern/LineChart/MarkPlot.js +38 -7
  253. package/modern/LineChart/formatter.js +4 -3
  254. package/modern/PieChart/PieArc.js +26 -57
  255. package/modern/PieChart/PieArcLabel.js +43 -34
  256. package/modern/PieChart/PieArcLabelPlot.js +90 -0
  257. package/modern/PieChart/PieArcPlot.js +83 -0
  258. package/modern/PieChart/PieChart.js +59 -12
  259. package/modern/PieChart/PiePlot.js +76 -55
  260. package/modern/PieChart/dataTransform/transition.js +130 -0
  261. package/modern/PieChart/dataTransform/useTransformData.js +58 -0
  262. package/modern/ResponsiveChartContainer/index.js +3 -3
  263. package/modern/ScatterChart/Scatter.js +10 -0
  264. package/modern/ScatterChart/ScatterChart.js +40 -8
  265. package/modern/ScatterChart/ScatterPlot.js +10 -0
  266. package/modern/SparkLineChart/SparkLineChart.js +25 -3
  267. package/modern/constants.js +1 -1
  268. package/modern/context/CartesianContextProvider.js +29 -13
  269. package/modern/context/DrawingProvider.js +8 -0
  270. package/modern/hooks/useChartDimensions.js +2 -0
  271. package/modern/hooks/useMounted.js +16 -0
  272. package/modern/hooks/useReducedMotion.js +27 -0
  273. package/modern/hooks/useTicks.js +15 -9
  274. package/modern/index.js +1 -1
  275. package/modern/internals/components/AxisSharedComponents.js +15 -70
  276. package/modern/internals/components/ChartsText.js +77 -0
  277. package/modern/internals/domUtils.js +113 -0
  278. package/modern/internals/geometry.js +36 -0
  279. package/package.json +9 -6
  280. package/themeAugmentation/components.d.ts +1 -0
  281. package/themeAugmentation/overrides.d.ts +2 -0
@@ -1,4 +1,6 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
3
+ import { useSlotProps } from '@mui/base/utils';
2
4
  import { SeriesContext } from '../context/SeriesContextProvider';
3
5
  import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltipPaper, ChartsTooltipRow } from './ChartsTooltipTable';
4
6
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -29,7 +31,6 @@ export function DefaultChartsItemContent(props) {
29
31
  const formattedValue = series.valueFormatter(series.data[itemData.dataIndex]);
30
32
  return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
31
33
  sx: sx,
32
- variant: "outlined",
33
34
  className: classes.root,
34
35
  children: /*#__PURE__*/_jsx(ChartsTooltipTable, {
35
36
  children: /*#__PURE__*/_jsx("tbody", {
@@ -58,14 +59,21 @@ export function ChartsItemTooltipContent(props) {
58
59
  content,
59
60
  itemData,
60
61
  sx,
61
- classes
62
+ classes,
63
+ contentProps
62
64
  } = props;
63
65
  const series = React.useContext(SeriesContext)[itemData.type].series[itemData.seriesId];
64
66
  const Content = content != null ? content : DefaultChartsItemContent;
65
- return /*#__PURE__*/_jsx(Content, {
66
- itemData: itemData,
67
- series: series,
68
- sx: sx,
69
- classes: classes
67
+ const chartTooltipContentProps = useSlotProps({
68
+ elementType: Content,
69
+ externalSlotProps: contentProps,
70
+ additionalProps: {
71
+ itemData,
72
+ series,
73
+ sx,
74
+ classes
75
+ },
76
+ ownerState: {}
70
77
  });
78
+ return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
71
79
  }
@@ -1,8 +1,11 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
2
3
  import PropTypes from 'prop-types';
3
- import { unstable_composeClasses as composeClasses } from '@mui/utils';
4
- import Popper from '@mui/material/Popper';
5
- import NoSsr from '@mui/material/NoSsr';
4
+ import composeClasses from '@mui/utils/composeClasses';
5
+ import { styled } from '@mui/material/styles';
6
+ import { Popper } from '@mui/base/Popper';
7
+ import { NoSsr } from '@mui/base/NoSsr';
8
+ import { useSlotProps } from '@mui/base/utils';
6
9
  import { InteractionContext } from '../context/InteractionProvider';
7
10
  import { generateVirtualElement, useMouseTracker, getTootipHasData } from './utils';
8
11
  import { ChartsItemTooltipContent } from './ChartsItemTooltipContent';
@@ -21,11 +24,34 @@ const useUtilityClasses = ownerState => {
21
24
  };
22
25
  return composeClasses(slots, getTooltipUtilityClass, classes);
23
26
  };
27
+ const ChartsTooltipRoot = styled(Popper, {
28
+ name: 'MuiChartsTooltip',
29
+ slot: 'Root',
30
+ overridesResolver: (_, styles) => styles.root
31
+ })(({
32
+ theme
33
+ }) => ({
34
+ pointerEvents: 'none',
35
+ zIndex: theme.zIndex.modal
36
+ }));
37
+
38
+ /**
39
+ * Demos:
40
+ *
41
+ * - [ChartsTooltip](https://mui.com/x/react-charts/tooltip/)
42
+ *
43
+ * API:
44
+ *
45
+ * - [ChartsTooltip API](https://mui.com/x/api/charts/charts-tool-tip/)
46
+ */
24
47
  function ChartsTooltip(props) {
48
+ var _slots$popper, _slots$itemContent, _slots$axisContent;
25
49
  const {
26
50
  trigger = 'axis',
27
51
  itemContent,
28
- axisContent
52
+ axisContent,
53
+ slots,
54
+ slotProps
29
55
  } = props;
30
56
  const mousePosition = useMouseTracker();
31
57
  const {
@@ -38,33 +64,40 @@ function ChartsTooltip(props) {
38
64
  const classes = useUtilityClasses({
39
65
  classes: props.classes
40
66
  });
67
+ const PopperComponent = (_slots$popper = slots == null ? void 0 : slots.popper) != null ? _slots$popper : ChartsTooltipRoot;
68
+ const popperProps = useSlotProps({
69
+ elementType: PopperComponent,
70
+ externalSlotProps: slotProps == null ? void 0 : slotProps.popper,
71
+ additionalProps: {
72
+ open: popperOpen,
73
+ placement: 'right-start',
74
+ anchorEl: generateVirtualElement(mousePosition)
75
+ },
76
+ ownerState: {}
77
+ });
41
78
  if (trigger === 'none') {
42
79
  return null;
43
80
  }
44
81
  return /*#__PURE__*/_jsx(NoSsr, {
45
- children: popperOpen && /*#__PURE__*/_jsx(Popper, {
46
- open: popperOpen,
47
- placement: "right-start",
48
- anchorEl: generateVirtualElement(mousePosition),
49
- style: {
50
- pointerEvents: 'none'
51
- },
82
+ children: popperOpen && /*#__PURE__*/_jsx(PopperComponent, _extends({}, popperProps, {
52
83
  children: trigger === 'item' ? /*#__PURE__*/_jsx(ChartsItemTooltipContent, {
53
84
  itemData: displayedData,
54
- content: itemContent,
85
+ content: (_slots$itemContent = slots == null ? void 0 : slots.itemContent) != null ? _slots$itemContent : itemContent,
86
+ contentProps: slotProps == null ? void 0 : slotProps.itemContent,
55
87
  sx: {
56
88
  mx: 2
57
89
  },
58
90
  classes: classes
59
91
  }) : /*#__PURE__*/_jsx(ChartsAxisTooltipContent, {
60
92
  axisData: displayedData,
61
- content: axisContent,
93
+ content: (_slots$axisContent = slots == null ? void 0 : slots.axisContent) != null ? _slots$axisContent : axisContent,
94
+ contentProps: slotProps == null ? void 0 : slotProps.axisContent,
62
95
  sx: {
63
96
  mx: 2
64
97
  },
65
98
  classes: classes
66
99
  })
67
- })
100
+ }))
68
101
  });
69
102
  }
70
103
  process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
@@ -74,6 +107,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
74
107
  // ----------------------------------------------------------------------
75
108
  /**
76
109
  * Component to override the tooltip content when triger is set to 'axis'.
110
+ * @deprecated Use slots.axisContent instead
77
111
  */
78
112
  axisContent: PropTypes.elementType,
79
113
  /**
@@ -82,8 +116,19 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
82
116
  classes: PropTypes.object,
83
117
  /**
84
118
  * Component to override the tooltip content when triger is set to 'item'.
119
+ * @deprecated Use slots.itemContent instead
85
120
  */
86
121
  itemContent: PropTypes.elementType,
122
+ /**
123
+ * The props used for each component slot.
124
+ * @default {}
125
+ */
126
+ slotProps: PropTypes.object,
127
+ /**
128
+ * Overridable component slots.
129
+ * @default {}
130
+ */
131
+ slots: PropTypes.object,
87
132
  /**
88
133
  * Select the kind of tooltip to display
89
134
  * - 'item': Shows data about the item below the mouse.
@@ -1,11 +1,18 @@
1
- import Box from '@mui/material/Box';
2
- import Paper from '@mui/material/Paper';
1
+ import Box from '@mui/system/Box';
3
2
  import { styled } from '@mui/material/styles';
4
3
  import { tooltipClasses } from './tooltipClasses';
5
- export const ChartsTooltipPaper = styled(Paper, {
4
+ export const ChartsTooltipPaper = styled('div', {
6
5
  name: 'MuiChartsTooltip',
7
- slot: 'Table'
8
- })({});
6
+ slot: 'Container'
7
+ })(({
8
+ theme
9
+ }) => ({
10
+ backgroundColor: (theme.vars || theme).palette.background.paper,
11
+ color: (theme.vars || theme).palette.text.primary,
12
+ transition: theme.transitions.create('box-shadow'),
13
+ border: `1px solid ${(theme.vars || theme).palette.divider}`,
14
+ borderRadius: theme.shape.borderRadius
15
+ }));
9
16
  export const ChartsTooltipTable = styled('table', {
10
17
  name: 'MuiChartsTooltip',
11
18
  slot: 'Table'
@@ -14,7 +21,7 @@ export const ChartsTooltipTable = styled('table', {
14
21
  }) => ({
15
22
  borderSpacing: 0,
16
23
  '& thead td': {
17
- borderBottom: `solid ${theme.palette.divider} 1px`
24
+ borderBottom: `solid ${(theme.vars || theme).palette.divider} 1px`
18
25
  }
19
26
  }));
20
27
  export const ChartsTooltipRow = styled('tr', {
@@ -37,13 +44,13 @@ export const ChartsTooltipCell = styled('td', {
37
44
  theme
38
45
  }) => ({
39
46
  verticalAlign: 'middle',
40
- color: theme.palette.text.secondary,
47
+ color: (theme.vars || theme).palette.text.secondary,
41
48
  [`&.${tooltipClasses.labelCell}`]: {
42
49
  paddingLeft: theme.spacing(1)
43
50
  },
44
51
  [`&.${tooltipClasses.valueCell}`]: {
45
52
  paddingLeft: theme.spacing(4),
46
- color: theme.palette.text.primary
53
+ color: (theme.vars || theme).palette.text.primary
47
54
  },
48
55
  'td:first-of-type&': {
49
56
  paddingLeft: theme.spacing(2)
@@ -63,7 +70,7 @@ export const ChartsTooltipMark = styled(Box, {
63
70
  height: theme.spacing(1),
64
71
  borderRadius: '50%',
65
72
  backgroundColor: ownerState.color,
66
- borderColor: theme.palette.background.paper,
67
- border: `solid ${theme.palette.background.paper} ${theme.spacing(0.25)}`,
73
+ borderColor: (theme.vars || theme).palette.background.paper,
74
+ border: `solid ${(theme.vars || theme).palette.background.paper} ${theme.spacing(0.25)}`,
68
75
  boxSizing: 'content-box'
69
76
  }));
@@ -1,15 +1,19 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["scale", "ticksNumber"];
3
+ const _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
12
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
12
- import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
13
+ import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
+ import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
15
+ import { getMinXTranslation } from '../internals/geometry';
16
+ import { useMounted } from '../hooks/useMounted';
13
17
  import { jsx as _jsx } from "react/jsx-runtime";
14
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
19
  const useUtilityClasses = ownerState => {
@@ -27,14 +31,76 @@ const useUtilityClasses = ownerState => {
27
31
  };
28
32
  return composeClasses(slots, getAxisUtilityClass, classes);
29
33
  };
34
+ function addLabelDimension(xTicks, {
35
+ tickLabelStyle: style,
36
+ tickLabelInterval,
37
+ isMounted
38
+ }) {
39
+ const withDimension = xTicks.map(tick => {
40
+ if (!isMounted || tick.formattedValue === undefined) {
41
+ return _extends({}, tick, {
42
+ width: 0,
43
+ height: 0
44
+ });
45
+ }
46
+ const tickSizes = getWordsByLines({
47
+ style,
48
+ needsComputation: true,
49
+ text: tick.formattedValue
50
+ });
51
+ return _extends({}, tick, {
52
+ width: Math.max(...tickSizes.map(size => size.width)),
53
+ height: Math.max(tickSizes.length * tickSizes[0].height)
54
+ });
55
+ });
56
+ if (typeof tickLabelInterval === 'function') {
57
+ return withDimension.map((item, index) => _extends({}, item, {
58
+ skipLabel: !tickLabelInterval(item.value, index)
59
+ }));
60
+ }
61
+
62
+ // Filter label to avoid overlap
63
+ let textStart = 0;
64
+ let textEnd = 0;
65
+ return withDimension.map((item, labelIndex) => {
66
+ const {
67
+ width,
68
+ offset,
69
+ labelOffset,
70
+ height
71
+ } = item;
72
+ const distance = getMinXTranslation(width, height, style == null ? void 0 : style.angle);
73
+ const textPosition = offset + labelOffset;
74
+ const 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
+ }
30
88
  const defaultProps = {
31
89
  position: 'bottom',
32
90
  disableLine: false,
33
91
  disableTicks: false,
34
- tickFontSize: 12,
35
- labelFontSize: 14,
36
92
  tickSize: 6
37
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
+ */
38
104
  function ChartsXAxis(inProps) {
39
105
  var _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
40
106
  const props = useThemeProps({
@@ -47,23 +113,28 @@ function ChartsXAxis(inProps) {
47
113
  xAxis: {
48
114
  [_props$axisId]: {
49
115
  scale: xScale,
50
- ticksNumber
116
+ tickNumber
51
117
  }
52
118
  }
53
119
  } = _React$useContext,
54
120
  settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_props$axisId], _excluded);
121
+ const isMounted = useMounted();
55
122
  const defaultizedProps = _extends({}, defaultProps, settings, props);
56
123
  const {
57
124
  position,
58
125
  disableLine,
59
126
  disableTicks,
60
- tickFontSize,
127
+ tickLabelStyle,
61
128
  label,
129
+ labelStyle,
130
+ tickFontSize,
62
131
  labelFontSize,
63
132
  tickSize: tickSizeProp,
64
133
  valueFormatter,
65
134
  slots,
66
- slotProps
135
+ slotProps,
136
+ tickInterval,
137
+ tickLabelInterval
67
138
  } = defaultizedProps;
68
139
  const theme = useTheme();
69
140
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
@@ -76,20 +147,52 @@ function ChartsXAxis(inProps) {
76
147
  height
77
148
  } = React.useContext(DrawingContext);
78
149
  const tickSize = disableTicks ? 4 : tickSizeProp;
150
+ const positionSign = position === 'bottom' ? 1 : -1;
151
+ const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
152
+ const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
153
+ const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
154
+ const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
155
+ const axisTickLabelProps = useSlotProps({
156
+ elementType: TickLabel,
157
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
158
+ additionalProps: {
159
+ style: _extends({
160
+ textAnchor: 'middle',
161
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
162
+ fontSize: tickFontSize != null ? tickFontSize : 12
163
+ }, tickLabelStyle),
164
+ className: classes.tickLabel
165
+ },
166
+ className: classes.tickLabel,
167
+ ownerState: {}
168
+ });
79
169
  const xTicks = useTicks({
80
170
  scale: xScale,
81
- ticksNumber,
82
- valueFormatter
171
+ tickNumber,
172
+ valueFormatter,
173
+ tickInterval
174
+ });
175
+ const xTicksWithDimension = addLabelDimension(xTicks, {
176
+ tickLabelStyle: axisTickLabelProps.style,
177
+ tickLabelInterval,
178
+ isMounted
83
179
  });
84
- const positionSigne = position === 'bottom' ? 1 : -1;
85
180
  const labelRefPoint = {
86
181
  x: left + width / 2,
87
- y: positionSigne * (tickFontSize + tickSize + 10)
182
+ y: positionSign * (tickSize + 22)
88
183
  };
89
- const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
90
- const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
91
- const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
92
- const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
184
+ const axisLabelProps = useSlotProps({
185
+ elementType: Label,
186
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
187
+ additionalProps: {
188
+ style: _extends({
189
+ fontSize: labelFontSize != null ? labelFontSize : 14,
190
+ textAnchor: 'middle',
191
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
192
+ }, labelStyle)
193
+ },
194
+ ownerState: {}
195
+ });
93
196
  return /*#__PURE__*/_jsxs(AxisRoot, {
94
197
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
95
198
  className: classes.root,
@@ -97,40 +200,33 @@ function ChartsXAxis(inProps) {
97
200
  x1: xScale.range()[0],
98
201
  x2: xScale.range()[1],
99
202
  className: classes.line
100
- }, slotProps == null ? void 0 : slotProps.axisLine)), xTicks.map(({
203
+ }, slotProps == null ? void 0 : slotProps.axisLine)), xTicksWithDimension.map(({
101
204
  formattedValue,
102
205
  offset,
103
- labelOffset
206
+ labelOffset,
207
+ skipLabel
104
208
  }, index) => {
105
209
  const xTickLabel = labelOffset != null ? labelOffset : 0;
106
- const yTickLabel = positionSigne * (tickSize + 3);
210
+ const yTickLabel = positionSign * (tickSize + 3);
107
211
  return /*#__PURE__*/_jsxs("g", {
108
212
  transform: `translate(${offset}, 0)`,
109
213
  className: classes.tickContainer,
110
214
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
111
- y2: positionSigne * tickSize,
215
+ y2: positionSign * tickSize,
112
216
  className: classes.tick
113
- }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
217
+ }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
114
218
  x: xTickLabel,
115
- y: yTickLabel,
116
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
117
- sx: {
118
- fontSize: tickFontSize
119
- },
120
- className: classes.tickLabel
121
- }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
122
- children: formattedValue
219
+ y: yTickLabel
220
+ }, axisTickLabelProps, {
221
+ text: formattedValue.toString()
123
222
  }))]
124
223
  }, index);
125
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
126
- sx: {
127
- fontSize: labelFontSize,
128
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
129
- },
130
- className: classes.label
131
- }, slotProps == null ? void 0 : slotProps.axisLabel, {
132
- children: label
133
- }))]
224
+ }), label && /*#__PURE__*/_jsx("g", {
225
+ className: classes.label,
226
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
227
+ text: label
228
+ }))
229
+ })]
134
230
  });
135
231
  }
136
232
  process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
@@ -168,8 +264,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
168
264
  /**
169
265
  * The font size of the axis label.
170
266
  * @default 14
267
+ * @deprecated Consider using `labelStyle.fontSize` instead.
171
268
  */
172
269
  labelFontSize: PropTypes.number,
270
+ /**
271
+ * The style applied to the axis label.
272
+ */
273
+ labelStyle: PropTypes.object,
173
274
  /**
174
275
  * Position of the axis.
175
276
  */
@@ -192,8 +293,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
192
293
  /**
193
294
  * The font size of the axis ticks text.
194
295
  * @default 12
296
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
195
297
  */
196
298
  tickFontSize: PropTypes.number,
299
+ /**
300
+ * Defines which ticks are displayed. Its value can be:
301
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
302
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
303
+ * - an array containing the values where ticks should be displayed.
304
+ * @default 'auto'
305
+ */
306
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
307
+ /**
308
+ * Defines which ticks get its label displayed. Its value can be:
309
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
310
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
311
+ * @default 'auto'
312
+ */
313
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
314
+ /**
315
+ * The style applied to ticks text.
316
+ */
317
+ tickLabelStyle: PropTypes.object,
197
318
  /**
198
319
  * Maximal step between two ticks.
199
320
  * When using time data, the value is assumed to be in ms.