@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.2

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 (258) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +33 -12
  3. package/BarChart/BarElement.d.ts +20 -13
  4. package/BarChart/BarElement.js +7 -3
  5. package/BarChart/BarPlot.d.ts +11 -6
  6. package/BarChart/BarPlot.js +28 -15
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +406 -1
  9. package/ChartContainer/ChartContainer.js +6 -4
  10. package/ChartsAxis/ChartsAxis.js +4 -4
  11. package/ChartsLegend/ChartsLegend.d.ts +5 -54
  12. package/ChartsLegend/ChartsLegend.js +2 -307
  13. package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
  14. package/ChartsLegend/DefaultChartsLegend.js +294 -0
  15. package/ChartsLegend/index.d.ts +1 -0
  16. package/ChartsLegend/index.js +11 -0
  17. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  18. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  19. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  20. package/ChartsOnAxisClickHandler/index.js +16 -0
  21. package/ChartsOnAxisClickHandler/package.json +6 -0
  22. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  23. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  24. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  25. package/ChartsReferenceLine/common.d.ts +2 -1
  26. package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  27. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  28. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
  29. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  30. package/ChartsTooltip/utils.d.ts +4 -1
  31. package/ChartsTooltip/utils.js +15 -0
  32. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  33. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  34. package/ChartsXAxis/ChartsXAxis.js +13 -9
  35. package/ChartsYAxis/ChartsYAxis.js +1 -1
  36. package/LineChart/AnimatedArea.d.ts +1361 -0
  37. package/LineChart/AnimatedArea.js +111 -0
  38. package/LineChart/AnimatedLine.d.ts +1361 -0
  39. package/LineChart/AnimatedLine.js +113 -0
  40. package/LineChart/AreaElement.d.ts +19 -18
  41. package/LineChart/AreaElement.js +17 -34
  42. package/LineChart/AreaPlot.d.ts +12 -7
  43. package/LineChart/AreaPlot.js +91 -58
  44. package/LineChart/LineChart.d.ts +13 -4
  45. package/LineChart/LineChart.js +45 -14
  46. package/LineChart/LineElement.d.ts +19 -18
  47. package/LineChart/LineElement.js +16 -36
  48. package/LineChart/LineHighlightElement.d.ts +3 -2
  49. package/LineChart/LineHighlightElement.js +5 -3
  50. package/LineChart/LinePlot.d.ts +12 -7
  51. package/LineChart/LinePlot.js +89 -56
  52. package/LineChart/MarkElement.d.ts +8 -4
  53. package/LineChart/MarkElement.js +27 -13
  54. package/LineChart/MarkPlot.d.ts +8 -1
  55. package/LineChart/MarkPlot.js +80 -51
  56. package/LineChart/formatter.js +1 -1
  57. package/LineChart/index.d.ts +2 -0
  58. package/LineChart/index.js +22 -0
  59. package/PieChart/PieArc.d.ts +3 -2
  60. package/PieChart/PieArc.js +1 -0
  61. package/PieChart/PieArcLabel.d.ts +3 -2
  62. package/PieChart/PieArcLabel.js +1 -0
  63. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  64. package/PieChart/PieArcLabelPlot.js +2 -2
  65. package/PieChart/PieArcPlot.d.ts +2 -2
  66. package/PieChart/PieArcPlot.js +7 -7
  67. package/PieChart/PieChart.d.ts +1 -1
  68. package/PieChart/PieChart.js +14 -12
  69. package/PieChart/PiePlot.d.ts +1 -1
  70. package/PieChart/PiePlot.js +4 -4
  71. package/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  72. package/ScatterChart/Scatter.d.ts +7 -1
  73. package/ScatterChart/Scatter.js +17 -3
  74. package/ScatterChart/ScatterChart.d.ts +8 -2
  75. package/ScatterChart/ScatterChart.js +21 -10
  76. package/ScatterChart/ScatterPlot.d.ts +1 -1
  77. package/ScatterChart/ScatterPlot.js +10 -2
  78. package/SparkLineChart/SparkLineChart.d.ts +1 -1
  79. package/SparkLineChart/SparkLineChart.js +7 -4
  80. package/context/CartesianContextProvider.js +8 -6
  81. package/context/DrawingProvider.d.ts +6 -1
  82. package/context/DrawingProvider.js +9 -2
  83. package/context/InteractionProvider.d.ts +3 -3
  84. package/esm/BarChart/BarChart.js +33 -12
  85. package/esm/BarChart/BarElement.js +7 -3
  86. package/esm/BarChart/BarPlot.js +27 -15
  87. package/esm/BarChart/formatter.js +1 -1
  88. package/esm/ChartContainer/ChartContainer.js +6 -4
  89. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  90. package/esm/ChartsLegend/ChartsLegend.js +2 -307
  91. package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
  92. package/esm/ChartsLegend/index.js +1 -0
  93. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  94. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  95. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  96. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  97. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  98. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  99. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  100. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
  101. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  102. package/esm/ChartsTooltip/utils.js +12 -0
  103. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  104. package/esm/ChartsXAxis/ChartsXAxis.js +13 -9
  105. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  106. package/esm/LineChart/AnimatedArea.js +103 -0
  107. package/esm/LineChart/AnimatedLine.js +105 -0
  108. package/esm/LineChart/AreaElement.js +16 -33
  109. package/esm/LineChart/AreaPlot.js +92 -59
  110. package/esm/LineChart/LineChart.js +45 -14
  111. package/esm/LineChart/LineElement.js +16 -35
  112. package/esm/LineChart/LineHighlightElement.js +5 -3
  113. package/esm/LineChart/LinePlot.js +90 -57
  114. package/esm/LineChart/MarkElement.js +27 -13
  115. package/esm/LineChart/MarkPlot.js +80 -51
  116. package/esm/LineChart/formatter.js +1 -1
  117. package/esm/LineChart/index.js +2 -0
  118. package/esm/PieChart/PieArc.js +1 -0
  119. package/esm/PieChart/PieArcLabel.js +1 -0
  120. package/esm/PieChart/PieArcLabelPlot.js +2 -2
  121. package/esm/PieChart/PieArcPlot.js +7 -7
  122. package/esm/PieChart/PieChart.js +14 -12
  123. package/esm/PieChart/PiePlot.js +4 -4
  124. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  125. package/esm/ScatterChart/Scatter.js +17 -3
  126. package/esm/ScatterChart/ScatterChart.js +21 -10
  127. package/esm/ScatterChart/ScatterPlot.js +10 -2
  128. package/esm/SparkLineChart/SparkLineChart.js +7 -4
  129. package/esm/context/CartesianContextProvider.js +8 -6
  130. package/esm/context/DrawingProvider.js +9 -2
  131. package/esm/hooks/useDrawingArea.js +7 -3
  132. package/esm/index.js +1 -0
  133. package/esm/internals/geometry.js +1 -1
  134. package/esm/internals/useAnimatedPath.js +29 -0
  135. package/esm/internals/utils.js +7 -0
  136. package/hooks/useDrawingArea.d.ts +2 -0
  137. package/hooks/useDrawingArea.js +7 -3
  138. package/index.d.ts +1 -0
  139. package/index.js +12 -1
  140. package/internals/defaultizeColor.d.ts +16 -16
  141. package/internals/defaultizeValueFormatter.d.ts +4 -7
  142. package/internals/geometry.js +1 -1
  143. package/internals/stackSeries.d.ts +4 -7
  144. package/internals/useAnimatedPath.d.ts +1 -0
  145. package/internals/useAnimatedPath.js +38 -0
  146. package/internals/utils.d.ts +4 -0
  147. package/internals/utils.js +8 -0
  148. package/legacy/BarChart/BarChart.js +33 -12
  149. package/legacy/BarChart/BarElement.js +6 -2
  150. package/legacy/BarChart/BarPlot.js +28 -14
  151. package/legacy/BarChart/formatter.js +1 -1
  152. package/legacy/ChartContainer/ChartContainer.js +6 -4
  153. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  154. package/legacy/ChartsLegend/ChartsLegend.js +2 -323
  155. package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
  156. package/legacy/ChartsLegend/index.js +1 -0
  157. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  158. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  159. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  160. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  161. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  162. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
  163. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  164. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
  165. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  166. package/legacy/ChartsTooltip/utils.js +12 -0
  167. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  168. package/legacy/ChartsXAxis/ChartsXAxis.js +12 -8
  169. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  170. package/legacy/LineChart/AnimatedArea.js +102 -0
  171. package/legacy/LineChart/AnimatedLine.js +104 -0
  172. package/legacy/LineChart/AreaElement.js +15 -35
  173. package/legacy/LineChart/AreaPlot.js +102 -66
  174. package/legacy/LineChart/LineChart.js +45 -14
  175. package/legacy/LineChart/LineElement.js +15 -37
  176. package/legacy/LineChart/LineHighlightElement.js +5 -3
  177. package/legacy/LineChart/LinePlot.js +97 -63
  178. package/legacy/LineChart/MarkElement.js +30 -12
  179. package/legacy/LineChart/MarkPlot.js +83 -53
  180. package/legacy/LineChart/formatter.js +1 -1
  181. package/legacy/LineChart/index.js +2 -0
  182. package/legacy/PieChart/PieArc.js +1 -0
  183. package/legacy/PieChart/PieArcLabel.js +1 -0
  184. package/legacy/PieChart/PieArcLabelPlot.js +2 -2
  185. package/legacy/PieChart/PieArcPlot.js +7 -7
  186. package/legacy/PieChart/PieChart.js +14 -12
  187. package/legacy/PieChart/PiePlot.js +4 -4
  188. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  189. package/legacy/ScatterChart/Scatter.js +19 -3
  190. package/legacy/ScatterChart/ScatterChart.js +21 -10
  191. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  192. package/legacy/SparkLineChart/SparkLineChart.js +8 -5
  193. package/legacy/context/CartesianContextProvider.js +8 -6
  194. package/legacy/context/DrawingProvider.js +11 -2
  195. package/legacy/hooks/useDrawingArea.js +7 -3
  196. package/legacy/index.js +2 -1
  197. package/legacy/internals/geometry.js +1 -1
  198. package/legacy/internals/useAnimatedPath.js +32 -0
  199. package/legacy/internals/utils.js +7 -0
  200. package/models/axis.d.ts +7 -2
  201. package/models/seriesType/common.d.ts +2 -1
  202. package/models/seriesType/config.d.ts +7 -12
  203. package/models/seriesType/line.d.ts +2 -2
  204. package/models/seriesType/pie.d.ts +7 -3
  205. package/models/seriesType/scatter.d.ts +5 -2
  206. package/modern/BarChart/BarChart.js +33 -12
  207. package/modern/BarChart/BarElement.js +7 -3
  208. package/modern/BarChart/BarPlot.js +27 -15
  209. package/modern/BarChart/formatter.js +1 -1
  210. package/modern/ChartContainer/ChartContainer.js +6 -4
  211. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  212. package/modern/ChartsLegend/ChartsLegend.js +2 -307
  213. package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
  214. package/modern/ChartsLegend/index.js +1 -0
  215. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  216. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  217. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  218. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  219. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  220. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  221. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  222. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
  223. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  224. package/modern/ChartsTooltip/utils.js +12 -0
  225. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  226. package/modern/ChartsXAxis/ChartsXAxis.js +13 -9
  227. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  228. package/modern/LineChart/AnimatedArea.js +103 -0
  229. package/modern/LineChart/AnimatedLine.js +105 -0
  230. package/modern/LineChart/AreaElement.js +16 -33
  231. package/modern/LineChart/AreaPlot.js +91 -58
  232. package/modern/LineChart/LineChart.js +45 -14
  233. package/modern/LineChart/LineElement.js +16 -35
  234. package/modern/LineChart/LineHighlightElement.js +5 -3
  235. package/modern/LineChart/LinePlot.js +89 -56
  236. package/modern/LineChart/MarkElement.js +27 -13
  237. package/modern/LineChart/MarkPlot.js +80 -51
  238. package/modern/LineChart/formatter.js +1 -1
  239. package/modern/LineChart/index.js +2 -0
  240. package/modern/PieChart/PieArc.js +1 -0
  241. package/modern/PieChart/PieArcLabel.js +1 -0
  242. package/modern/PieChart/PieArcLabelPlot.js +2 -2
  243. package/modern/PieChart/PieArcPlot.js +7 -7
  244. package/modern/PieChart/PieChart.js +14 -12
  245. package/modern/PieChart/PiePlot.js +4 -4
  246. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  247. package/modern/ScatterChart/Scatter.js +17 -3
  248. package/modern/ScatterChart/ScatterChart.js +21 -10
  249. package/modern/ScatterChart/ScatterPlot.js +10 -2
  250. package/modern/SparkLineChart/SparkLineChart.js +7 -4
  251. package/modern/context/CartesianContextProvider.js +8 -6
  252. package/modern/context/DrawingProvider.js +9 -2
  253. package/modern/hooks/useDrawingArea.js +7 -3
  254. package/modern/index.js +2 -1
  255. package/modern/internals/geometry.js +1 -1
  256. package/modern/internals/useAnimatedPath.js +29 -0
  257. package/modern/internals/utils.js +7 -0
  258. package/package.json +6 -5
@@ -10,7 +10,7 @@ function ChartsReferenceLine(props) {
10
10
  y
11
11
  } = props;
12
12
  if (x !== undefined && y !== undefined) {
13
- throw new Error('MUI X Charts: The ChartsReferenceLine can not have both `x` and `y` props set.');
13
+ throw new Error('MUI X Charts: The ChartsReferenceLine cannot have both `x` and `y` props set.');
14
14
  }
15
15
  if (x === undefined && y === undefined) {
16
16
  throw new Error('MUI X Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
@@ -29,7 +29,7 @@ process.env.NODE_ENV !== "production" ? ChartsReferenceLine.propTypes = {
29
29
  * The id of the axis used for the reference value.
30
30
  * @default The `id` of the first defined axis.
31
31
  */
32
- axisId: PropTypes.string,
32
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
33
33
  /**
34
34
  * Override or extend the styles applied to the component.
35
35
  */
@@ -69,7 +69,7 @@ function ChartsXReferenceLine(props) {
69
69
  if (process.env.NODE_ENV !== 'production') {
70
70
  if (!warnedOnce) {
71
71
  warnedOnce = true;
72
- console.error(`MUI X: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
72
+ console.error(`MUI X Charts: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
73
73
  }
74
74
  }
75
75
  return null;
@@ -69,7 +69,7 @@ function ChartsYReferenceLine(props) {
69
69
  if (process.env.NODE_ENV !== 'production') {
70
70
  if (!warnedOnce) {
71
71
  warnedOnce = true;
72
- console.error(`MUI X: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
72
+ console.error(`MUI X Charts: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
73
73
  }
74
74
  }
75
75
  return null;
@@ -5,6 +5,7 @@ import { useSlotProps } from '@mui/base/utils';
5
5
  import { SeriesContext } from '../context/SeriesContextProvider';
6
6
  import { CartesianContext } from '../context/CartesianContextProvider';
7
7
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
8
+ import { isCartesianSeriesType } from './utils';
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
10
  function ChartsAxisTooltipContent(props) {
10
11
  const {
@@ -27,7 +28,7 @@ function ChartsAxisTooltipContent(props) {
27
28
  const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
28
29
  const relevantSeries = React.useMemo(() => {
29
30
  const rep = [];
30
- Object.keys(series).filter(seriesType => ['bar', 'line', 'scatter'].includes(seriesType)).forEach(seriesType => {
31
+ Object.keys(series).filter(isCartesianSeriesType).forEach(seriesType => {
31
32
  series[seriesType].seriesOrder.forEach(seriesId => {
32
33
  const item = series[seriesType].series[seriesId];
33
34
  const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
@@ -66,11 +67,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
66
67
  axisData: PropTypes.shape({
67
68
  x: PropTypes.shape({
68
69
  index: PropTypes.number,
69
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
70
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
70
71
  }),
71
72
  y: PropTypes.shape({
72
73
  index: PropTypes.number,
73
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
74
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
74
75
  })
75
76
  }).isRequired,
76
77
  classes: PropTypes.object.isRequired,
@@ -80,11 +81,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
80
81
  axisData: PropTypes.shape({
81
82
  x: PropTypes.shape({
82
83
  index: PropTypes.number,
83
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
84
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
84
85
  }),
85
86
  y: PropTypes.shape({
86
87
  index: PropTypes.number,
87
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
88
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
88
89
  })
89
90
  }),
90
91
  axisValue: PropTypes.any,
@@ -39,7 +39,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
39
39
  classes: PropTypes.object,
40
40
  itemData: PropTypes.shape({
41
41
  dataIndex: PropTypes.number,
42
- seriesId: PropTypes.string.isRequired,
42
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
43
43
  type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
44
44
  }),
45
45
  series: PropTypes.object,
@@ -47,7 +47,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
47
47
  }),
48
48
  itemData: PropTypes.shape({
49
49
  dataIndex: PropTypes.number,
50
- seriesId: PropTypes.string.isRequired,
50
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
51
51
  type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
52
52
  }).isRequired,
53
53
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import clsx from 'clsx';
4
4
  import Typography from '@mui/material/Typography';
5
5
  import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
6
+ import { isCartesianSeries, utcFormatter } from './utils';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
9
  function DefaultChartsAxisTooltipContent(props) {
@@ -17,7 +18,7 @@ function DefaultChartsAxisTooltipContent(props) {
17
18
  if (dataIndex == null) {
18
19
  return null;
19
20
  }
20
- const axisFormatter = axis.valueFormatter ?? (v => v.toLocaleString());
21
+ const axisFormatter = axis.valueFormatter ?? (v => axis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString());
21
22
  return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
22
23
  sx: sx,
23
24
  className: classes.root,
@@ -33,14 +34,15 @@ function DefaultChartsAxisTooltipContent(props) {
33
34
  })
34
35
  })
35
36
  }), /*#__PURE__*/_jsx("tbody", {
36
- children: series.map(({
37
+ children: series.filter(isCartesianSeries).map(({
37
38
  color,
38
39
  id,
39
40
  label,
40
41
  valueFormatter,
41
42
  data
42
43
  }) => {
43
- const formattedValue = valueFormatter(data[dataIndex]);
44
+ // @ts-ignore
45
+ const formattedValue = valueFormatter(data[dataIndex] ?? null);
44
46
  if (formattedValue == null) {
45
47
  return null;
46
48
  }
@@ -87,11 +89,11 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
87
89
  axisData: PropTypes.shape({
88
90
  x: PropTypes.shape({
89
91
  index: PropTypes.number,
90
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
92
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
91
93
  }),
92
94
  y: PropTypes.shape({
93
95
  index: PropTypes.number,
94
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
96
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
95
97
  })
96
98
  }).isRequired,
97
99
  /**
@@ -68,7 +68,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
68
68
  */
69
69
  itemData: PropTypes.shape({
70
70
  dataIndex: PropTypes.number,
71
- seriesId: PropTypes.string.isRequired,
71
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
72
72
  type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
73
73
  }).isRequired,
74
74
  /**
@@ -78,4 +78,16 @@ export function getTooltipHasData(trigger, displayedData) {
78
78
  const hasAxisXData = displayedData.x !== null;
79
79
  const hasAxisYData = displayedData.y !== null;
80
80
  return hasAxisXData || hasAxisYData;
81
+ }
82
+ export function isCartesianSeriesType(seriesType) {
83
+ return ['bar', 'line', 'scatter'].includes(seriesType);
84
+ }
85
+ export function isCartesianSeries(series) {
86
+ return isCartesianSeriesType(series.type);
87
+ }
88
+ export function utcFormatter(v) {
89
+ if (v instanceof Date) {
90
+ return v.toUTCString();
91
+ }
92
+ return v.toLocaleString();
81
93
  }
@@ -11,7 +11,8 @@ import { getSVGPoint } from '../internals/utils';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  function ChartsVoronoiHandler(props) {
13
13
  const {
14
- voronoiMaxRadius
14
+ voronoiMaxRadius,
15
+ onItemClick
15
16
  } = props;
16
17
  const svgRef = React.useContext(SVGContext);
17
18
  const {
@@ -49,6 +50,8 @@ function ChartsVoronoiHandler(props) {
49
50
  };
50
51
  }, [dispatch]);
51
52
  useEnhancedEffect(() => {
53
+ // This effect generate and store the Delaunay object that's used to map coordinate to closest point.
54
+
52
55
  if (seriesOrder === undefined || series === undefined) {
53
56
  // If there is no scatter chart series
54
57
  return;
@@ -82,80 +85,125 @@ function ChartsVoronoiHandler(props) {
82
85
  if (element === null) {
83
86
  return undefined;
84
87
  }
85
- const handleMouseOut = () => {
86
- dispatch({
87
- type: 'exitChart'
88
- });
89
- };
90
88
 
91
89
  // TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
92
- const handleMouseMove = event => {
90
+ function getClosestPoint(event) {
93
91
  // Get mouse coordinate in global SVG space
94
92
  const svgPoint = getSVGPoint(svgRef.current, event);
95
93
  const outsideX = svgPoint.x < left || svgPoint.x > left + width;
96
94
  const outsideY = svgPoint.y < top || svgPoint.y > top + height;
97
95
  if (outsideX || outsideY) {
98
- dispatch({
99
- type: 'exitChart'
100
- });
101
- return;
96
+ return 'outside-chart';
102
97
  }
103
98
  if (!voronoiRef.current.delauney) {
104
- return;
99
+ return 'no-point-found';
105
100
  }
106
101
  const closestPointIndex = voronoiRef.current.delauney?.find(svgPoint.x, svgPoint.y);
107
- if (closestPointIndex !== undefined) {
108
- const seriesId = Object.keys(voronoiRef.current).find(id => {
109
- if (id === 'delauney') {
110
- return false;
111
- }
112
- return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
113
- });
114
- if (seriesId === undefined) {
115
- return;
102
+ if (closestPointIndex === undefined) {
103
+ return 'no-point-found';
104
+ }
105
+ const seriesId = Object.keys(voronoiRef.current).find(id => {
106
+ if (id === 'delauney') {
107
+ return false;
116
108
  }
117
- const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
118
- if (voronoiMaxRadius !== undefined) {
119
- const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
120
- const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
121
- const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
122
- if (dist2 > voronoiMaxRadius ** 2) {
123
- // The closest point is too far to be considered.
124
- dispatch({
125
- type: 'leaveItem',
126
- data: {
127
- type: 'scatter',
128
- seriesId,
129
- dataIndex
130
- }
131
- });
132
- return;
133
- }
109
+ return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
110
+ });
111
+ if (seriesId === undefined) {
112
+ return 'no-point-found';
113
+ }
114
+ const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
115
+ if (voronoiMaxRadius !== undefined) {
116
+ const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
117
+ const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
118
+ const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
119
+ if (dist2 > voronoiMaxRadius ** 2) {
120
+ // The closest point is too far to be considered.
121
+ return 'outside-voronoi-max-radius';
134
122
  }
123
+ }
124
+ return {
125
+ seriesId,
126
+ dataIndex
127
+ };
128
+ }
129
+ const handleMouseOut = () => {
130
+ dispatch({
131
+ type: 'exitChart'
132
+ });
133
+ };
134
+ const handleMouseMove = event => {
135
+ const closestPoint = getClosestPoint(event);
136
+ if (closestPoint === 'outside-chart') {
137
+ dispatch({
138
+ type: 'exitChart'
139
+ });
140
+ return;
141
+ }
142
+ if (closestPoint === 'outside-voronoi-max-radius' || closestPoint === 'no-point-found') {
135
143
  dispatch({
136
- type: 'enterItem',
144
+ type: 'leaveItem',
137
145
  data: {
138
- type: 'scatter',
139
- seriesId,
140
- dataIndex
146
+ type: 'scatter'
141
147
  }
142
148
  });
149
+ return;
143
150
  }
151
+ const {
152
+ seriesId,
153
+ dataIndex
154
+ } = closestPoint;
155
+ dispatch({
156
+ type: 'enterItem',
157
+ data: {
158
+ type: 'scatter',
159
+ seriesId,
160
+ dataIndex
161
+ }
162
+ });
163
+ };
164
+ const handleMouseClick = event => {
165
+ if (!onItemClick) {
166
+ return;
167
+ }
168
+ const closestPoint = getClosestPoint(event);
169
+ if (typeof closestPoint === 'string') {
170
+ // No point fond for any reason
171
+ return;
172
+ }
173
+ const {
174
+ seriesId,
175
+ dataIndex
176
+ } = closestPoint;
177
+ onItemClick(event, {
178
+ type: 'scatter',
179
+ seriesId,
180
+ dataIndex
181
+ });
144
182
  };
145
183
  element.addEventListener('mouseout', handleMouseOut);
146
184
  element.addEventListener('mousemove', handleMouseMove);
185
+ element.addEventListener('click', handleMouseClick);
147
186
  return () => {
148
187
  element.removeEventListener('mouseout', handleMouseOut);
149
188
  element.removeEventListener('mousemove', handleMouseMove);
189
+ element.removeEventListener('click', handleMouseClick);
150
190
  };
151
- }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
152
- return /*#__PURE__*/_jsx("g", {}); // Workaround to fix docs scripts
191
+ }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick]);
192
+
193
+ // eslint-disable-next-line react/jsx-no-useless-fragment
194
+ return /*#__PURE__*/_jsx(React.Fragment, {});
153
195
  }
154
196
  process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
155
197
  // ----------------------------- Warning --------------------------------
156
198
  // | These PropTypes are generated from the TypeScript type definitions |
157
199
  // | To update them edit the TypeScript types and run "yarn proptypes" |
158
200
  // ----------------------------------------------------------------------
201
+ /**
202
+ * Callback fired when clicking on a scatter item.
203
+ * @param {MouseEvent} event Mouse event catched at the svg level
204
+ * @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
205
+ */
206
+ onItemClick: PropTypes.func,
159
207
  /**
160
208
  * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
161
209
  * If `undefined`, the radius is assumed to be infinite.
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["scale", "tickNumber"];
3
+ const _excluded = ["scale", "tickNumber", "reverse"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useSlotProps } from '@mui/base/utils';
@@ -35,6 +35,7 @@ const useUtilityClasses = ownerState => {
35
35
  function addLabelDimension(xTicks, {
36
36
  tickLabelStyle: style,
37
37
  tickLabelInterval,
38
+ reverse,
38
39
  isMounted
39
40
  }) {
40
41
  const withDimension = xTicks.map(tick => {
@@ -61,8 +62,9 @@ function addLabelDimension(xTicks, {
61
62
  }
62
63
 
63
64
  // Filter label to avoid overlap
64
- let textStart = 0;
65
- let textEnd = 0;
65
+ let currentTextLimit = 0;
66
+ let previouseTextLimit = 0;
67
+ const direction = reverse ? -1 : 1;
66
68
  return withDimension.map((item, labelIndex) => {
67
69
  const {
68
70
  width,
@@ -74,15 +76,15 @@ function addLabelDimension(xTicks, {
74
76
  const textPosition = offset + labelOffset;
75
77
  const gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
76
78
 
77
- textStart = textPosition - gapRatio * distance / 2;
78
- if (labelIndex > 0 && textStart < textEnd) {
79
+ currentTextLimit = textPosition - direction * (gapRatio * distance) / 2;
80
+ if (labelIndex > 0 && direction * currentTextLimit < direction * previouseTextLimit) {
79
81
  // Except for the first label, we skip all label that overlap with the last accepted.
80
- // Notice that the early return prevents `textEnd` from being updated.
82
+ // Notice that the early return prevents `previouseTextLimit` from being updated.
81
83
  return _extends({}, item, {
82
84
  skipLabel: true
83
85
  });
84
86
  }
85
- textEnd = textPosition + gapRatio * distance / 2;
87
+ previouseTextLimit = textPosition + direction * (gapRatio * distance) / 2;
86
88
  return item;
87
89
  });
88
90
  }
@@ -116,7 +118,8 @@ function ChartsXAxis(inProps) {
116
118
  xAxis: {
117
119
  [_ref]: {
118
120
  scale: xScale,
119
- tickNumber
121
+ tickNumber,
122
+ reverse
120
123
  }
121
124
  }
122
125
  } = _React$useContext,
@@ -178,6 +181,7 @@ function ChartsXAxis(inProps) {
178
181
  const xTicksWithDimension = addLabelDimension(xTicks, {
179
182
  tickLabelStyle: axisTickLabelProps.style,
180
183
  tickLabelInterval,
184
+ reverse,
181
185
  isMounted
182
186
  });
183
187
  const labelRefPoint = {
@@ -241,7 +245,7 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
241
245
  * The id of the axis to render.
242
246
  * If undefined, it will be the first defined axis.
243
247
  */
244
- axisId: PropTypes.string,
248
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
245
249
  /**
246
250
  * Override or extend the styles applied to the component.
247
251
  */
@@ -175,7 +175,7 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
175
175
  * The id of the axis to render.
176
176
  * If undefined, it will be the first defined axis.
177
177
  */
178
- axisId: PropTypes.string,
178
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
179
179
  /**
180
180
  * Override or extend the styles applied to the component.
181
181
  */
@@ -0,0 +1,103 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["d", "skipAnimation", "ownerState"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { styled } from '@mui/material/styles';
7
+ import { color as d3Color } from 'd3-color';
8
+ import { animated, useSpring } from '@react-spring/web';
9
+ import { useAnimatedPath } from '../internals/useAnimatedPath';
10
+ import { DrawingContext } from '../context/DrawingProvider';
11
+ import { cleanId } from '../internals/utils';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export const AreaElementPath = styled(animated.path, {
15
+ name: 'MuiAreaElement',
16
+ slot: 'Root',
17
+ overridesResolver: (_, styles) => styles.root
18
+ })(({
19
+ ownerState
20
+ }) => ({
21
+ stroke: 'none',
22
+ fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
23
+ transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
24
+ opacity: ownerState.isFaded ? 0.3 : 1
25
+ }));
26
+ /**
27
+ * Demos:
28
+ *
29
+ * - [Lines](https://mui.com/x/react-charts/lines/)
30
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
31
+ *
32
+ * API:
33
+ *
34
+ * - [AreaElement API](https://mui.com/x/api/charts/animated-area/)
35
+ */
36
+ function AnimatedArea(props) {
37
+ const {
38
+ d,
39
+ skipAnimation,
40
+ ownerState
41
+ } = props,
42
+ other = _objectWithoutPropertiesLoose(props, _excluded);
43
+ const {
44
+ left,
45
+ top,
46
+ right,
47
+ bottom,
48
+ width,
49
+ height,
50
+ chartId
51
+ } = React.useContext(DrawingContext);
52
+ const path = useAnimatedPath(d, skipAnimation);
53
+ const {
54
+ animatedWidth
55
+ } = useSpring({
56
+ from: {
57
+ animatedWidth: left
58
+ },
59
+ to: {
60
+ animatedWidth: width + left + right
61
+ },
62
+ reset: false,
63
+ immediate: skipAnimation
64
+ });
65
+ const clipId = cleanId(`${chartId}-${ownerState.id}-area-clip`);
66
+ return /*#__PURE__*/_jsxs(React.Fragment, {
67
+ children: [/*#__PURE__*/_jsx("clipPath", {
68
+ id: clipId,
69
+ children: /*#__PURE__*/_jsx(animated.rect, {
70
+ x: 0,
71
+ y: 0,
72
+ width: animatedWidth,
73
+ height: top + height + bottom
74
+ })
75
+ }), /*#__PURE__*/_jsx("g", {
76
+ clipPath: `url(#${clipId})`,
77
+ children: /*#__PURE__*/_jsx(AreaElementPath, _extends({}, other, {
78
+ ownerState: ownerState,
79
+ d: path
80
+ }))
81
+ })]
82
+ });
83
+ }
84
+ process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
85
+ // ----------------------------- Warning --------------------------------
86
+ // | These PropTypes are generated from the TypeScript type definitions |
87
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
88
+ // ----------------------------------------------------------------------
89
+ d: PropTypes.string.isRequired,
90
+ ownerState: PropTypes.shape({
91
+ classes: PropTypes.object,
92
+ color: PropTypes.string.isRequired,
93
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
94
+ isFaded: PropTypes.bool.isRequired,
95
+ isHighlighted: PropTypes.bool.isRequired
96
+ }).isRequired,
97
+ /**
98
+ * If `true`, animations are skipped.
99
+ * @default false
100
+ */
101
+ skipAnimation: PropTypes.bool
102
+ } : void 0;
103
+ export { AnimatedArea };
@@ -0,0 +1,105 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["d", "skipAnimation", "ownerState"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { animated, useSpring } from '@react-spring/web';
7
+ import { color as d3Color } from 'd3-color';
8
+ import { styled } from '@mui/material/styles';
9
+ import { useAnimatedPath } from '../internals/useAnimatedPath';
10
+ import { DrawingContext } from '../context/DrawingProvider';
11
+ import { cleanId } from '../internals/utils';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export const LineElementPath = styled(animated.path, {
15
+ name: 'MuiLineElement',
16
+ slot: 'Root',
17
+ overridesResolver: (_, styles) => styles.root
18
+ })(({
19
+ ownerState
20
+ }) => ({
21
+ strokeWidth: 2,
22
+ strokeLinejoin: 'round',
23
+ fill: 'none',
24
+ stroke: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
25
+ transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
26
+ opacity: ownerState.isFaded ? 0.3 : 1
27
+ }));
28
+ /**
29
+ * Demos:
30
+ *
31
+ * - [Lines](https://mui.com/x/react-charts/lines/)
32
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
33
+ *
34
+ * API:
35
+ *
36
+ * - [AnimatedLine API](https://mui.com/x/api/charts/animated-line/)
37
+ */
38
+ function AnimatedLine(props) {
39
+ const {
40
+ d,
41
+ skipAnimation,
42
+ ownerState
43
+ } = props,
44
+ other = _objectWithoutPropertiesLoose(props, _excluded);
45
+ const {
46
+ left,
47
+ top,
48
+ bottom,
49
+ width,
50
+ height,
51
+ right,
52
+ chartId
53
+ } = React.useContext(DrawingContext);
54
+ const path = useAnimatedPath(d, skipAnimation);
55
+ const {
56
+ animatedWidth
57
+ } = useSpring({
58
+ from: {
59
+ animatedWidth: left
60
+ },
61
+ to: {
62
+ animatedWidth: width + left + right
63
+ },
64
+ reset: false,
65
+ immediate: skipAnimation
66
+ });
67
+ const clipId = cleanId(`${chartId}-${ownerState.id}-line-clip`);
68
+ return /*#__PURE__*/_jsxs(React.Fragment, {
69
+ children: [/*#__PURE__*/_jsx("clipPath", {
70
+ id: clipId,
71
+ children: /*#__PURE__*/_jsx(animated.rect, {
72
+ x: 0,
73
+ y: 0,
74
+ width: animatedWidth,
75
+ height: top + height + bottom
76
+ })
77
+ }), /*#__PURE__*/_jsx("g", {
78
+ clipPath: `url(#${clipId})`,
79
+ children: /*#__PURE__*/_jsx(LineElementPath, _extends({}, other, {
80
+ ownerState: ownerState,
81
+ d: path
82
+ }))
83
+ })]
84
+ });
85
+ }
86
+ process.env.NODE_ENV !== "production" ? AnimatedLine.propTypes = {
87
+ // ----------------------------- Warning --------------------------------
88
+ // | These PropTypes are generated from the TypeScript type definitions |
89
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
90
+ // ----------------------------------------------------------------------
91
+ d: PropTypes.string.isRequired,
92
+ ownerState: PropTypes.shape({
93
+ classes: PropTypes.object,
94
+ color: PropTypes.string.isRequired,
95
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
96
+ isFaded: PropTypes.bool.isRequired,
97
+ isHighlighted: PropTypes.bool.isRequired
98
+ }).isRequired,
99
+ /**
100
+ * If `true`, animations are skipped.
101
+ * @default false
102
+ */
103
+ skipAnimation: PropTypes.bool
104
+ } : void 0;
105
+ export { AnimatedLine };