@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,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,33 @@ 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) {
25
48
  const {
26
49
  trigger = 'axis',
27
50
  itemContent,
28
- axisContent
51
+ axisContent,
52
+ slots,
53
+ slotProps
29
54
  } = props;
30
55
  const mousePosition = useMouseTracker();
31
56
  const {
@@ -38,33 +63,40 @@ function ChartsTooltip(props) {
38
63
  const classes = useUtilityClasses({
39
64
  classes: props.classes
40
65
  });
66
+ const PopperComponent = slots?.popper ?? ChartsTooltipRoot;
67
+ const popperProps = useSlotProps({
68
+ elementType: PopperComponent,
69
+ externalSlotProps: slotProps?.popper,
70
+ additionalProps: {
71
+ open: popperOpen,
72
+ placement: 'right-start',
73
+ anchorEl: generateVirtualElement(mousePosition)
74
+ },
75
+ ownerState: {}
76
+ });
41
77
  if (trigger === 'none') {
42
78
  return null;
43
79
  }
44
80
  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
- },
81
+ children: popperOpen && /*#__PURE__*/_jsx(PopperComponent, _extends({}, popperProps, {
52
82
  children: trigger === 'item' ? /*#__PURE__*/_jsx(ChartsItemTooltipContent, {
53
83
  itemData: displayedData,
54
- content: itemContent,
84
+ content: slots?.itemContent ?? itemContent,
85
+ contentProps: slotProps?.itemContent,
55
86
  sx: {
56
87
  mx: 2
57
88
  },
58
89
  classes: classes
59
90
  }) : /*#__PURE__*/_jsx(ChartsAxisTooltipContent, {
60
91
  axisData: displayedData,
61
- content: axisContent,
92
+ content: slots?.axisContent ?? axisContent,
93
+ contentProps: slotProps?.axisContent,
62
94
  sx: {
63
95
  mx: 2
64
96
  },
65
97
  classes: classes
66
98
  })
67
- })
99
+ }))
68
100
  });
69
101
  }
70
102
  process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
@@ -74,6 +106,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
74
106
  // ----------------------------------------------------------------------
75
107
  /**
76
108
  * Component to override the tooltip content when triger is set to 'axis'.
109
+ * @deprecated Use slots.axisContent instead
77
110
  */
78
111
  axisContent: PropTypes.elementType,
79
112
  /**
@@ -82,8 +115,19 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
82
115
  classes: PropTypes.object,
83
116
  /**
84
117
  * Component to override the tooltip content when triger is set to 'item'.
118
+ * @deprecated Use slots.itemContent instead
85
119
  */
86
120
  itemContent: PropTypes.elementType,
121
+ /**
122
+ * The props used for each component slot.
123
+ * @default {}
124
+ */
125
+ slotProps: PropTypes.object,
126
+ /**
127
+ * Overridable component slots.
128
+ * @default {}
129
+ */
130
+ slots: PropTypes.object,
87
131
  /**
88
132
  * Select the kind of tooltip to display
89
133
  * - '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?.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
  const props = useThemeProps({
40
106
  props: _extends({}, defaultProps, inProps),
@@ -46,23 +112,28 @@ function ChartsXAxis(inProps) {
46
112
  xAxis: {
47
113
  [_props$axisId]: {
48
114
  scale: xScale,
49
- ticksNumber
115
+ tickNumber
50
116
  }
51
117
  }
52
118
  } = _React$useContext,
53
119
  settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_props$axisId], _excluded);
120
+ const isMounted = useMounted();
54
121
  const defaultizedProps = _extends({}, defaultProps, settings, props);
55
122
  const {
56
123
  position,
57
124
  disableLine,
58
125
  disableTicks,
59
- tickFontSize,
126
+ tickLabelStyle,
60
127
  label,
128
+ labelStyle,
129
+ tickFontSize,
61
130
  labelFontSize,
62
131
  tickSize: tickSizeProp,
63
132
  valueFormatter,
64
133
  slots,
65
- slotProps
134
+ slotProps,
135
+ tickInterval,
136
+ tickLabelInterval
66
137
  } = defaultizedProps;
67
138
  const theme = useTheme();
68
139
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
@@ -75,20 +146,52 @@ function ChartsXAxis(inProps) {
75
146
  height
76
147
  } = React.useContext(DrawingContext);
77
148
  const tickSize = disableTicks ? 4 : tickSizeProp;
149
+ const positionSign = position === 'bottom' ? 1 : -1;
150
+ const Line = slots?.axisLine ?? 'line';
151
+ const Tick = slots?.axisTick ?? 'line';
152
+ const TickLabel = slots?.axisTickLabel ?? ChartsText;
153
+ const Label = slots?.axisLabel ?? ChartsText;
154
+ const axisTickLabelProps = useSlotProps({
155
+ elementType: TickLabel,
156
+ externalSlotProps: slotProps?.axisTickLabel,
157
+ additionalProps: {
158
+ style: _extends({
159
+ textAnchor: 'middle',
160
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
161
+ fontSize: tickFontSize ?? 12
162
+ }, tickLabelStyle),
163
+ className: classes.tickLabel
164
+ },
165
+ className: classes.tickLabel,
166
+ ownerState: {}
167
+ });
78
168
  const xTicks = useTicks({
79
169
  scale: xScale,
80
- ticksNumber,
81
- valueFormatter
170
+ tickNumber,
171
+ valueFormatter,
172
+ tickInterval
173
+ });
174
+ const xTicksWithDimension = addLabelDimension(xTicks, {
175
+ tickLabelStyle: axisTickLabelProps.style,
176
+ tickLabelInterval,
177
+ isMounted
82
178
  });
83
- const positionSigne = position === 'bottom' ? 1 : -1;
84
179
  const labelRefPoint = {
85
180
  x: left + width / 2,
86
- y: positionSigne * (tickFontSize + tickSize + 10)
181
+ y: positionSign * (tickSize + 22)
87
182
  };
88
- const Line = slots?.axisLine ?? ChartsLine;
89
- const Tick = slots?.axisTick ?? ChartsTick;
90
- const TickLabel = slots?.axisTickLabel ?? ChartsTickLabel;
91
- const Label = slots?.axisLabel ?? ChartsLabel;
183
+ const axisLabelProps = useSlotProps({
184
+ elementType: Label,
185
+ externalSlotProps: slotProps?.axisLabel,
186
+ additionalProps: {
187
+ style: _extends({
188
+ fontSize: labelFontSize ?? 14,
189
+ textAnchor: 'middle',
190
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
191
+ }, labelStyle)
192
+ },
193
+ ownerState: {}
194
+ });
92
195
  return /*#__PURE__*/_jsxs(AxisRoot, {
93
196
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
94
197
  className: classes.root,
@@ -96,40 +199,33 @@ function ChartsXAxis(inProps) {
96
199
  x1: xScale.range()[0],
97
200
  x2: xScale.range()[1],
98
201
  className: classes.line
99
- }, slotProps?.axisLine)), xTicks.map(({
202
+ }, slotProps?.axisLine)), xTicksWithDimension.map(({
100
203
  formattedValue,
101
204
  offset,
102
- labelOffset
205
+ labelOffset,
206
+ skipLabel
103
207
  }, index) => {
104
208
  const xTickLabel = labelOffset ?? 0;
105
- const yTickLabel = positionSigne * (tickSize + 3);
209
+ const yTickLabel = positionSign * (tickSize + 3);
106
210
  return /*#__PURE__*/_jsxs("g", {
107
211
  transform: `translate(${offset}, 0)`,
108
212
  className: classes.tickContainer,
109
213
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
110
- y2: positionSigne * tickSize,
214
+ y2: positionSign * tickSize,
111
215
  className: classes.tick
112
- }, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
216
+ }, slotProps?.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
113
217
  x: xTickLabel,
114
- y: yTickLabel,
115
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
116
- sx: {
117
- fontSize: tickFontSize
118
- },
119
- className: classes.tickLabel
120
- }, slotProps?.axisTickLabel, {
121
- children: formattedValue
218
+ y: yTickLabel
219
+ }, axisTickLabelProps, {
220
+ text: formattedValue.toString()
122
221
  }))]
123
222
  }, index);
124
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
125
- sx: {
126
- fontSize: labelFontSize,
127
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
128
- },
129
- className: classes.label
130
- }, slotProps?.axisLabel, {
131
- children: label
132
- }))]
223
+ }), label && /*#__PURE__*/_jsx("g", {
224
+ className: classes.label,
225
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
226
+ text: label
227
+ }))
228
+ })]
133
229
  });
134
230
  }
135
231
  process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
@@ -167,8 +263,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
167
263
  /**
168
264
  * The font size of the axis label.
169
265
  * @default 14
266
+ * @deprecated Consider using `labelStyle.fontSize` instead.
170
267
  */
171
268
  labelFontSize: PropTypes.number,
269
+ /**
270
+ * The style applied to the axis label.
271
+ */
272
+ labelStyle: PropTypes.object,
172
273
  /**
173
274
  * Position of the axis.
174
275
  */
@@ -191,8 +292,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
191
292
  /**
192
293
  * The font size of the axis ticks text.
193
294
  * @default 12
295
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
194
296
  */
195
297
  tickFontSize: PropTypes.number,
298
+ /**
299
+ * Defines which ticks are displayed. Its value can be:
300
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
301
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
302
+ * - an array containing the values where ticks should be displayed.
303
+ * @default 'auto'
304
+ */
305
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
306
+ /**
307
+ * Defines which ticks get its label displayed. Its value can be:
308
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
309
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
310
+ * @default 'auto'
311
+ */
312
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
313
+ /**
314
+ * The style applied to ticks text.
315
+ */
316
+ tickLabelStyle: PropTypes.object,
196
317
  /**
197
318
  * Maximal step between two ticks.
198
319
  * When using time data, the value is assumed to be in ms.
@@ -1,14 +1,16 @@
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
- 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";
@@ -35,6 +37,16 @@ const defaultProps = {
35
37
  labelFontSize: 14,
36
38
  tickSize: 6
37
39
  };
40
+
41
+ /**
42
+ * Demos:
43
+ *
44
+ * - [Axis](https://mui.com/x/react-charts/axis/)
45
+ *
46
+ * API:
47
+ *
48
+ * - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
49
+ */
38
50
  function ChartsYAxis(inProps) {
39
51
  const props = useThemeProps({
40
52
  props: _extends({}, defaultProps, inProps),
@@ -46,7 +58,7 @@ function ChartsYAxis(inProps) {
46
58
  yAxis: {
47
59
  [_props$axisId]: {
48
60
  scale: yScale,
49
- ticksNumber
61
+ tickNumber
50
62
  }
51
63
  }
52
64
  } = _React$useContext,
@@ -77,18 +89,44 @@ function ChartsYAxis(inProps) {
77
89
  const tickSize = disableTicks ? 4 : tickSizeProp;
78
90
  const yTicks = useTicks({
79
91
  scale: yScale,
80
- ticksNumber,
92
+ tickNumber,
81
93
  valueFormatter
82
94
  });
83
- const positionSigne = position === 'right' ? 1 : -1;
95
+ const positionSign = position === 'right' ? 1 : -1;
84
96
  const labelRefPoint = {
85
- x: positionSigne * (tickFontSize + tickSize + 10),
97
+ x: positionSign * (tickFontSize + tickSize + 10),
86
98
  y: top + height / 2
87
99
  };
88
- const Line = slots?.axisLine ?? ChartsLine;
89
- const Tick = slots?.axisTick ?? ChartsTick;
90
- const TickLabel = slots?.axisTickLabel ?? ChartsTickLabel;
91
- const Label = slots?.axisLabel ?? ChartsLabel;
100
+ const Line = slots?.axisLine ?? 'line';
101
+ const Tick = slots?.axisTick ?? 'line';
102
+ const TickLabel = slots?.axisTickLabel ?? ChartsText;
103
+ const Label = slots?.axisLabel ?? ChartsText;
104
+ const axisTickLabelProps = useSlotProps({
105
+ elementType: TickLabel,
106
+ externalSlotProps: slotProps?.axisTickLabel,
107
+ additionalProps: {
108
+ style: {
109
+ fontSize: tickFontSize,
110
+ textAnchor: position === 'right' ? 'start' : 'end',
111
+ dominantBaseline: 'central'
112
+ },
113
+ className: classes.tickLabel
114
+ },
115
+ ownerState: {}
116
+ });
117
+ const axisLabelProps = useSlotProps({
118
+ elementType: Label,
119
+ externalSlotProps: slotProps?.axisLabel,
120
+ additionalProps: {
121
+ style: {
122
+ fontSize: labelFontSize,
123
+ angle: positionSign * 90,
124
+ textAnchor: 'middle',
125
+ dominantBaseline: 'auto'
126
+ }
127
+ },
128
+ ownerState: {}
129
+ });
92
130
  return /*#__PURE__*/_jsxs(AxisRoot, {
93
131
  transform: `translate(${position === 'right' ? left + width : left}, 0)`,
94
132
  className: classes.root,
@@ -101,36 +139,26 @@ function ChartsYAxis(inProps) {
101
139
  offset,
102
140
  labelOffset
103
141
  }, index) => {
104
- const xTickLabel = positionSigne * (tickSize + 2);
142
+ const xTickLabel = positionSign * (tickSize + 2);
105
143
  const yTickLabel = labelOffset;
106
144
  return /*#__PURE__*/_jsxs("g", {
107
145
  transform: `translate(0, ${offset})`,
108
146
  className: classes.tickContainer,
109
147
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
110
- x2: positionSigne * tickSize,
148
+ x2: positionSign * tickSize,
111
149
  className: classes.tick
112
150
  }, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
113
151
  x: xTickLabel,
114
152
  y: yTickLabel,
115
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
116
- sx: {
117
- fontSize: tickFontSize
118
- },
119
- className: classes.tickLabel
120
- }, slotProps?.axisTickLabel, {
121
- children: formattedValue.toLocaleString()
122
- }))]
153
+ text: formattedValue.toString()
154
+ }, axisTickLabelProps))]
123
155
  }, index);
124
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
125
- sx: {
126
- fontSize: labelFontSize,
127
- transform: `rotate(${positionSigne * 90}deg)`,
128
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
129
- },
130
- className: classes.label
131
- }, slotProps?.axisLabel, {
132
- children: label
133
- }))]
156
+ }), label && /*#__PURE__*/_jsx("g", {
157
+ className: classes.label,
158
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
159
+ text: label
160
+ }))
161
+ })]
134
162
  });
135
163
  }
136
164
  process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
@@ -168,8 +196,13 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
168
196
  /**
169
197
  * The font size of the axis label.
170
198
  * @default 14
199
+ * @deprecated Consider using `labelStyle.fontSize` instead.
171
200
  */
172
201
  labelFontSize: PropTypes.number,
202
+ /**
203
+ * The style applied to the axis label.
204
+ */
205
+ labelStyle: PropTypes.object,
173
206
  /**
174
207
  * Position of the axis.
175
208
  */
@@ -192,8 +225,28 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
192
225
  /**
193
226
  * The font size of the axis ticks text.
194
227
  * @default 12
228
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
195
229
  */
196
230
  tickFontSize: PropTypes.number,
231
+ /**
232
+ * Defines which ticks are displayed. Its value can be:
233
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
234
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
235
+ * - an array containing the values where ticks should be displayed.
236
+ * @default 'auto'
237
+ */
238
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
239
+ /**
240
+ * Defines which ticks get its label displayed. Its value can be:
241
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
242
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
243
+ * @default 'auto'
244
+ */
245
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
246
+ /**
247
+ * The style applied to ticks text.
248
+ */
249
+ tickLabelStyle: PropTypes.object,
197
250
  /**
198
251
  * Maximal step between two ticks.
199
252
  * When using time data, the value is assumed to be in ms.
@@ -55,6 +55,16 @@ AreaElementPath.propTypes = {
55
55
  }).isRequired,
56
56
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
57
57
  };
58
+ /**
59
+ * Demos:
60
+ *
61
+ * - [Lines](https://mui.com/x/react-charts/lines/)
62
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
63
+ *
64
+ * API:
65
+ *
66
+ * - [AreaElement API](https://mui.com/x/api/charts/area-element/)
67
+ */
58
68
  function AreaElement(props) {
59
69
  const {
60
70
  id,