@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
@@ -0,0 +1,245 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["width", "height"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
+ import ownerWindow from '@mui/utils/ownerWindow';
8
+ import { styled } from '@mui/material/styles';
9
+ import { ChartContainer } from '../ChartContainer';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ const useChartDimensions = (inWidth, inHeight) => {
12
+ const rootRef = React.useRef(null);
13
+ const displayError = React.useRef(false);
14
+ const [width, setWidth] = React.useState(0);
15
+ const [height, setHeight] = React.useState(0);
16
+
17
+ // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
18
+ const computeSize = React.useCallback(() => {
19
+ const mainEl = rootRef == null ? void 0 : rootRef.current;
20
+ if (!mainEl) {
21
+ return;
22
+ }
23
+ const win = ownerWindow(mainEl);
24
+ const computedStyle = win.getComputedStyle(mainEl);
25
+ const newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
26
+ const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
27
+ setWidth(newWidth);
28
+ setHeight(newHeight);
29
+ }, []);
30
+ React.useEffect(() => {
31
+ // Ensure the error detection occurs after the first rendering.
32
+ displayError.current = true;
33
+ }, []);
34
+ useEnhancedEffect(() => {
35
+ if (inWidth !== undefined && inHeight !== undefined) {
36
+ return () => {};
37
+ }
38
+ computeSize();
39
+ const elementToObserve = rootRef.current;
40
+ if (typeof ResizeObserver === 'undefined') {
41
+ return () => {};
42
+ }
43
+ let animationFrame;
44
+ const observer = new ResizeObserver(() => {
45
+ // See https://github.com/mui/mui-x/issues/8733
46
+ animationFrame = requestAnimationFrame(() => {
47
+ computeSize();
48
+ });
49
+ });
50
+ if (elementToObserve) {
51
+ observer.observe(elementToObserve);
52
+ }
53
+ return () => {
54
+ if (animationFrame) {
55
+ window.cancelAnimationFrame(animationFrame);
56
+ }
57
+ if (elementToObserve) {
58
+ observer.unobserve(elementToObserve);
59
+ }
60
+ };
61
+ }, [computeSize, inHeight, inWidth]);
62
+ if (process.env.NODE_ENV !== 'production') {
63
+ if (displayError.current && inWidth === undefined && width === 0) {
64
+ console.error(`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
65
+ displayError.current = false;
66
+ }
67
+ if (displayError.current && inHeight === undefined && height === 0) {
68
+ console.error(`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
69
+ displayError.current = false;
70
+ }
71
+ }
72
+ return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
73
+ };
74
+ const ResizableContainer = styled('div', {
75
+ name: 'MuiResponsiveChart',
76
+ slot: 'Container'
77
+ })(({
78
+ ownerState
79
+ }) => {
80
+ var _ownerState$width, _ownerState$height;
81
+ return {
82
+ width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
83
+ height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
84
+ display: 'flex',
85
+ position: 'relative',
86
+ flexGrow: 1,
87
+ flexDirection: 'column',
88
+ alignItems: 'center',
89
+ justifyContent: 'center',
90
+ overflow: 'hidden',
91
+ '&>svg': {
92
+ width: '100%',
93
+ height: '100%'
94
+ }
95
+ };
96
+ });
97
+ const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
98
+ const {
99
+ width: inWidth,
100
+ height: inHeight
101
+ } = props,
102
+ other = _objectWithoutPropertiesLoose(props, _excluded);
103
+ const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
104
+ return /*#__PURE__*/_jsx(ResizableContainer, {
105
+ ref: containerRef,
106
+ ownerState: {
107
+ width: inWidth,
108
+ height: inHeight
109
+ },
110
+ children: width && height ? /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
111
+ width: width,
112
+ height: height,
113
+ ref: ref
114
+ })) : null
115
+ });
116
+ });
117
+ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
118
+ // ----------------------------- Warning --------------------------------
119
+ // | These PropTypes are generated from the TypeScript type definitions |
120
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
121
+ // ----------------------------------------------------------------------
122
+ children: PropTypes.node,
123
+ className: PropTypes.string,
124
+ /**
125
+ * Color palette used to colorize multiple series.
126
+ * @default blueberryTwilightPalette
127
+ */
128
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
129
+ /**
130
+ * An array of objects that can be used to populate series and axes data using their `dataKey` property.
131
+ */
132
+ dataset: PropTypes.arrayOf(PropTypes.object),
133
+ desc: PropTypes.string,
134
+ /**
135
+ * If `true`, the charts will not listen to the mouse move event.
136
+ * It might break interactive features, but will improve performance.
137
+ * @default false
138
+ */
139
+ disableAxisListener: PropTypes.bool,
140
+ /**
141
+ * The height of the chart in px. If not defined, it takes the height of the parent element.
142
+ * @default undefined
143
+ */
144
+ height: PropTypes.number,
145
+ /**
146
+ * The margin between the SVG and the drawing area.
147
+ * It's used for leaving some space for extra information such as the x- and y-axis or legend.
148
+ * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
149
+ * @default object Depends on the charts type.
150
+ */
151
+ margin: PropTypes.shape({
152
+ bottom: PropTypes.number,
153
+ left: PropTypes.number,
154
+ right: PropTypes.number,
155
+ top: PropTypes.number
156
+ }),
157
+ /**
158
+ * The array of series to display.
159
+ * Each type of series has its own specificity.
160
+ * Please refer to the appropriate docs page to learn more about it.
161
+ */
162
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
163
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
164
+ title: PropTypes.string,
165
+ viewBox: PropTypes.shape({
166
+ height: PropTypes.number,
167
+ width: PropTypes.number,
168
+ x: PropTypes.number,
169
+ y: PropTypes.number
170
+ }),
171
+ /**
172
+ * The width of the chart in px. If not defined, it takes the width of the parent element.
173
+ * @default undefined
174
+ */
175
+ width: PropTypes.number,
176
+ /**
177
+ * The configuration of the x-axes.
178
+ * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
179
+ */
180
+ xAxis: PropTypes.arrayOf(PropTypes.shape({
181
+ axisId: PropTypes.string,
182
+ classes: PropTypes.object,
183
+ data: PropTypes.array,
184
+ dataKey: PropTypes.string,
185
+ disableLine: PropTypes.bool,
186
+ disableTicks: PropTypes.bool,
187
+ fill: PropTypes.string,
188
+ hideTooltip: PropTypes.bool,
189
+ id: PropTypes.string,
190
+ label: PropTypes.string,
191
+ labelFontSize: PropTypes.number,
192
+ labelStyle: PropTypes.object,
193
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
194
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
195
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
196
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
197
+ slotProps: PropTypes.object,
198
+ slots: PropTypes.object,
199
+ stroke: PropTypes.string,
200
+ tickFontSize: PropTypes.number,
201
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
202
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
203
+ tickLabelStyle: PropTypes.object,
204
+ tickMaxStep: PropTypes.number,
205
+ tickMinStep: PropTypes.number,
206
+ tickNumber: PropTypes.number,
207
+ tickSize: PropTypes.number,
208
+ valueFormatter: PropTypes.func
209
+ })),
210
+ /**
211
+ * The configuration of the y-axes.
212
+ * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
213
+ */
214
+ yAxis: PropTypes.arrayOf(PropTypes.shape({
215
+ axisId: PropTypes.string,
216
+ classes: PropTypes.object,
217
+ data: PropTypes.array,
218
+ dataKey: PropTypes.string,
219
+ disableLine: PropTypes.bool,
220
+ disableTicks: PropTypes.bool,
221
+ fill: PropTypes.string,
222
+ hideTooltip: PropTypes.bool,
223
+ id: PropTypes.string,
224
+ label: PropTypes.string,
225
+ labelFontSize: PropTypes.number,
226
+ labelStyle: PropTypes.object,
227
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
228
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
229
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
230
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
231
+ slotProps: PropTypes.object,
232
+ slots: PropTypes.object,
233
+ stroke: PropTypes.string,
234
+ tickFontSize: PropTypes.number,
235
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
236
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
237
+ tickLabelStyle: PropTypes.object,
238
+ tickMaxStep: PropTypes.number,
239
+ tickMinStep: PropTypes.number,
240
+ tickNumber: PropTypes.number,
241
+ tickSize: PropTypes.number,
242
+ valueFormatter: PropTypes.func
243
+ }))
244
+ } : void 0;
245
+ export { ResponsiveChartContainer };
@@ -1,115 +1 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["width", "height"];
4
- import * as React from 'react';
5
- import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
6
- import ownerWindow from '@mui/utils/ownerWindow';
7
- import { styled } from '@mui/material/styles';
8
- import { ChartContainer } from '../ChartContainer';
9
- import { jsx as _jsx } from "react/jsx-runtime";
10
- const useChartDimensions = (inWidth, inHeight) => {
11
- const rootRef = React.useRef(null);
12
- const displayError = React.useRef(false);
13
- const [width, setWidth] = React.useState(0);
14
- const [height, setHeight] = React.useState(0);
15
-
16
- // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
17
- const computeSize = React.useCallback(() => {
18
- const mainEl = rootRef == null ? void 0 : rootRef.current;
19
- if (!mainEl) {
20
- return;
21
- }
22
- const win = ownerWindow(mainEl);
23
- const computedStyle = win.getComputedStyle(mainEl);
24
- const newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
25
- const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
26
- setWidth(newWidth);
27
- setHeight(newHeight);
28
- }, []);
29
- React.useEffect(() => {
30
- // Ensure the error detection occurs after the first rendering.
31
- displayError.current = true;
32
- }, []);
33
- useEnhancedEffect(() => {
34
- if (inWidth !== undefined && inHeight !== undefined) {
35
- return () => {};
36
- }
37
- computeSize();
38
- const elementToObserve = rootRef.current;
39
- if (typeof ResizeObserver === 'undefined') {
40
- return () => {};
41
- }
42
- let animationFrame;
43
- const observer = new ResizeObserver(() => {
44
- // See https://github.com/mui/mui-x/issues/8733
45
- animationFrame = requestAnimationFrame(() => {
46
- computeSize();
47
- });
48
- });
49
- if (elementToObserve) {
50
- observer.observe(elementToObserve);
51
- }
52
- return () => {
53
- if (animationFrame) {
54
- window.cancelAnimationFrame(animationFrame);
55
- }
56
- if (elementToObserve) {
57
- observer.unobserve(elementToObserve);
58
- }
59
- };
60
- }, [computeSize, inHeight, inWidth]);
61
- if (process.env.NODE_ENV !== 'production') {
62
- if (displayError.current && inWidth === undefined && width === 0) {
63
- console.error(`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
64
- displayError.current = false;
65
- }
66
- if (displayError.current && inHeight === undefined && height === 0) {
67
- console.error(`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
68
- displayError.current = false;
69
- }
70
- }
71
- return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
72
- };
73
- const ResizableContainer = styled('div', {
74
- name: 'MuiResponsiveChart',
75
- slot: 'Container'
76
- })(({
77
- ownerState
78
- }) => {
79
- var _ownerState$width, _ownerState$height;
80
- return {
81
- width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
82
- height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
83
- display: 'flex',
84
- position: 'relative',
85
- flexGrow: 1,
86
- flexDirection: 'column',
87
- alignItems: 'center',
88
- justifyContent: 'center',
89
- overflow: 'hidden',
90
- '&>svg': {
91
- width: '100%',
92
- height: '100%'
93
- }
94
- };
95
- });
96
- export const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
97
- const {
98
- width: inWidth,
99
- height: inHeight
100
- } = props,
101
- other = _objectWithoutPropertiesLoose(props, _excluded);
102
- const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
103
- return /*#__PURE__*/_jsx(ResizableContainer, {
104
- ref: containerRef,
105
- ownerState: {
106
- width: inWidth,
107
- height: inHeight
108
- },
109
- children: width && height ? /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
110
- width: width,
111
- height: height,
112
- ref: ref
113
- })) : null
114
- });
115
- });
1
+ export * from './ResponsiveChartContainer';
@@ -21,7 +21,8 @@ function Scatter(props) {
21
21
  xScale,
22
22
  yScale,
23
23
  color,
24
- markerSize
24
+ markerSize,
25
+ onItemClick
25
26
  } = props;
26
27
  const highlightScope = React.useMemo(() => _extends({
27
28
  highlighted: 'item',
@@ -61,7 +62,8 @@ function Scatter(props) {
61
62
  isHighlighted,
62
63
  isFaded: !isHighlighted && getIsFaded(item, pointCtx, highlightScope),
63
64
  interactionProps: getInteractionItemProps(pointCtx),
64
- id: scatterPoint.id
65
+ id: scatterPoint.id,
66
+ dataIndex: i
65
67
  });
66
68
  }
67
69
  }
@@ -74,7 +76,13 @@ function Scatter(props) {
74
76
  r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
75
77
  transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
76
78
  fill: color,
77
- opacity: dataPoint.isFaded && 0.3 || 1
79
+ opacity: dataPoint.isFaded && 0.3 || 1,
80
+ onClick: onItemClick && (event => onItemClick(event, {
81
+ type: 'scatter',
82
+ seriesId: series.id,
83
+ dataIndex: dataPoint.dataIndex
84
+ })),
85
+ cursor: onItemClick ? 'pointer' : 'unset'
78
86
  }, dataPoint.interactionProps), dataPoint.id))
79
87
  });
80
88
  }
@@ -85,26 +93,13 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
85
93
  // ----------------------------------------------------------------------
86
94
  color: PropTypes.string.isRequired,
87
95
  markerSize: PropTypes.number.isRequired,
88
- series: PropTypes.shape({
89
- color: PropTypes.string.isRequired,
90
- data: PropTypes.arrayOf(PropTypes.shape({
91
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
92
- x: PropTypes.number.isRequired,
93
- y: PropTypes.number.isRequired
94
- })).isRequired,
95
- disableHover: PropTypes.bool,
96
- highlightScope: PropTypes.shape({
97
- faded: PropTypes.oneOf(['global', 'none', 'series']),
98
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
99
- }),
100
- id: PropTypes.string.isRequired,
101
- label: PropTypes.string,
102
- markerSize: PropTypes.number,
103
- type: PropTypes.oneOf(['scatter']).isRequired,
104
- valueFormatter: PropTypes.func.isRequired,
105
- xAxisKey: PropTypes.string,
106
- yAxisKey: PropTypes.string
107
- }).isRequired,
96
+ /**
97
+ * Callback fired when clicking on a scatter item.
98
+ * @param {MouseEvent} event Mouse event recorded on the `<svg/>` element.
99
+ * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
100
+ */
101
+ onItemClick: PropTypes.func,
102
+ series: PropTypes.object.isRequired,
108
103
  xScale: PropTypes.func.isRequired,
109
104
  yScale: PropTypes.func.isRequired
110
105
  } : void 0;
@@ -39,6 +39,7 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
39
39
  leftAxis,
40
40
  rightAxis,
41
41
  bottomAxis,
42
+ onItemClick,
42
43
  children,
43
44
  slots,
44
45
  slotProps
@@ -56,7 +57,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
56
57
  yAxis: yAxis,
57
58
  sx: sx,
58
59
  children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
59
- voronoiMaxRadius: voronoiMaxRadius
60
+ voronoiMaxRadius: voronoiMaxRadius,
61
+ onItemClick: onItemClick
60
62
  }), /*#__PURE__*/_jsx(ChartsAxis, {
61
63
  topAxis: topAxis,
62
64
  leftAxis: leftAxis,
@@ -66,7 +68,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
66
68
  slotProps: slotProps
67
69
  }), /*#__PURE__*/_jsx(ScatterPlot, {
68
70
  slots: slots,
69
- slotProps: slotProps
71
+ slotProps: slotProps,
72
+ onItemClick: disableVoronoi ? onItemClick : undefined
70
73
  }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
71
74
  slots: slots,
72
75
  slotProps: slotProps
@@ -195,6 +198,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
195
198
  right: PropTypes.number,
196
199
  top: PropTypes.number
197
200
  }),
201
+ /**
202
+ * Callback fired when clicking on a scatter item.
203
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element if using Voronoi cells. Or the Mouse event from the scatter element, when `disableVoronoi=true`.
204
+ * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
205
+ */
206
+ onItemClick: PropTypes.func,
198
207
  /**
199
208
  * Indicate which axis to display the right of the charts.
200
209
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -222,26 +231,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
222
231
  tickNumber: PropTypes.number,
223
232
  tickSize: PropTypes.number
224
233
  }), PropTypes.string]),
225
- series: PropTypes.arrayOf(PropTypes.shape({
226
- color: PropTypes.string,
227
- data: PropTypes.arrayOf(PropTypes.shape({
228
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
229
- x: PropTypes.number.isRequired,
230
- y: PropTypes.number.isRequired
231
- })).isRequired,
232
- disableHover: PropTypes.bool,
233
- highlightScope: PropTypes.shape({
234
- faded: PropTypes.oneOf(['global', 'none', 'series']),
235
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
236
- }),
237
- id: PropTypes.string,
238
- label: PropTypes.string,
239
- markerSize: PropTypes.number,
240
- type: PropTypes.oneOf(['scatter']),
241
- valueFormatter: PropTypes.func,
242
- xAxisKey: PropTypes.string,
243
- yAxisKey: PropTypes.string
244
- })).isRequired,
234
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
245
235
  /**
246
236
  * The props used for each component slot.
247
237
  * @default {}
@@ -19,7 +19,8 @@ function ScatterPlot(props) {
19
19
  var _slots$scatter;
20
20
  const {
21
21
  slots,
22
- slotProps
22
+ slotProps,
23
+ onItemClick
23
24
  } = props;
24
25
  const seriesData = React.useContext(SeriesContext).scatter;
25
26
  const axisData = React.useContext(CartesianContext);
@@ -55,7 +56,8 @@ function ScatterPlot(props) {
55
56
  yScale: yScale,
56
57
  color: color,
57
58
  markerSize: markerSize != null ? markerSize : 4,
58
- series: series[seriesId]
59
+ series: series[seriesId],
60
+ onItemClick: onItemClick
59
61
  }, slotProps == null ? void 0 : slotProps.scatter), id);
60
62
  })
61
63
  });
@@ -65,6 +67,12 @@ process.env.NODE_ENV !== "production" ? ScatterPlot.propTypes = {
65
67
  // | These PropTypes are generated from the TypeScript type definitions |
66
68
  // | To update them edit the TypeScript types and run "yarn proptypes" |
67
69
  // ----------------------------------------------------------------------
70
+ /**
71
+ * Callback fired when clicking on a scatter item.
72
+ * @param {MouseEvent} event Mouse event recorded on the `<svg/>` element.
73
+ * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
74
+ */
75
+ onItemClick: PropTypes.func,
68
76
  /**
69
77
  * The props used for each component slot.
70
78
  * @default {}
@@ -86,9 +86,11 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
86
86
  }
87
87
  }), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
88
88
  children: [/*#__PURE__*/_jsx(AreaPlot, {
89
+ skipAnimation: true,
89
90
  slots: slots,
90
91
  slotProps: slotProps
91
92
  }), /*#__PURE__*/_jsx(LinePlot, {
93
+ skipAnimation: true,
92
94
  slots: slots,
93
95
  slotProps: slotProps
94
96
  }), /*#__PURE__*/_jsx(LineHighlightPlot, {
@@ -1,5 +1,7 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
2
3
  import PropTypes from 'prop-types';
4
+ import useId from '@mui/utils/useId';
3
5
  import useChartDimensions from '../hooks/useChartDimensions';
4
6
 
5
7
  /**
@@ -12,7 +14,8 @@ export const DrawingContext = /*#__PURE__*/React.createContext({
12
14
  bottom: 0,
13
15
  right: 0,
14
16
  height: 300,
15
- width: 400
17
+ width: 400,
18
+ chartId: ''
16
19
  });
17
20
  export const SVGContext = /*#__PURE__*/React.createContext({
18
21
  current: null
@@ -32,10 +35,14 @@ function DrawingProvider(props) {
32
35
  children
33
36
  } = props;
34
37
  const drawingArea = useChartDimensions(width, height, margin);
38
+ const chartId = useId();
39
+ const value = React.useMemo(() => _extends({
40
+ chartId: chartId != null ? chartId : ''
41
+ }, drawingArea), [chartId, drawingArea]);
35
42
  return /*#__PURE__*/_jsx(SVGContext.Provider, {
36
43
  value: svgRef,
37
44
  children: /*#__PURE__*/_jsx(DrawingContext.Provider, {
38
- value: drawingArea,
45
+ value: value,
39
46
  children: children
40
47
  })
41
48
  });
@@ -5,12 +5,16 @@ export function useDrawingArea() {
5
5
  left,
6
6
  top,
7
7
  width,
8
- height
8
+ height,
9
+ bottom,
10
+ right
9
11
  } = React.useContext(DrawingContext);
10
12
  return React.useMemo(() => ({
11
13
  left,
12
14
  top,
13
15
  width,
14
- height
15
- }), [height, left, top, width]);
16
+ height,
17
+ bottom,
18
+ right
19
+ }), [height, left, top, width, bottom, right]);
16
20
  }
package/esm/index.js CHANGED
@@ -13,6 +13,7 @@ export * from './ChartsTooltip';
13
13
  export * from './ChartsLegend';
14
14
  export * from './ChartsAxisHighlight';
15
15
  export * from './ChartsVoronoiHandler';
16
+ export * from './ChartsOnAxisClickHandler';
16
17
  export * from './BarChart';
17
18
  export * from './LineChart';
18
19
  export * from './PieChart';
@@ -14,7 +14,7 @@ export function getMinXTranslation(width, height, angle = 0) {
14
14
  if (process.env.NODE_ENV !== 'production') {
15
15
  if (!warnedOnce && angle > 90 && angle < -90) {
16
16
  warnedOnce = true;
17
- console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
17
+ console.warn([`MUI X Charts: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
18
18
  }
19
19
  }
20
20
  const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import { interpolateString } from 'd3-interpolate';
3
+ import { useSpring, to } from '@react-spring/web';
4
+ function usePrevious(value) {
5
+ const ref = React.useRef(null);
6
+ React.useEffect(() => {
7
+ ref.current = value;
8
+ }, [value]);
9
+ return ref.current;
10
+ }
11
+
12
+ // Taken from Nivo
13
+ export const useAnimatedPath = (path, skipAnimation) => {
14
+ const previousPath = usePrevious(path);
15
+ const interpolator = React.useMemo(() => previousPath ? interpolateString(previousPath, path) : () => path, [previousPath, path]);
16
+ const {
17
+ value
18
+ } = useSpring({
19
+ from: {
20
+ value: 0
21
+ },
22
+ to: {
23
+ value: 1
24
+ },
25
+ reset: true,
26
+ immediate: skipAnimation
27
+ });
28
+ return to([value], interpolator);
29
+ };
@@ -42,4 +42,11 @@ export function getPercentageValue(value, refValue) {
42
42
  }
43
43
  }
44
44
  throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
45
+ }
46
+
47
+ /**
48
+ * Remove spaces to have viable ids
49
+ */
50
+ export function cleanId(id) {
51
+ return id.replace(' ', '_');
45
52
  }
@@ -3,4 +3,6 @@ export declare function useDrawingArea(): {
3
3
  top: number;
4
4
  width: number;
5
5
  height: number;
6
+ bottom: number;
7
+ right: number;
6
8
  };