@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
@@ -0,0 +1 @@
1
+ export * from './ChartsOnAxisClickHandler';
@@ -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
  */
@@ -70,7 +70,7 @@ function ChartsXReferenceLine(props) {
70
70
  if (process.env.NODE_ENV !== 'production') {
71
71
  if (!warnedOnce) {
72
72
  warnedOnce = true;
73
- console.error(`MUI X: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
73
+ console.error(`MUI X Charts: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
74
74
  }
75
75
  }
76
76
  return null;
@@ -70,7 +70,7 @@ function ChartsYReferenceLine(props) {
70
70
  if (process.env.NODE_ENV !== 'production') {
71
71
  if (!warnedOnce) {
72
72
  warnedOnce = true;
73
- console.error(`MUI X: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
73
+ console.error(`MUI X Charts: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
74
74
  }
75
75
  }
76
76
  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) {
@@ -18,7 +19,7 @@ function DefaultChartsAxisTooltipContent(props) {
18
19
  if (dataIndex == null) {
19
20
  return null;
20
21
  }
21
- const axisFormatter = (_axis$valueFormatter = axis.valueFormatter) != null ? _axis$valueFormatter : v => v.toLocaleString();
22
+ const axisFormatter = (_axis$valueFormatter = axis.valueFormatter) != null ? _axis$valueFormatter : v => axis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString();
22
23
  return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
23
24
  sx: sx,
24
25
  className: classes.root,
@@ -34,14 +35,16 @@ function DefaultChartsAxisTooltipContent(props) {
34
35
  })
35
36
  })
36
37
  }), /*#__PURE__*/_jsx("tbody", {
37
- children: series.map(({
38
+ children: series.filter(isCartesianSeries).map(({
38
39
  color,
39
40
  id,
40
41
  label,
41
42
  valueFormatter,
42
43
  data
43
44
  }) => {
44
- const formattedValue = valueFormatter(data[dataIndex]);
45
+ var _data$dataIndex;
46
+ // @ts-ignore
47
+ const formattedValue = valueFormatter((_data$dataIndex = data[dataIndex]) != null ? _data$dataIndex : null);
45
48
  if (formattedValue == null) {
46
49
  return null;
47
50
  }
@@ -88,11 +91,11 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
88
91
  axisData: PropTypes.shape({
89
92
  x: PropTypes.shape({
90
93
  index: PropTypes.number,
91
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
94
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
92
95
  }),
93
96
  y: PropTypes.shape({
94
97
  index: PropTypes.number,
95
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
98
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
96
99
  })
97
100
  }).isRequired,
98
101
  /**
@@ -69,7 +69,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
69
69
  */
70
70
  itemData: PropTypes.shape({
71
71
  dataIndex: PropTypes.number,
72
- seriesId: PropTypes.string.isRequired,
72
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
73
73
  type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
74
74
  }).isRequired,
75
75
  /**
@@ -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
  }
@@ -12,7 +12,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
12
12
  function ChartsVoronoiHandler(props) {
13
13
  var _React$useContext$sca;
14
14
  const {
15
- voronoiMaxRadius
15
+ voronoiMaxRadius,
16
+ onItemClick
16
17
  } = props;
17
18
  const svgRef = React.useContext(SVGContext);
18
19
  const {
@@ -50,6 +51,8 @@ function ChartsVoronoiHandler(props) {
50
51
  };
51
52
  }, [dispatch]);
52
53
  useEnhancedEffect(() => {
54
+ // This effect generate and store the Delaunay object that's used to map coordinate to closest point.
55
+
53
56
  if (seriesOrder === undefined || series === undefined) {
54
57
  // If there is no scatter chart series
55
58
  return;
@@ -83,81 +86,126 @@ function ChartsVoronoiHandler(props) {
83
86
  if (element === null) {
84
87
  return undefined;
85
88
  }
86
- const handleMouseOut = () => {
87
- dispatch({
88
- type: 'exitChart'
89
- });
90
- };
91
89
 
92
90
  // TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
93
- const handleMouseMove = event => {
91
+ function getClosestPoint(event) {
94
92
  var _voronoiRef$current$d;
95
93
  // Get mouse coordinate in global SVG space
96
94
  const svgPoint = getSVGPoint(svgRef.current, event);
97
95
  const outsideX = svgPoint.x < left || svgPoint.x > left + width;
98
96
  const outsideY = svgPoint.y < top || svgPoint.y > top + height;
99
97
  if (outsideX || outsideY) {
100
- dispatch({
101
- type: 'exitChart'
102
- });
103
- return;
98
+ return 'outside-chart';
104
99
  }
105
100
  if (!voronoiRef.current.delauney) {
106
- return;
101
+ return 'no-point-found';
107
102
  }
108
103
  const closestPointIndex = (_voronoiRef$current$d = voronoiRef.current.delauney) == null ? void 0 : _voronoiRef$current$d.find(svgPoint.x, svgPoint.y);
109
- if (closestPointIndex !== undefined) {
110
- const seriesId = Object.keys(voronoiRef.current).find(id => {
111
- if (id === 'delauney') {
112
- return false;
113
- }
114
- return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
115
- });
116
- if (seriesId === undefined) {
117
- return;
104
+ if (closestPointIndex === undefined) {
105
+ return 'no-point-found';
106
+ }
107
+ const seriesId = Object.keys(voronoiRef.current).find(id => {
108
+ if (id === 'delauney') {
109
+ return false;
118
110
  }
119
- const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
120
- if (voronoiMaxRadius !== undefined) {
121
- const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
122
- const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
123
- const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
124
- if (dist2 > voronoiMaxRadius ** 2) {
125
- // The closest point is too far to be considered.
126
- dispatch({
127
- type: 'leaveItem',
128
- data: {
129
- type: 'scatter',
130
- seriesId,
131
- dataIndex
132
- }
133
- });
134
- return;
135
- }
111
+ return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
112
+ });
113
+ if (seriesId === undefined) {
114
+ return 'no-point-found';
115
+ }
116
+ const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
117
+ if (voronoiMaxRadius !== undefined) {
118
+ const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
119
+ const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
120
+ const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
121
+ if (dist2 > voronoiMaxRadius ** 2) {
122
+ // The closest point is too far to be considered.
123
+ return 'outside-voronoi-max-radius';
136
124
  }
125
+ }
126
+ return {
127
+ seriesId,
128
+ dataIndex
129
+ };
130
+ }
131
+ const handleMouseOut = () => {
132
+ dispatch({
133
+ type: 'exitChart'
134
+ });
135
+ };
136
+ const handleMouseMove = event => {
137
+ const closestPoint = getClosestPoint(event);
138
+ if (closestPoint === 'outside-chart') {
139
+ dispatch({
140
+ type: 'exitChart'
141
+ });
142
+ return;
143
+ }
144
+ if (closestPoint === 'outside-voronoi-max-radius' || closestPoint === 'no-point-found') {
137
145
  dispatch({
138
- type: 'enterItem',
146
+ type: 'leaveItem',
139
147
  data: {
140
- type: 'scatter',
141
- seriesId,
142
- dataIndex
148
+ type: 'scatter'
143
149
  }
144
150
  });
151
+ return;
145
152
  }
153
+ const {
154
+ seriesId,
155
+ dataIndex
156
+ } = closestPoint;
157
+ dispatch({
158
+ type: 'enterItem',
159
+ data: {
160
+ type: 'scatter',
161
+ seriesId,
162
+ dataIndex
163
+ }
164
+ });
165
+ };
166
+ const handleMouseClick = event => {
167
+ if (!onItemClick) {
168
+ return;
169
+ }
170
+ const closestPoint = getClosestPoint(event);
171
+ if (typeof closestPoint === 'string') {
172
+ // No point fond for any reason
173
+ return;
174
+ }
175
+ const {
176
+ seriesId,
177
+ dataIndex
178
+ } = closestPoint;
179
+ onItemClick(event, {
180
+ type: 'scatter',
181
+ seriesId,
182
+ dataIndex
183
+ });
146
184
  };
147
185
  element.addEventListener('mouseout', handleMouseOut);
148
186
  element.addEventListener('mousemove', handleMouseMove);
187
+ element.addEventListener('click', handleMouseClick);
149
188
  return () => {
150
189
  element.removeEventListener('mouseout', handleMouseOut);
151
190
  element.removeEventListener('mousemove', handleMouseMove);
191
+ element.removeEventListener('click', handleMouseClick);
152
192
  };
153
- }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
154
- return /*#__PURE__*/_jsx("g", {}); // Workaround to fix docs scripts
193
+ }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick]);
194
+
195
+ // eslint-disable-next-line react/jsx-no-useless-fragment
196
+ return /*#__PURE__*/_jsx(React.Fragment, {});
155
197
  }
156
198
  process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
157
199
  // ----------------------------- Warning --------------------------------
158
200
  // | These PropTypes are generated from the TypeScript type definitions |
159
201
  // | To update them edit the TypeScript types and run "yarn proptypes" |
160
202
  // ----------------------------------------------------------------------
203
+ /**
204
+ * Callback fired when clicking on a scatter item.
205
+ * @param {MouseEvent} event Mouse event catched at the svg level
206
+ * @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
207
+ */
208
+ onItemClick: PropTypes.func,
161
209
  /**
162
210
  * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
163
211
  * 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
  }
@@ -117,7 +119,8 @@ function ChartsXAxis(inProps) {
117
119
  xAxis: {
118
120
  [_ref]: {
119
121
  scale: xScale,
120
- tickNumber
122
+ tickNumber,
123
+ reverse
121
124
  }
122
125
  }
123
126
  } = _React$useContext,
@@ -179,6 +182,7 @@ function ChartsXAxis(inProps) {
179
182
  const xTicksWithDimension = addLabelDimension(xTicks, {
180
183
  tickLabelStyle: axisTickLabelProps.style,
181
184
  tickLabelInterval,
185
+ reverse,
182
186
  isMounted
183
187
  });
184
188
  const labelRefPoint = {
@@ -242,7 +246,7 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
242
246
  * The id of the axis to render.
243
247
  * If undefined, it will be the first defined axis.
244
248
  */
245
- axisId: PropTypes.string,
249
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
246
250
  /**
247
251
  * Override or extend the styles applied to the component.
248
252
  */
@@ -176,7 +176,7 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
176
176
  * The id of the axis to render.
177
177
  * If undefined, it will be the first defined axis.
178
178
  */
179
- axisId: PropTypes.string,
179
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
180
180
  /**
181
181
  * Override or extend the styles applied to the component.
182
182
  */
@@ -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 };