@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
  var content = props.content,
@@ -24,9 +25,7 @@ function ChartsAxisTooltipContent(props) {
24
25
  var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
25
26
  var relevantSeries = React.useMemo(function () {
26
27
  var rep = [];
27
- Object.keys(series).filter(function (seriesType) {
28
- return ['bar', 'line', 'scatter'].includes(seriesType);
29
- }).forEach(function (seriesType) {
28
+ Object.keys(series).filter(isCartesianSeriesType).forEach(function (seriesType) {
30
29
  series[seriesType].seriesOrder.forEach(function (seriesId) {
31
30
  var item = series[seriesType].series[seriesId];
32
31
  var axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
@@ -65,83 +64,31 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
65
64
  axisData: PropTypes.shape({
66
65
  x: PropTypes.shape({
67
66
  index: PropTypes.number,
68
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
67
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
69
68
  }),
70
69
  y: PropTypes.shape({
71
70
  index: PropTypes.number,
72
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
71
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
73
72
  })
74
73
  }).isRequired,
75
74
  classes: PropTypes.object.isRequired,
76
75
  content: PropTypes.elementType,
77
76
  contentProps: PropTypes.shape({
78
- axis: PropTypes.shape({
79
- axisId: PropTypes.string,
80
- classes: PropTypes.object,
81
- data: PropTypes.array,
82
- dataKey: PropTypes.string,
83
- disableLine: PropTypes.bool,
84
- disableTicks: PropTypes.bool,
85
- fill: PropTypes.string,
86
- hideTooltip: PropTypes.bool,
87
- id: PropTypes.string.isRequired,
88
- label: PropTypes.string,
89
- labelFontSize: PropTypes.number,
90
- labelStyle: PropTypes.object,
91
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
92
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
93
- position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
94
- scale: PropTypes.func.isRequired,
95
- scaleType: PropTypes.oneOf(['time']).isRequired,
96
- slotProps: PropTypes.object,
97
- slots: PropTypes.object,
98
- stroke: PropTypes.string,
99
- tickFontSize: PropTypes.number,
100
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
101
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
102
- tickLabelStyle: PropTypes.object,
103
- tickMaxStep: PropTypes.number,
104
- tickMinStep: PropTypes.number,
105
- tickNumber: PropTypes.number.isRequired,
106
- tickSize: PropTypes.number,
107
- valueFormatter: PropTypes.func
108
- }),
77
+ axis: PropTypes.object,
109
78
  axisData: PropTypes.shape({
110
79
  x: PropTypes.shape({
111
80
  index: PropTypes.number,
112
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
81
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
113
82
  }),
114
83
  y: PropTypes.shape({
115
84
  index: PropTypes.number,
116
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
85
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
117
86
  })
118
87
  }),
119
88
  axisValue: PropTypes.any,
120
89
  classes: PropTypes.object,
121
90
  dataIndex: PropTypes.number,
122
- series: PropTypes.arrayOf(PropTypes.shape({
123
- area: PropTypes.bool,
124
- color: PropTypes.string.isRequired,
125
- connectNulls: PropTypes.bool,
126
- curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
127
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
128
- dataKey: PropTypes.string,
129
- disableHighlight: PropTypes.bool,
130
- highlightScope: PropTypes.shape({
131
- faded: PropTypes.oneOf(['global', 'none', 'series']),
132
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
133
- }),
134
- id: PropTypes.string.isRequired,
135
- label: PropTypes.string,
136
- showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
137
- stack: PropTypes.string,
138
- stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
139
- stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
140
- type: PropTypes.oneOf(['line']).isRequired,
141
- valueFormatter: PropTypes.func.isRequired,
142
- xAxisKey: PropTypes.string,
143
- yAxisKey: PropTypes.string
144
- })),
91
+ series: PropTypes.arrayOf(PropTypes.object),
145
92
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
146
93
  }),
147
94
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
@@ -40,17 +40,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
40
40
  seriesId: PropTypes.string.isRequired,
41
41
  type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
42
42
  }),
43
- series: PropTypes.shape({
44
- color: PropTypes.string,
45
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
46
- highlightScope: PropTypes.shape({
47
- faded: PropTypes.oneOf(['global', 'none', 'series']),
48
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
49
- }),
50
- id: PropTypes.string.isRequired,
51
- type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
52
- valueFormatter: PropTypes.func.isRequired
53
- }),
43
+ series: PropTypes.object,
54
44
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
55
45
  }),
56
46
  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,13 +35,15 @@ function DefaultChartsAxisTooltipContent(props) {
34
35
  })
35
36
  })
36
37
  }), /*#__PURE__*/_jsx("tbody", {
37
- children: series.map(function (_ref) {
38
+ children: series.filter(isCartesianSeries).map(function (_ref) {
39
+ var _data$dataIndex;
38
40
  var color = _ref.color,
39
41
  id = _ref.id,
40
42
  label = _ref.label,
41
43
  valueFormatter = _ref.valueFormatter,
42
44
  data = _ref.data;
43
- var formattedValue = valueFormatter(data[dataIndex]);
45
+ // @ts-ignore
46
+ var formattedValue = valueFormatter((_data$dataIndex = data[dataIndex]) != null ? _data$dataIndex : null);
44
47
  if (formattedValue == null) {
45
48
  return null;
46
49
  }
@@ -80,48 +83,18 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
80
83
  /**
81
84
  * The properties of the triggered axis.
82
85
  */
83
- axis: PropTypes.shape({
84
- axisId: PropTypes.string,
85
- classes: PropTypes.object,
86
- data: PropTypes.array,
87
- dataKey: PropTypes.string,
88
- disableLine: PropTypes.bool,
89
- disableTicks: PropTypes.bool,
90
- fill: PropTypes.string,
91
- hideTooltip: PropTypes.bool,
92
- id: PropTypes.string.isRequired,
93
- label: PropTypes.string,
94
- labelFontSize: PropTypes.number,
95
- labelStyle: PropTypes.object,
96
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
97
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
98
- position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
99
- scale: PropTypes.func.isRequired,
100
- scaleType: PropTypes.oneOf(['time']).isRequired,
101
- slotProps: PropTypes.object,
102
- slots: PropTypes.object,
103
- stroke: PropTypes.string,
104
- tickFontSize: PropTypes.number,
105
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
106
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
107
- tickLabelStyle: PropTypes.object,
108
- tickMaxStep: PropTypes.number,
109
- tickMinStep: PropTypes.number,
110
- tickNumber: PropTypes.number.isRequired,
111
- tickSize: PropTypes.number,
112
- valueFormatter: PropTypes.func
113
- }).isRequired,
86
+ axis: PropTypes.object.isRequired,
114
87
  /**
115
88
  * Data identifying the triggered axis.
116
89
  */
117
90
  axisData: PropTypes.shape({
118
91
  x: PropTypes.shape({
119
92
  index: PropTypes.number,
120
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
93
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
121
94
  }),
122
95
  y: PropTypes.shape({
123
96
  index: PropTypes.number,
124
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
97
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
125
98
  })
126
99
  }).isRequired,
127
100
  /**
@@ -139,29 +112,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
139
112
  /**
140
113
  * The series linked to the triggered axis.
141
114
  */
142
- series: PropTypes.arrayOf(PropTypes.shape({
143
- area: PropTypes.bool,
144
- color: PropTypes.string.isRequired,
145
- connectNulls: PropTypes.bool,
146
- curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
147
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
148
- dataKey: PropTypes.string,
149
- disableHighlight: PropTypes.bool,
150
- highlightScope: PropTypes.shape({
151
- faded: PropTypes.oneOf(['global', 'none', 'series']),
152
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
153
- }),
154
- id: PropTypes.string.isRequired,
155
- label: PropTypes.string,
156
- showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
157
- stack: PropTypes.string,
158
- stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
159
- stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
160
- type: PropTypes.oneOf(['line']).isRequired,
161
- valueFormatter: PropTypes.func.isRequired,
162
- xAxisKey: PropTypes.string,
163
- yAxisKey: PropTypes.string
164
- })).isRequired,
115
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
165
116
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
166
117
  } : void 0;
167
118
  export { DefaultChartsAxisTooltipContent };
@@ -72,17 +72,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
72
72
  /**
73
73
  * The series linked to the triggered axis.
74
74
  */
75
- series: PropTypes.shape({
76
- color: PropTypes.string,
77
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
78
- highlightScope: PropTypes.shape({
79
- faded: PropTypes.oneOf(['global', 'none', 'series']),
80
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
81
- }),
82
- id: PropTypes.string.isRequired,
83
- type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
84
- valueFormatter: PropTypes.func.isRequired
85
- }).isRequired,
75
+ series: PropTypes.object.isRequired,
86
76
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
87
77
  } : void 0;
88
78
  export { DefaultChartsItemTooltipContent };
@@ -88,4 +88,10 @@ export function getTooltipHasData(trigger, displayedData) {
88
88
  var hasAxisXData = displayedData.x !== null;
89
89
  var hasAxisYData = displayedData.y !== null;
90
90
  return hasAxisXData || hasAxisYData;
91
+ }
92
+ export function isCartesianSeriesType(seriesType) {
93
+ return ['bar', 'line', 'scatter'].includes(seriesType);
94
+ }
95
+ export function isCartesianSeries(series) {
96
+ return isCartesianSeriesType(series.type);
91
97
  }
@@ -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
  var _React$useContext$sca;
14
- var voronoiMaxRadius = props.voronoiMaxRadius;
14
+ var voronoiMaxRadius = props.voronoiMaxRadius,
15
+ onItemClick = props.onItemClick;
15
16
  var svgRef = React.useContext(SVGContext);
16
17
  var _React$useContext = React.useContext(DrawingContext),
17
18
  width = _React$useContext.width,
@@ -44,6 +45,8 @@ function ChartsVoronoiHandler(props) {
44
45
  };
45
46
  }, [dispatch]);
46
47
  useEnhancedEffect(function () {
48
+ // This effect generate and store the Delaunay object that's used to map coordinate to closest point.
49
+
47
50
  if (seriesOrder === undefined || series === undefined) {
48
51
  // If there is no scatter chart series
49
52
  return;
@@ -77,81 +80,122 @@ function ChartsVoronoiHandler(props) {
77
80
  if (element === null) {
78
81
  return undefined;
79
82
  }
80
- var handleMouseOut = function handleMouseOut() {
81
- dispatch({
82
- type: 'exitChart'
83
- });
84
- };
85
83
 
86
84
  // TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
87
- var handleMouseMove = function handleMouseMove(event) {
85
+ function getClosestPoint(event) {
88
86
  var _voronoiRef$current$d;
89
87
  // Get mouse coordinate in global SVG space
90
88
  var svgPoint = getSVGPoint(svgRef.current, event);
91
89
  var outsideX = svgPoint.x < left || svgPoint.x > left + width;
92
90
  var outsideY = svgPoint.y < top || svgPoint.y > top + height;
93
91
  if (outsideX || outsideY) {
94
- dispatch({
95
- type: 'exitChart'
96
- });
97
- return;
92
+ return 'outside-chart';
98
93
  }
99
94
  if (!voronoiRef.current.delauney) {
100
- return;
95
+ return 'no-point-found';
101
96
  }
102
97
  var closestPointIndex = (_voronoiRef$current$d = voronoiRef.current.delauney) == null ? void 0 : _voronoiRef$current$d.find(svgPoint.x, svgPoint.y);
103
- if (closestPointIndex !== undefined) {
104
- var seriesId = Object.keys(voronoiRef.current).find(function (id) {
105
- if (id === 'delauney') {
106
- return false;
107
- }
108
- return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
109
- });
110
- if (seriesId === undefined) {
111
- return;
98
+ if (closestPointIndex === undefined) {
99
+ return 'no-point-found';
100
+ }
101
+ var seriesId = Object.keys(voronoiRef.current).find(function (id) {
102
+ if (id === 'delauney') {
103
+ return false;
112
104
  }
113
- var dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
114
- if (voronoiMaxRadius !== undefined) {
115
- var pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
116
- var pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
117
- var dist2 = Math.pow(pointX - svgPoint.x, 2) + Math.pow(pointY - svgPoint.y, 2);
118
- if (dist2 > Math.pow(voronoiMaxRadius, 2)) {
119
- // The closest point is too far to be considered.
120
- dispatch({
121
- type: 'leaveItem',
122
- data: {
123
- type: 'scatter',
124
- seriesId: seriesId,
125
- dataIndex: dataIndex
126
- }
127
- });
128
- return;
129
- }
105
+ return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
106
+ });
107
+ if (seriesId === undefined) {
108
+ return 'no-point-found';
109
+ }
110
+ var dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
111
+ if (voronoiMaxRadius !== undefined) {
112
+ var pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
113
+ var pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
114
+ var dist2 = Math.pow(pointX - svgPoint.x, 2) + Math.pow(pointY - svgPoint.y, 2);
115
+ if (dist2 > Math.pow(voronoiMaxRadius, 2)) {
116
+ // The closest point is too far to be considered.
117
+ return 'outside-voronoi-max-radius';
130
118
  }
119
+ }
120
+ return {
121
+ seriesId: seriesId,
122
+ dataIndex: dataIndex
123
+ };
124
+ }
125
+ var handleMouseOut = function handleMouseOut() {
126
+ dispatch({
127
+ type: 'exitChart'
128
+ });
129
+ };
130
+ var handleMouseMove = function handleMouseMove(event) {
131
+ var closestPoint = getClosestPoint(event);
132
+ if (closestPoint === 'outside-chart') {
131
133
  dispatch({
132
- type: 'enterItem',
134
+ type: 'exitChart'
135
+ });
136
+ return;
137
+ }
138
+ if (closestPoint === 'outside-voronoi-max-radius' || closestPoint === 'no-point-found') {
139
+ dispatch({
140
+ type: 'leaveItem',
133
141
  data: {
134
- type: 'scatter',
135
- seriesId: seriesId,
136
- dataIndex: dataIndex
142
+ type: 'scatter'
137
143
  }
138
144
  });
145
+ return;
146
+ }
147
+ var seriesId = closestPoint.seriesId,
148
+ dataIndex = closestPoint.dataIndex;
149
+ dispatch({
150
+ type: 'enterItem',
151
+ data: {
152
+ type: 'scatter',
153
+ seriesId: seriesId,
154
+ dataIndex: dataIndex
155
+ }
156
+ });
157
+ };
158
+ var handleMouseClick = function handleMouseClick(event) {
159
+ if (!onItemClick) {
160
+ return;
139
161
  }
162
+ var closestPoint = getClosestPoint(event);
163
+ if (typeof closestPoint === 'string') {
164
+ // No point fond for any reason
165
+ return;
166
+ }
167
+ var seriesId = closestPoint.seriesId,
168
+ dataIndex = closestPoint.dataIndex;
169
+ onItemClick(event, {
170
+ type: 'scatter',
171
+ seriesId: seriesId,
172
+ dataIndex: dataIndex
173
+ });
140
174
  };
141
175
  element.addEventListener('mouseout', handleMouseOut);
142
176
  element.addEventListener('mousemove', handleMouseMove);
177
+ element.addEventListener('click', handleMouseClick);
143
178
  return function () {
144
179
  element.removeEventListener('mouseout', handleMouseOut);
145
180
  element.removeEventListener('mousemove', handleMouseMove);
181
+ element.removeEventListener('click', handleMouseClick);
146
182
  };
147
- }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
148
- return /*#__PURE__*/_jsx("g", {}); // Workaround to fix docs scripts
183
+ }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick]);
184
+
185
+ // eslint-disable-next-line react/jsx-no-useless-fragment
186
+ return /*#__PURE__*/_jsx(React.Fragment, {});
149
187
  }
150
188
  process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
151
189
  // ----------------------------- Warning --------------------------------
152
190
  // | These PropTypes are generated from the TypeScript type definitions |
153
191
  // | To update them edit the TypeScript types and run "yarn proptypes" |
154
192
  // ----------------------------------------------------------------------
193
+ /**
194
+ * Callback fired when clicking on a scatter item.
195
+ * @param {MouseEvent} event Mouse event catched at the svg level
196
+ * @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
197
+ */
198
+ onItemClick: PropTypes.func,
155
199
  /**
156
200
  * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
157
201
  * If `undefined`, the radius is assumed to be infinite.
@@ -0,0 +1,102 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _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 var AreaElementPath = styled(animated.path, {
15
+ name: 'MuiAreaElement',
16
+ slot: 'Root',
17
+ overridesResolver: function overridesResolver(_, styles) {
18
+ return styles.root;
19
+ }
20
+ })(function (_ref) {
21
+ var ownerState = _ref.ownerState;
22
+ return {
23
+ stroke: 'none',
24
+ fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
25
+ transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
26
+ opacity: ownerState.isFaded ? 0.3 : 1
27
+ };
28
+ });
29
+ /**
30
+ * Demos:
31
+ *
32
+ * - [Lines](https://mui.com/x/react-charts/lines/)
33
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
34
+ *
35
+ * API:
36
+ *
37
+ * - [AreaElement API](https://mui.com/x/api/charts/animated-area/)
38
+ */
39
+ function AnimatedArea(props) {
40
+ var d = props.d,
41
+ skipAnimation = props.skipAnimation,
42
+ ownerState = props.ownerState,
43
+ other = _objectWithoutProperties(props, _excluded);
44
+ var _React$useContext = React.useContext(DrawingContext),
45
+ left = _React$useContext.left,
46
+ top = _React$useContext.top,
47
+ right = _React$useContext.right,
48
+ bottom = _React$useContext.bottom,
49
+ width = _React$useContext.width,
50
+ height = _React$useContext.height,
51
+ chartId = _React$useContext.chartId;
52
+ var path = useAnimatedPath(d, skipAnimation);
53
+ var _useSpring = useSpring({
54
+ from: {
55
+ animatedWidth: left
56
+ },
57
+ to: {
58
+ animatedWidth: width + left + right
59
+ },
60
+ reset: false,
61
+ immediate: skipAnimation
62
+ }),
63
+ animatedWidth = _useSpring.animatedWidth;
64
+ var clipId = cleanId("".concat(chartId, "-").concat(ownerState.id, "-area-clip"));
65
+ return /*#__PURE__*/_jsxs(React.Fragment, {
66
+ children: [/*#__PURE__*/_jsx("clipPath", {
67
+ id: clipId,
68
+ children: /*#__PURE__*/_jsx(animated.rect, {
69
+ x: 0,
70
+ y: 0,
71
+ width: animatedWidth,
72
+ height: top + height + bottom
73
+ })
74
+ }), /*#__PURE__*/_jsx("g", {
75
+ clipPath: "url(#".concat(clipId, ")"),
76
+ children: /*#__PURE__*/_jsx(AreaElementPath, _extends({}, other, {
77
+ ownerState: ownerState,
78
+ d: path
79
+ }))
80
+ })]
81
+ });
82
+ }
83
+ process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
84
+ // ----------------------------- Warning --------------------------------
85
+ // | These PropTypes are generated from the TypeScript type definitions |
86
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
87
+ // ----------------------------------------------------------------------
88
+ d: PropTypes.string.isRequired,
89
+ ownerState: PropTypes.shape({
90
+ classes: PropTypes.object,
91
+ color: PropTypes.string.isRequired,
92
+ id: PropTypes.string.isRequired,
93
+ isFaded: PropTypes.bool.isRequired,
94
+ isHighlighted: PropTypes.bool.isRequired
95
+ }).isRequired,
96
+ /**
97
+ * If `true`, animations are skipped.
98
+ * @default false
99
+ */
100
+ skipAnimation: PropTypes.bool
101
+ } : void 0;
102
+ export { AnimatedArea };
@@ -0,0 +1,104 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _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 var LineElementPath = styled(animated.path, {
15
+ name: 'MuiLineElement',
16
+ slot: 'Root',
17
+ overridesResolver: function overridesResolver(_, styles) {
18
+ return styles.root;
19
+ }
20
+ })(function (_ref) {
21
+ var ownerState = _ref.ownerState;
22
+ return {
23
+ strokeWidth: 2,
24
+ strokeLinejoin: 'round',
25
+ fill: 'none',
26
+ stroke: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
27
+ transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
28
+ opacity: ownerState.isFaded ? 0.3 : 1
29
+ };
30
+ });
31
+ /**
32
+ * Demos:
33
+ *
34
+ * - [Lines](https://mui.com/x/react-charts/lines/)
35
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
36
+ *
37
+ * API:
38
+ *
39
+ * - [AnimatedLine API](https://mui.com/x/api/charts/animated-line/)
40
+ */
41
+ function AnimatedLine(props) {
42
+ var d = props.d,
43
+ skipAnimation = props.skipAnimation,
44
+ ownerState = props.ownerState,
45
+ other = _objectWithoutProperties(props, _excluded);
46
+ var _React$useContext = React.useContext(DrawingContext),
47
+ left = _React$useContext.left,
48
+ top = _React$useContext.top,
49
+ bottom = _React$useContext.bottom,
50
+ width = _React$useContext.width,
51
+ height = _React$useContext.height,
52
+ right = _React$useContext.right,
53
+ chartId = _React$useContext.chartId;
54
+ var path = useAnimatedPath(d, skipAnimation);
55
+ var _useSpring = useSpring({
56
+ from: {
57
+ animatedWidth: left
58
+ },
59
+ to: {
60
+ animatedWidth: width + left + right
61
+ },
62
+ reset: false,
63
+ immediate: skipAnimation
64
+ }),
65
+ animatedWidth = _useSpring.animatedWidth;
66
+ var clipId = cleanId("".concat(chartId, "-").concat(ownerState.id, "-line-clip"));
67
+ return /*#__PURE__*/_jsxs(React.Fragment, {
68
+ children: [/*#__PURE__*/_jsx("clipPath", {
69
+ id: clipId,
70
+ children: /*#__PURE__*/_jsx(animated.rect, {
71
+ x: 0,
72
+ y: 0,
73
+ width: animatedWidth,
74
+ height: top + height + bottom
75
+ })
76
+ }), /*#__PURE__*/_jsx("g", {
77
+ clipPath: "url(#".concat(clipId, ")"),
78
+ children: /*#__PURE__*/_jsx(LineElementPath, _extends({}, other, {
79
+ ownerState: ownerState,
80
+ d: path
81
+ }))
82
+ })]
83
+ });
84
+ }
85
+ process.env.NODE_ENV !== "production" ? AnimatedLine.propTypes = {
86
+ // ----------------------------- Warning --------------------------------
87
+ // | These PropTypes are generated from the TypeScript type definitions |
88
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
89
+ // ----------------------------------------------------------------------
90
+ d: PropTypes.string.isRequired,
91
+ ownerState: PropTypes.shape({
92
+ classes: PropTypes.object,
93
+ color: PropTypes.string.isRequired,
94
+ id: PropTypes.string.isRequired,
95
+ isFaded: PropTypes.bool.isRequired,
96
+ isHighlighted: PropTypes.bool.isRequired
97
+ }).isRequired,
98
+ /**
99
+ * If `true`, animations are skipped.
100
+ * @default false
101
+ */
102
+ skipAnimation: PropTypes.bool
103
+ } : void 0;
104
+ export { AnimatedLine };