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