@mui/x-charts 7.0.0-alpha.9 → 7.0.0-beta.1

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 (214) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +24 -23
  3. package/BarChart/BarElement.d.ts +1 -1
  4. package/BarChart/BarElement.js +6 -3
  5. package/BarChart/BarPlot.d.ts +8 -1
  6. package/BarChart/BarPlot.js +19 -5
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +386 -38
  9. package/ChartContainer/ChartContainer.d.ts +12 -0
  10. package/ChartContainer/ChartContainer.js +197 -0
  11. package/ChartContainer/index.d.ts +1 -11
  12. package/ChartContainer/index.js +9 -63
  13. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  14. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  15. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  16. package/ChartsOnAxisClickHandler/index.js +16 -0
  17. package/ChartsOnAxisClickHandler/package.json +6 -0
  18. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  19. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  20. package/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
  21. package/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  22. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -58
  23. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  24. package/ChartsTooltip/utils.d.ts +3 -1
  25. package/ChartsTooltip/utils.js +8 -0
  26. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  27. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  28. package/LineChart/AnimatedArea.d.ts +1361 -0
  29. package/LineChart/AnimatedArea.js +111 -0
  30. package/LineChart/AnimatedLine.d.ts +1361 -0
  31. package/LineChart/AnimatedLine.js +113 -0
  32. package/LineChart/AreaElement.d.ts +17 -17
  33. package/LineChart/AreaElement.js +17 -34
  34. package/LineChart/AreaPlot.d.ts +12 -7
  35. package/LineChart/AreaPlot.js +91 -58
  36. package/LineChart/LineChart.d.ts +13 -4
  37. package/LineChart/LineChart.js +36 -29
  38. package/LineChart/LineElement.d.ts +17 -17
  39. package/LineChart/LineElement.js +16 -36
  40. package/LineChart/LineHighlightElement.js +3 -2
  41. package/LineChart/LinePlot.d.ts +12 -7
  42. package/LineChart/LinePlot.js +89 -56
  43. package/LineChart/MarkElement.d.ts +5 -2
  44. package/LineChart/MarkElement.js +26 -13
  45. package/LineChart/MarkPlot.d.ts +8 -1
  46. package/LineChart/MarkPlot.js +80 -51
  47. package/LineChart/formatter.js +1 -1
  48. package/LineChart/index.d.ts +2 -0
  49. package/LineChart/index.js +22 -0
  50. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  51. package/PieChart/PieArcLabelPlot.js +1 -1
  52. package/PieChart/PieArcPlot.d.ts +2 -2
  53. package/PieChart/PieArcPlot.js +6 -6
  54. package/PieChart/PieChart.d.ts +1 -1
  55. package/PieChart/PieChart.js +5 -50
  56. package/PieChart/PiePlot.d.ts +1 -1
  57. package/PieChart/PiePlot.js +4 -4
  58. package/README.md +2 -2
  59. package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +16 -0
  60. package/ResponsiveChartContainer/ResponsiveChartContainer.js +250 -0
  61. package/ResponsiveChartContainer/index.d.ts +1 -15
  62. package/ResponsiveChartContainer/index.js +8 -113
  63. package/ScatterChart/Scatter.d.ts +7 -1
  64. package/ScatterChart/Scatter.js +18 -23
  65. package/ScatterChart/ScatterChart.d.ts +8 -2
  66. package/ScatterChart/ScatterChart.js +12 -22
  67. package/ScatterChart/ScatterPlot.d.ts +1 -1
  68. package/ScatterChart/ScatterPlot.js +10 -2
  69. package/SparkLineChart/SparkLineChart.js +2 -0
  70. package/context/DrawingProvider.d.ts +6 -1
  71. package/context/DrawingProvider.js +9 -2
  72. package/context/InteractionProvider.d.ts +3 -3
  73. package/esm/BarChart/BarChart.js +24 -23
  74. package/esm/BarChart/BarElement.js +6 -3
  75. package/esm/BarChart/BarPlot.js +19 -5
  76. package/esm/BarChart/formatter.js +1 -1
  77. package/esm/ChartContainer/ChartContainer.js +189 -0
  78. package/esm/ChartContainer/index.js +1 -61
  79. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  80. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  81. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  82. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  83. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
  84. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  85. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +9 -58
  86. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  87. package/esm/ChartsTooltip/utils.js +6 -0
  88. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  89. package/esm/LineChart/AnimatedArea.js +103 -0
  90. package/esm/LineChart/AnimatedLine.js +105 -0
  91. package/esm/LineChart/AreaElement.js +16 -33
  92. package/esm/LineChart/AreaPlot.js +92 -59
  93. package/esm/LineChart/LineChart.js +36 -29
  94. package/esm/LineChart/LineElement.js +16 -35
  95. package/esm/LineChart/LineHighlightElement.js +3 -2
  96. package/esm/LineChart/LinePlot.js +90 -57
  97. package/esm/LineChart/MarkElement.js +26 -13
  98. package/esm/LineChart/MarkPlot.js +80 -51
  99. package/esm/LineChart/formatter.js +1 -1
  100. package/esm/LineChart/index.js +2 -0
  101. package/esm/PieChart/PieArcLabelPlot.js +1 -1
  102. package/esm/PieChart/PieArcPlot.js +6 -6
  103. package/esm/PieChart/PieChart.js +5 -50
  104. package/esm/PieChart/PiePlot.js +4 -4
  105. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +245 -0
  106. package/esm/ResponsiveChartContainer/index.js +1 -115
  107. package/esm/ScatterChart/Scatter.js +18 -23
  108. package/esm/ScatterChart/ScatterChart.js +12 -22
  109. package/esm/ScatterChart/ScatterPlot.js +10 -2
  110. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  111. package/esm/context/DrawingProvider.js +9 -2
  112. package/esm/hooks/useDrawingArea.js +7 -3
  113. package/esm/index.js +1 -0
  114. package/esm/internals/geometry.js +1 -1
  115. package/esm/internals/useAnimatedPath.js +29 -0
  116. package/esm/internals/utils.js +7 -0
  117. package/hooks/useDrawingArea.d.ts +2 -0
  118. package/hooks/useDrawingArea.js +7 -3
  119. package/index.d.ts +1 -0
  120. package/index.js +12 -1
  121. package/internals/geometry.js +1 -1
  122. package/internals/useAnimatedPath.d.ts +1 -0
  123. package/internals/useAnimatedPath.js +38 -0
  124. package/internals/utils.d.ts +4 -0
  125. package/internals/utils.js +8 -0
  126. package/legacy/BarChart/BarChart.js +24 -23
  127. package/legacy/BarChart/BarElement.js +5 -2
  128. package/legacy/BarChart/BarPlot.js +18 -4
  129. package/legacy/BarChart/formatter.js +1 -1
  130. package/legacy/ChartContainer/ChartContainer.js +187 -0
  131. package/legacy/ChartContainer/index.js +1 -59
  132. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  133. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  134. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  135. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  136. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +8 -61
  137. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  138. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +9 -58
  139. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  140. package/legacy/ChartsTooltip/utils.js +6 -0
  141. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  142. package/legacy/LineChart/AnimatedArea.js +102 -0
  143. package/legacy/LineChart/AnimatedLine.js +104 -0
  144. package/legacy/LineChart/AreaElement.js +15 -35
  145. package/legacy/LineChart/AreaPlot.js +102 -66
  146. package/legacy/LineChart/LineChart.js +36 -29
  147. package/legacy/LineChart/LineElement.js +15 -37
  148. package/legacy/LineChart/LineHighlightElement.js +3 -2
  149. package/legacy/LineChart/LinePlot.js +97 -63
  150. package/legacy/LineChart/MarkElement.js +29 -12
  151. package/legacy/LineChart/MarkPlot.js +83 -53
  152. package/legacy/LineChart/formatter.js +1 -1
  153. package/legacy/LineChart/index.js +2 -0
  154. package/legacy/PieChart/PieArcLabelPlot.js +1 -1
  155. package/legacy/PieChart/PieArcPlot.js +6 -6
  156. package/legacy/PieChart/PieChart.js +5 -50
  157. package/legacy/PieChart/PiePlot.js +4 -4
  158. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +253 -0
  159. package/legacy/ResponsiveChartContainer/index.js +1 -123
  160. package/legacy/ScatterChart/Scatter.js +20 -23
  161. package/legacy/ScatterChart/ScatterChart.js +12 -22
  162. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  163. package/legacy/SparkLineChart/SparkLineChart.js +2 -0
  164. package/legacy/context/DrawingProvider.js +11 -2
  165. package/legacy/hooks/useDrawingArea.js +7 -3
  166. package/legacy/index.js +2 -1
  167. package/legacy/internals/geometry.js +1 -1
  168. package/legacy/internals/useAnimatedPath.js +32 -0
  169. package/legacy/internals/utils.js +7 -0
  170. package/modern/BarChart/BarChart.js +24 -23
  171. package/modern/BarChart/BarElement.js +6 -3
  172. package/modern/BarChart/BarPlot.js +19 -5
  173. package/modern/BarChart/formatter.js +1 -1
  174. package/modern/ChartContainer/ChartContainer.js +189 -0
  175. package/modern/ChartContainer/index.js +1 -61
  176. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  177. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  178. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  179. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  180. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
  181. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  182. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -58
  183. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  184. package/modern/ChartsTooltip/utils.js +6 -0
  185. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  186. package/modern/LineChart/AnimatedArea.js +103 -0
  187. package/modern/LineChart/AnimatedLine.js +105 -0
  188. package/modern/LineChart/AreaElement.js +16 -33
  189. package/modern/LineChart/AreaPlot.js +91 -58
  190. package/modern/LineChart/LineChart.js +36 -29
  191. package/modern/LineChart/LineElement.js +16 -35
  192. package/modern/LineChart/LineHighlightElement.js +3 -2
  193. package/modern/LineChart/LinePlot.js +89 -56
  194. package/modern/LineChart/MarkElement.js +26 -13
  195. package/modern/LineChart/MarkPlot.js +80 -51
  196. package/modern/LineChart/formatter.js +1 -1
  197. package/modern/LineChart/index.js +2 -0
  198. package/modern/PieChart/PieArcLabelPlot.js +1 -1
  199. package/modern/PieChart/PieArcPlot.js +6 -6
  200. package/modern/PieChart/PieChart.js +5 -50
  201. package/modern/PieChart/PiePlot.js +4 -4
  202. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +242 -0
  203. package/modern/ResponsiveChartContainer/index.js +1 -112
  204. package/modern/ScatterChart/Scatter.js +18 -23
  205. package/modern/ScatterChart/ScatterChart.js +12 -22
  206. package/modern/ScatterChart/ScatterPlot.js +10 -2
  207. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  208. package/modern/context/DrawingProvider.js +9 -2
  209. package/modern/hooks/useDrawingArea.js +7 -3
  210. package/modern/index.js +2 -1
  211. package/modern/internals/geometry.js +1 -1
  212. package/modern/internals/useAnimatedPath.js +29 -0
  213. package/modern/internals/utils.js +7 -0
  214. package/package.json +6 -5
@@ -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,83 +67,31 @@ 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,
77
78
  content: PropTypes.elementType,
78
79
  contentProps: PropTypes.shape({
79
- axis: PropTypes.shape({
80
- axisId: PropTypes.string,
81
- classes: PropTypes.object,
82
- data: PropTypes.array,
83
- dataKey: PropTypes.string,
84
- disableLine: PropTypes.bool,
85
- disableTicks: PropTypes.bool,
86
- fill: PropTypes.string,
87
- hideTooltip: PropTypes.bool,
88
- id: PropTypes.string.isRequired,
89
- label: PropTypes.string,
90
- labelFontSize: PropTypes.number,
91
- labelStyle: PropTypes.object,
92
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
93
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
94
- position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
95
- scale: PropTypes.func.isRequired,
96
- scaleType: PropTypes.oneOf(['time']).isRequired,
97
- slotProps: PropTypes.object,
98
- slots: PropTypes.object,
99
- stroke: PropTypes.string,
100
- tickFontSize: PropTypes.number,
101
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
102
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
103
- tickLabelStyle: PropTypes.object,
104
- tickMaxStep: PropTypes.number,
105
- tickMinStep: PropTypes.number,
106
- tickNumber: PropTypes.number.isRequired,
107
- tickSize: PropTypes.number,
108
- valueFormatter: PropTypes.func
109
- }),
80
+ axis: PropTypes.object,
110
81
  axisData: PropTypes.shape({
111
82
  x: PropTypes.shape({
112
83
  index: PropTypes.number,
113
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
84
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
114
85
  }),
115
86
  y: PropTypes.shape({
116
87
  index: PropTypes.number,
117
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
88
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
118
89
  })
119
90
  }),
120
91
  axisValue: PropTypes.any,
121
92
  classes: PropTypes.object,
122
93
  dataIndex: PropTypes.number,
123
- series: PropTypes.arrayOf(PropTypes.shape({
124
- area: PropTypes.bool,
125
- color: PropTypes.string.isRequired,
126
- connectNulls: PropTypes.bool,
127
- curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
128
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
129
- dataKey: PropTypes.string,
130
- disableHighlight: PropTypes.bool,
131
- highlightScope: PropTypes.shape({
132
- faded: PropTypes.oneOf(['global', 'none', 'series']),
133
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
134
- }),
135
- id: PropTypes.string.isRequired,
136
- label: PropTypes.string,
137
- showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
138
- stack: PropTypes.string,
139
- stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
140
- stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
141
- type: PropTypes.oneOf(['line']).isRequired,
142
- valueFormatter: PropTypes.func.isRequired,
143
- xAxisKey: PropTypes.string,
144
- yAxisKey: PropTypes.string
145
- })),
94
+ series: PropTypes.arrayOf(PropTypes.object),
146
95
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
147
96
  }),
148
97
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
@@ -42,17 +42,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
42
42
  seriesId: PropTypes.string.isRequired,
43
43
  type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
44
44
  }),
45
- series: PropTypes.shape({
46
- color: PropTypes.string,
47
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
48
- highlightScope: PropTypes.shape({
49
- faded: PropTypes.oneOf(['global', 'none', 'series']),
50
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
51
- }),
52
- id: PropTypes.string.isRequired,
53
- type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
54
- valueFormatter: PropTypes.func.isRequired
55
- }),
45
+ series: PropTypes.object,
56
46
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
57
47
  }),
58
48
  itemData: PropTypes.shape({
@@ -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 } 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) {
@@ -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
  }
@@ -81,48 +84,18 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
81
84
  /**
82
85
  * The properties of the triggered axis.
83
86
  */
84
- axis: PropTypes.shape({
85
- axisId: PropTypes.string,
86
- classes: PropTypes.object,
87
- data: PropTypes.array,
88
- dataKey: PropTypes.string,
89
- disableLine: PropTypes.bool,
90
- disableTicks: PropTypes.bool,
91
- fill: PropTypes.string,
92
- hideTooltip: PropTypes.bool,
93
- id: PropTypes.string.isRequired,
94
- label: PropTypes.string,
95
- labelFontSize: PropTypes.number,
96
- labelStyle: PropTypes.object,
97
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
98
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
99
- position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
100
- scale: PropTypes.func.isRequired,
101
- scaleType: PropTypes.oneOf(['time']).isRequired,
102
- slotProps: PropTypes.object,
103
- slots: PropTypes.object,
104
- stroke: PropTypes.string,
105
- tickFontSize: PropTypes.number,
106
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
107
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
108
- tickLabelStyle: PropTypes.object,
109
- tickMaxStep: PropTypes.number,
110
- tickMinStep: PropTypes.number,
111
- tickNumber: PropTypes.number.isRequired,
112
- tickSize: PropTypes.number,
113
- valueFormatter: PropTypes.func
114
- }).isRequired,
87
+ axis: PropTypes.object.isRequired,
115
88
  /**
116
89
  * Data identifying the triggered axis.
117
90
  */
118
91
  axisData: PropTypes.shape({
119
92
  x: PropTypes.shape({
120
93
  index: PropTypes.number,
121
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
94
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
122
95
  }),
123
96
  y: PropTypes.shape({
124
97
  index: PropTypes.number,
125
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
98
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
126
99
  })
127
100
  }).isRequired,
128
101
  /**
@@ -140,29 +113,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
140
113
  /**
141
114
  * The series linked to the triggered axis.
142
115
  */
143
- series: PropTypes.arrayOf(PropTypes.shape({
144
- area: PropTypes.bool,
145
- color: PropTypes.string.isRequired,
146
- connectNulls: PropTypes.bool,
147
- curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
148
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
149
- dataKey: PropTypes.string,
150
- disableHighlight: PropTypes.bool,
151
- highlightScope: PropTypes.shape({
152
- faded: PropTypes.oneOf(['global', 'none', 'series']),
153
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
154
- }),
155
- id: PropTypes.string.isRequired,
156
- label: PropTypes.string,
157
- showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
158
- stack: PropTypes.string,
159
- stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
160
- stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
161
- type: PropTypes.oneOf(['line']).isRequired,
162
- valueFormatter: PropTypes.func.isRequired,
163
- xAxisKey: PropTypes.string,
164
- yAxisKey: PropTypes.string
165
- })).isRequired,
116
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
166
117
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
167
118
  } : void 0;
168
119
  export { DefaultChartsAxisTooltipContent };
@@ -75,17 +75,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
75
75
  /**
76
76
  * The series linked to the triggered axis.
77
77
  */
78
- series: PropTypes.shape({
79
- color: PropTypes.string,
80
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
81
- highlightScope: PropTypes.shape({
82
- faded: PropTypes.oneOf(['global', 'none', 'series']),
83
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
84
- }),
85
- id: PropTypes.string.isRequired,
86
- type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
87
- valueFormatter: PropTypes.func.isRequired
88
- }).isRequired,
78
+ series: PropTypes.object.isRequired,
89
79
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
90
80
  } : void 0;
91
81
  export { DefaultChartsItemTooltipContent };
@@ -78,4 +78,10 @@ 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);
81
87
  }
@@ -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.
@@ -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.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.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 };