@mui/x-charts 6.0.0-alpha.15 → 6.0.0-alpha.16

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 (173) hide show
  1. package/BarChart/BarChart.d.ts +13 -2
  2. package/BarChart/BarChart.js +45 -3
  3. package/BarChart/BarElement.d.ts +1318 -3
  4. package/BarChart/BarElement.js +10 -8
  5. package/BarChart/BarPlot.d.ts +17 -1
  6. package/BarChart/BarPlot.js +152 -66
  7. package/CHANGELOG.md +65 -0
  8. package/ChartContainer/index.js +5 -2
  9. package/ChartsAxis/ChartsAxis.js +18 -2
  10. package/ChartsAxis/axisClasses.d.ts +1 -1
  11. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  12. package/ChartsClipPath/ChartsClipPath.js +2 -2
  13. package/ChartsLegend/ChartsLegend.d.ts +2 -1
  14. package/ChartsLegend/ChartsLegend.js +12 -8
  15. package/ChartsSurface.js +2 -2
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  17. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  18. package/ChartsTooltip/ChartsTooltip.js +2 -2
  19. package/ChartsTooltip/utils.js +2 -2
  20. package/ChartsXAxis/ChartsXAxis.js +123 -35
  21. package/ChartsYAxis/ChartsYAxis.js +38 -16
  22. package/LineChart/AreaElement.d.ts +10 -0
  23. package/LineChart/AreaElement.js +12 -2
  24. package/LineChart/AreaPlot.d.ts +11 -0
  25. package/LineChart/AreaPlot.js +13 -2
  26. package/LineChart/LineChart.d.ts +10 -0
  27. package/LineChart/LineChart.js +36 -2
  28. package/LineChart/LineElement.d.ts +10 -0
  29. package/LineChart/LineElement.js +12 -2
  30. package/LineChart/LineHighlightElement.d.ts +10 -0
  31. package/LineChart/LineHighlightElement.js +12 -2
  32. package/LineChart/LineHighlightPlot.d.ts +10 -0
  33. package/LineChart/LineHighlightPlot.js +12 -2
  34. package/LineChart/LinePlot.d.ts +10 -0
  35. package/LineChart/LinePlot.js +12 -2
  36. package/LineChart/MarkElement.d.ts +10 -0
  37. package/LineChart/MarkElement.js +12 -2
  38. package/LineChart/MarkPlot.d.ts +10 -0
  39. package/LineChart/MarkPlot.js +12 -2
  40. package/PieChart/PieArc.js +2 -2
  41. package/PieChart/PieArcLabel.js +2 -2
  42. package/PieChart/PieChart.d.ts +10 -0
  43. package/PieChart/PieChart.js +37 -2
  44. package/PieChart/PiePlot.d.ts +10 -0
  45. package/PieChart/PiePlot.js +12 -2
  46. package/ResponsiveChartContainer/index.js +4 -4
  47. package/ScatterChart/Scatter.d.ts +10 -0
  48. package/ScatterChart/Scatter.js +12 -2
  49. package/ScatterChart/ScatterChart.d.ts +10 -0
  50. package/ScatterChart/ScatterChart.js +36 -2
  51. package/ScatterChart/ScatterPlot.d.ts +10 -0
  52. package/ScatterChart/ScatterPlot.js +12 -2
  53. package/SparkLineChart/SparkLineChart.d.ts +9 -0
  54. package/SparkLineChart/SparkLineChart.js +16 -2
  55. package/context/CartesianContextProvider.js +10 -2
  56. package/context/DrawingProvider.js +2 -2
  57. package/context/HighlightProvider.js +2 -2
  58. package/context/InteractionProvider.js +2 -2
  59. package/context/SeriesContextProvider.js +2 -2
  60. package/esm/BarChart/BarChart.js +43 -1
  61. package/esm/BarChart/BarElement.js +7 -4
  62. package/esm/BarChart/BarPlot.js +152 -67
  63. package/esm/ChartContainer/index.js +3 -0
  64. package/esm/ChartsAxis/ChartsAxis.js +16 -0
  65. package/esm/ChartsLegend/ChartsLegend.js +10 -6
  66. package/esm/ChartsXAxis/ChartsXAxis.js +122 -34
  67. package/esm/ChartsYAxis/ChartsYAxis.js +36 -14
  68. package/esm/LineChart/AreaElement.js +10 -0
  69. package/esm/LineChart/AreaPlot.js +11 -0
  70. package/esm/LineChart/LineChart.js +34 -0
  71. package/esm/LineChart/LineElement.js +10 -0
  72. package/esm/LineChart/LineHighlightElement.js +10 -0
  73. package/esm/LineChart/LineHighlightPlot.js +10 -0
  74. package/esm/LineChart/LinePlot.js +10 -0
  75. package/esm/LineChart/MarkElement.js +10 -0
  76. package/esm/LineChart/MarkPlot.js +10 -0
  77. package/esm/PieChart/PieChart.js +35 -0
  78. package/esm/PieChart/PiePlot.js +10 -0
  79. package/esm/ResponsiveChartContainer/index.js +2 -2
  80. package/esm/ScatterChart/Scatter.js +10 -0
  81. package/esm/ScatterChart/ScatterChart.js +34 -0
  82. package/esm/ScatterChart/ScatterPlot.js +10 -0
  83. package/esm/SparkLineChart/SparkLineChart.js +14 -0
  84. package/esm/context/CartesianContextProvider.js +8 -0
  85. package/esm/hooks/useMounted.js +16 -0
  86. package/esm/hooks/useReducedMotion.js +27 -0
  87. package/esm/hooks/useTicks.js +12 -6
  88. package/esm/internals/components/ChartsText.js +17 -13
  89. package/esm/internals/geometry.js +36 -0
  90. package/hooks/useAxisEvents.js +2 -2
  91. package/hooks/useChartDimensions.js +2 -2
  92. package/hooks/useDrawingArea.js +2 -2
  93. package/hooks/useInteractionItemProps.js +2 -2
  94. package/hooks/useMounted.d.ts +1 -0
  95. package/hooks/useMounted.js +25 -0
  96. package/hooks/useReducedMotion.d.ts +8 -0
  97. package/hooks/useReducedMotion.js +33 -0
  98. package/hooks/useScale.d.ts +2 -2
  99. package/hooks/useScale.js +2 -2
  100. package/hooks/useTicks.d.ts +18 -9
  101. package/hooks/useTicks.js +14 -8
  102. package/index.js +1 -1
  103. package/internals/components/ChartsText.d.ts +11 -8
  104. package/internals/components/ChartsText.js +19 -15
  105. package/internals/defaultizeColor.d.ts +1 -1
  106. package/internals/domUtils.d.ts +0 -1
  107. package/internals/geometry.d.ts +9 -0
  108. package/internals/geometry.js +42 -0
  109. package/legacy/BarChart/BarChart.js +43 -1
  110. package/legacy/BarChart/BarElement.js +6 -3
  111. package/legacy/BarChart/BarPlot.js +151 -63
  112. package/legacy/ChartContainer/index.js +3 -0
  113. package/legacy/ChartsAxis/ChartsAxis.js +16 -0
  114. package/legacy/ChartsLegend/ChartsLegend.js +14 -7
  115. package/legacy/ChartsXAxis/ChartsXAxis.js +126 -36
  116. package/legacy/ChartsYAxis/ChartsYAxis.js +36 -14
  117. package/legacy/LineChart/AreaElement.js +10 -0
  118. package/legacy/LineChart/AreaPlot.js +11 -0
  119. package/legacy/LineChart/LineChart.js +34 -0
  120. package/legacy/LineChart/LineElement.js +10 -0
  121. package/legacy/LineChart/LineHighlightElement.js +10 -0
  122. package/legacy/LineChart/LineHighlightPlot.js +10 -0
  123. package/legacy/LineChart/LinePlot.js +10 -0
  124. package/legacy/LineChart/MarkElement.js +10 -0
  125. package/legacy/LineChart/MarkPlot.js +10 -0
  126. package/legacy/PieChart/PieChart.js +35 -0
  127. package/legacy/PieChart/PiePlot.js +10 -0
  128. package/legacy/ResponsiveChartContainer/index.js +2 -2
  129. package/legacy/ScatterChart/Scatter.js +10 -0
  130. package/legacy/ScatterChart/ScatterChart.js +34 -0
  131. package/legacy/ScatterChart/ScatterPlot.js +10 -0
  132. package/legacy/SparkLineChart/SparkLineChart.js +14 -0
  133. package/legacy/context/CartesianContextProvider.js +8 -0
  134. package/legacy/hooks/useMounted.js +21 -0
  135. package/legacy/hooks/useReducedMotion.js +27 -0
  136. package/legacy/hooks/useTicks.js +13 -6
  137. package/legacy/index.js +1 -1
  138. package/legacy/internals/components/ChartsText.js +15 -15
  139. package/legacy/internals/geometry.js +37 -0
  140. package/models/axis.d.ts +19 -2
  141. package/models/seriesType/line.d.ts +2 -2
  142. package/modern/BarChart/BarChart.js +43 -1
  143. package/modern/BarChart/BarElement.js +7 -4
  144. package/modern/BarChart/BarPlot.js +149 -65
  145. package/modern/ChartContainer/index.js +3 -0
  146. package/modern/ChartsAxis/ChartsAxis.js +16 -0
  147. package/modern/ChartsLegend/ChartsLegend.js +10 -6
  148. package/modern/ChartsXAxis/ChartsXAxis.js +122 -34
  149. package/modern/ChartsYAxis/ChartsYAxis.js +36 -14
  150. package/modern/LineChart/AreaElement.js +10 -0
  151. package/modern/LineChart/AreaPlot.js +11 -0
  152. package/modern/LineChart/LineChart.js +34 -0
  153. package/modern/LineChart/LineElement.js +10 -0
  154. package/modern/LineChart/LineHighlightElement.js +10 -0
  155. package/modern/LineChart/LineHighlightPlot.js +10 -0
  156. package/modern/LineChart/LinePlot.js +10 -0
  157. package/modern/LineChart/MarkElement.js +10 -0
  158. package/modern/LineChart/MarkPlot.js +10 -0
  159. package/modern/PieChart/PieChart.js +35 -0
  160. package/modern/PieChart/PiePlot.js +10 -0
  161. package/modern/ResponsiveChartContainer/index.js +2 -2
  162. package/modern/ScatterChart/Scatter.js +10 -0
  163. package/modern/ScatterChart/ScatterChart.js +34 -0
  164. package/modern/ScatterChart/ScatterPlot.js +10 -0
  165. package/modern/SparkLineChart/SparkLineChart.js +14 -0
  166. package/modern/context/CartesianContextProvider.js +8 -0
  167. package/modern/hooks/useMounted.js +16 -0
  168. package/modern/hooks/useReducedMotion.js +27 -0
  169. package/modern/hooks/useTicks.js +12 -6
  170. package/modern/index.js +1 -1
  171. package/modern/internals/components/ChartsText.js +17 -13
  172. package/modern/internals/geometry.js +36 -0
  173. package/package.json +5 -3
@@ -1,12 +1,15 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
1
2
  import _extends from "@babel/runtime/helpers/esm/extends";
2
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ var _excluded = ["skipAnimation"];
3
5
  import * as React from 'react';
4
6
  import PropTypes from 'prop-types';
7
+ import { useTransition } from '@react-spring/web';
5
8
  import { SeriesContext } from '../context/SeriesContextProvider';
6
9
  import { CartesianContext } from '../context/CartesianContextProvider';
7
10
  import { BarElement } from './BarElement';
8
11
  import { isBandScaleConfig } from '../models/axis';
9
-
12
+ import { jsx as _jsx } from "react/jsx-runtime";
10
13
  /**
11
14
  * Solution of the equations
12
15
  * W = barWidth * N + offset * (N-1)
@@ -16,7 +19,6 @@ import { isBandScaleConfig } from '../models/axis';
16
19
  * @param gapRatio The ratio of the gap between bars over the bar width.
17
20
  * @returns The bar width and the offset between bars.
18
21
  */
19
- import { jsx as _jsx } from "react/jsx-runtime";
20
22
  function getBandSize(_ref) {
21
23
  var W = _ref.bandWidth,
22
24
  N = _ref.numberOfGroups,
@@ -34,12 +36,14 @@ function getBandSize(_ref) {
34
36
  offset: offset
35
37
  };
36
38
  }
37
- function BarPlot(props) {
38
- var seriesData = React.useContext(SeriesContext).bar;
39
+ var useCompletedData = function useCompletedData() {
40
+ var _React$useContext$bar;
41
+ var seriesData = (_React$useContext$bar = React.useContext(SeriesContext).bar) != null ? _React$useContext$bar : {
42
+ series: {},
43
+ stackingGroups: [],
44
+ seriesOrder: []
45
+ };
39
46
  var axisData = React.useContext(CartesianContext);
40
- if (seriesData === undefined) {
41
- return null;
42
- }
43
47
  var series = seriesData.series,
44
48
  stackingGroups = seriesData.stackingGroups;
45
49
  var xAxis = axisData.xAxis,
@@ -48,64 +52,143 @@ function BarPlot(props) {
48
52
  yAxisIds = axisData.yAxisIds;
49
53
  var defaultXAxisId = xAxisIds[0];
50
54
  var defaultYAxisId = yAxisIds[0];
51
- return /*#__PURE__*/_jsx(React.Fragment, {
52
- children: stackingGroups.flatMap(function (_ref2, groupIndex) {
53
- var groupIds = _ref2.ids;
54
- return groupIds.flatMap(function (seriesId) {
55
- var _series$seriesId$xAxi, _series$seriesId$yAxi;
56
- var xAxisKey = (_series$seriesId$xAxi = series[seriesId].xAxisKey) != null ? _series$seriesId$xAxi : defaultXAxisId;
57
- var yAxisKey = (_series$seriesId$yAxi = series[seriesId].yAxisKey) != null ? _series$seriesId$yAxi : defaultYAxisId;
58
- var xAxisConfig = xAxis[xAxisKey];
59
- var yAxisConfig = yAxis[yAxisKey];
60
- var verticalLayout = series[seriesId].layout === 'vertical';
61
- var baseScaleConfig;
62
- if (verticalLayout) {
63
- if (!isBandScaleConfig(xAxisConfig)) {
64
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
65
- }
66
- if (xAxis[xAxisKey].data === undefined) {
67
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
68
- }
69
- baseScaleConfig = xAxisConfig;
70
- } else {
71
- if (!isBandScaleConfig(yAxisConfig)) {
72
- throw new Error("Axis with id \"".concat(yAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
73
- }
74
- if (yAxis[yAxisKey].data === undefined) {
75
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
76
- }
77
- baseScaleConfig = yAxisConfig;
55
+ var data = stackingGroups.flatMap(function (_ref2, groupIndex) {
56
+ var groupIds = _ref2.ids;
57
+ return groupIds.flatMap(function (seriesId) {
58
+ var _series$seriesId$xAxi, _series$seriesId$yAxi;
59
+ var xAxisKey = (_series$seriesId$xAxi = series[seriesId].xAxisKey) != null ? _series$seriesId$xAxi : defaultXAxisId;
60
+ var yAxisKey = (_series$seriesId$yAxi = series[seriesId].yAxisKey) != null ? _series$seriesId$yAxi : defaultYAxisId;
61
+ var xAxisConfig = xAxis[xAxisKey];
62
+ var yAxisConfig = yAxis[yAxisKey];
63
+ var verticalLayout = series[seriesId].layout === 'vertical';
64
+ var baseScaleConfig;
65
+ if (verticalLayout) {
66
+ if (!isBandScaleConfig(xAxisConfig)) {
67
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
68
+ }
69
+ if (xAxis[xAxisKey].data === undefined) {
70
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
71
+ }
72
+ baseScaleConfig = xAxisConfig;
73
+ } else {
74
+ if (!isBandScaleConfig(yAxisConfig)) {
75
+ throw new Error("Axis with id \"".concat(yAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
78
76
  }
79
- var xScale = xAxisConfig.scale;
80
- var yScale = yAxisConfig.scale;
81
- var bandWidth = baseScaleConfig.scale.bandwidth();
82
- var _getBandSize = getBandSize({
83
- bandWidth: bandWidth,
84
- numberOfGroups: stackingGroups.length,
85
- gapRatio: baseScaleConfig.barGapRatio
86
- }),
87
- barWidth = _getBandSize.barWidth,
88
- offset = _getBandSize.offset;
89
- var barOffset = groupIndex * (barWidth + offset);
90
- var _series$seriesId = series[seriesId],
91
- stackedData = _series$seriesId.stackedData,
92
- color = _series$seriesId.color;
93
- return stackedData.map(function (values, dataIndex) {
94
- var _xAxis$xAxisKey$data, _yAxis$yAxisKey$data;
95
- var baseline = Math.min.apply(Math, _toConsumableArray(values));
96
- var value = Math.max.apply(Math, _toConsumableArray(values));
97
- return /*#__PURE__*/_jsx(BarElement, _extends({
98
- id: seriesId,
99
- dataIndex: dataIndex,
100
- x: verticalLayout ? xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + barOffset : xScale(baseline),
101
- y: verticalLayout ? yScale(value) : yScale((_yAxis$yAxisKey$data = yAxis[yAxisKey].data) == null ? void 0 : _yAxis$yAxisKey$data[dataIndex]) + barOffset,
102
- height: verticalLayout ? Math.abs(yScale(baseline) - yScale(value)) : barWidth,
103
- width: verticalLayout ? barWidth : Math.abs(xScale(baseline) - xScale(value)),
104
- color: color,
105
- highlightScope: series[seriesId].highlightScope
106
- }, props), "".concat(seriesId, "-").concat(dataIndex));
107
- });
77
+ if (yAxis[yAxisKey].data === undefined) {
78
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
79
+ }
80
+ baseScaleConfig = yAxisConfig;
81
+ }
82
+ var xScale = xAxisConfig.scale;
83
+ var yScale = yAxisConfig.scale;
84
+ var bandWidth = baseScaleConfig.scale.bandwidth();
85
+ var _getBandSize = getBandSize({
86
+ bandWidth: bandWidth,
87
+ numberOfGroups: stackingGroups.length,
88
+ gapRatio: baseScaleConfig.barGapRatio
89
+ }),
90
+ barWidth = _getBandSize.barWidth,
91
+ offset = _getBandSize.offset;
92
+ var barOffset = groupIndex * (barWidth + offset);
93
+ var _series$seriesId = series[seriesId],
94
+ stackedData = _series$seriesId.stackedData,
95
+ color = _series$seriesId.color;
96
+ return stackedData.map(function (values, dataIndex) {
97
+ var _xAxis$xAxisKey$data, _yAxis$yAxisKey$data;
98
+ var bottom = Math.min.apply(Math, _toConsumableArray(values));
99
+ var top = Math.max.apply(Math, _toConsumableArray(values));
100
+ return {
101
+ bottom: bottom,
102
+ top: top,
103
+ seriesId: seriesId,
104
+ dataIndex: dataIndex,
105
+ layout: series[seriesId].layout,
106
+ x: verticalLayout ? xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + barOffset : xScale(bottom),
107
+ y: verticalLayout ? yScale(top) : yScale((_yAxis$yAxisKey$data = yAxis[yAxisKey].data) == null ? void 0 : _yAxis$yAxisKey$data[dataIndex]) + barOffset,
108
+ xOrigin: xScale(0),
109
+ yOrigin: yScale(0),
110
+ height: verticalLayout ? Math.abs(yScale(bottom) - yScale(top)) : barWidth,
111
+ width: verticalLayout ? barWidth : Math.abs(xScale(bottom) - xScale(top)),
112
+ color: color,
113
+ highlightScope: series[seriesId].highlightScope
114
+ };
108
115
  });
116
+ });
117
+ });
118
+ return data;
119
+ };
120
+ var getOutStyle = function getOutStyle(_ref3) {
121
+ var layout = _ref3.layout,
122
+ yOrigin = _ref3.yOrigin,
123
+ x = _ref3.x,
124
+ width = _ref3.width,
125
+ y = _ref3.y,
126
+ xOrigin = _ref3.xOrigin,
127
+ height = _ref3.height;
128
+ return _extends({}, layout === 'vertical' ? {
129
+ y: yOrigin,
130
+ x: x,
131
+ height: 0,
132
+ width: width
133
+ } : {
134
+ y: y,
135
+ x: xOrigin,
136
+ height: height,
137
+ width: 0
138
+ });
139
+ };
140
+ var getInStyle = function getInStyle(_ref4) {
141
+ var x = _ref4.x,
142
+ width = _ref4.width,
143
+ y = _ref4.y,
144
+ height = _ref4.height;
145
+ return {
146
+ y: y,
147
+ x: x,
148
+ height: height,
149
+ width: width
150
+ };
151
+ };
152
+
153
+ /**
154
+ * Demos:
155
+ *
156
+ * - [Bars](https://mui.com/x/react-charts/bars/)
157
+ * - [Bar demonstration](https://mui.com/x/react-charts/bar-demo/)
158
+ * - [Stacking](https://mui.com/x/react-charts/stacking/)
159
+ *
160
+ * API:
161
+ *
162
+ * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
163
+ */
164
+ function BarPlot(props) {
165
+ var completedData = useCompletedData();
166
+ var skipAnimation = props.skipAnimation,
167
+ other = _objectWithoutProperties(props, _excluded);
168
+ var transition = useTransition(completedData, {
169
+ keys: function keys(bar) {
170
+ return "".concat(bar.seriesId, "-").concat(bar.dataIndex);
171
+ },
172
+ from: getOutStyle,
173
+ leave: getOutStyle,
174
+ enter: getInStyle,
175
+ update: getInStyle,
176
+ immediate: skipAnimation
177
+ });
178
+ return /*#__PURE__*/_jsx(React.Fragment, {
179
+ children: transition(function (style, _ref5) {
180
+ var seriesId = _ref5.seriesId,
181
+ dataIndex = _ref5.dataIndex,
182
+ color = _ref5.color,
183
+ highlightScope = _ref5.highlightScope;
184
+ return /*#__PURE__*/_jsx(BarElement, _extends({
185
+ id: seriesId,
186
+ dataIndex: dataIndex,
187
+ highlightScope: highlightScope,
188
+ color: color
189
+ }, other, {
190
+ style: style
191
+ }));
109
192
  })
110
193
  });
111
194
  }
@@ -114,6 +197,11 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
114
197
  // | These PropTypes are generated from the TypeScript type definitions |
115
198
  // | To update them edit the TypeScript types and run "yarn proptypes" |
116
199
  // ----------------------------------------------------------------------
200
+ /**
201
+ * If `true`, animations are skiped.
202
+ * @default false
203
+ */
204
+ skipAnimation: PropTypes.bool,
117
205
  /**
118
206
  * The props used for each component slot.
119
207
  * @default {}
@@ -3,6 +3,7 @@ import useForkRef from '@mui/utils/useForkRef';
3
3
  import { DrawingProvider } from '../context/DrawingProvider';
4
4
  import { SeriesContextProvider } from '../context/SeriesContextProvider';
5
5
  import { InteractionProvider } from '../context/InteractionProvider';
6
+ import { useReducedMotion } from '../hooks/useReducedMotion';
6
7
  import { ChartsSurface } from '../ChartsSurface';
7
8
  import { CartesianContextProvider } from '../context/CartesianContextProvider';
8
9
  import { HighlightProvider } from '../context/HighlightProvider';
@@ -23,6 +24,8 @@ export var ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContaine
23
24
  children = props.children;
24
25
  var svgRef = React.useRef(null);
25
26
  var handleRef = useForkRef(ref, svgRef);
27
+ useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
28
+
26
29
  return /*#__PURE__*/_jsx(DrawingProvider, {
27
30
  width: width,
28
31
  height: height,
@@ -95,11 +95,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
95
95
  fill: PropTypes.string,
96
96
  label: PropTypes.string,
97
97
  labelFontSize: PropTypes.number,
98
+ labelStyle: PropTypes.object,
98
99
  position: PropTypes.oneOf(['bottom', 'top']),
99
100
  slotProps: PropTypes.object,
100
101
  slots: PropTypes.object,
101
102
  stroke: PropTypes.string,
102
103
  tickFontSize: PropTypes.number,
104
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
105
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
106
+ tickLabelStyle: PropTypes.object,
103
107
  tickMaxStep: PropTypes.number,
104
108
  tickMinStep: PropTypes.number,
105
109
  tickNumber: PropTypes.number,
@@ -118,11 +122,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
118
122
  fill: PropTypes.string,
119
123
  label: PropTypes.string,
120
124
  labelFontSize: PropTypes.number,
125
+ labelStyle: PropTypes.object,
121
126
  position: PropTypes.oneOf(['left', 'right']),
122
127
  slotProps: PropTypes.object,
123
128
  slots: PropTypes.object,
124
129
  stroke: PropTypes.string,
125
130
  tickFontSize: PropTypes.number,
131
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
132
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
133
+ tickLabelStyle: PropTypes.object,
126
134
  tickMaxStep: PropTypes.number,
127
135
  tickMinStep: PropTypes.number,
128
136
  tickNumber: PropTypes.number,
@@ -141,11 +149,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
141
149
  fill: PropTypes.string,
142
150
  label: PropTypes.string,
143
151
  labelFontSize: PropTypes.number,
152
+ labelStyle: PropTypes.object,
144
153
  position: PropTypes.oneOf(['left', 'right']),
145
154
  slotProps: PropTypes.object,
146
155
  slots: PropTypes.object,
147
156
  stroke: PropTypes.string,
148
157
  tickFontSize: PropTypes.number,
158
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
159
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
160
+ tickLabelStyle: PropTypes.object,
149
161
  tickMaxStep: PropTypes.number,
150
162
  tickMinStep: PropTypes.number,
151
163
  tickNumber: PropTypes.number,
@@ -174,11 +186,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
174
186
  fill: PropTypes.string,
175
187
  label: PropTypes.string,
176
188
  labelFontSize: PropTypes.number,
189
+ labelStyle: PropTypes.object,
177
190
  position: PropTypes.oneOf(['bottom', 'top']),
178
191
  slotProps: PropTypes.object,
179
192
  slots: PropTypes.object,
180
193
  stroke: PropTypes.string,
181
194
  tickFontSize: PropTypes.number,
195
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
196
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
197
+ tickLabelStyle: PropTypes.object,
182
198
  tickMaxStep: PropTypes.number,
183
199
  tickMinStep: PropTypes.number,
184
200
  tickNumber: PropTypes.number,
@@ -1,7 +1,8 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
- var _excluded = ["label"];
4
+ var _excluded = ["rotate", "dominantBaseline"],
5
+ _excluded2 = ["label"];
5
6
  import * as React from 'react';
6
7
  import { useSlotProps } from '@mui/base/utils';
7
8
  import { NoSsr } from '@mui/base/NoSsr';
@@ -80,14 +81,22 @@ function DefaultChartsLegend(props) {
80
81
  var labelStyle = React.useMemo(function () {
81
82
  return _extends({}, theme.typography.subtitle1, {
82
83
  color: 'inherit',
84
+ dominantBaseline: 'central',
85
+ textAnchor: 'start',
83
86
  fill: (theme.vars || theme).palette.text.primary,
84
87
  lineHeight: 1
85
88
  }, inLabelStyle);
86
- }, [inLabelStyle, theme]);
89
+ },
90
+ // To say to TS that the dominantBaseline and textAnchor are correct
91
+ [inLabelStyle, theme]);
87
92
  var padding = React.useMemo(function () {
88
93
  return getStandardizedPadding(paddingProps);
89
94
  }, [paddingProps]);
90
- var getItemSpace = React.useCallback(function (label, style) {
95
+ var getItemSpace = React.useCallback(function (label) {
96
+ var inStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
97
+ var rotate = inStyle.rotate,
98
+ dominantBaseline = inStyle.dominantBaseline,
99
+ style = _objectWithoutProperties(inStyle, _excluded);
91
100
  var linesSize = getWordsByLines({
92
101
  style: style,
93
102
  needsComputation: true,
@@ -120,7 +129,7 @@ function DefaultChartsLegend(props) {
120
129
  var rowMaxHeight = [0];
121
130
  var seriesWithRawPosition = seriesToDisplay.map(function (_ref) {
122
131
  var label = _ref.label,
123
- other = _objectWithoutProperties(_ref, _excluded);
132
+ other = _objectWithoutProperties(_ref, _excluded2);
124
133
  var itemSpace = getItemSpace(label, labelStyle);
125
134
  var rep = _extends({}, other, {
126
135
  label: label,
@@ -229,8 +238,6 @@ function DefaultChartsLegend(props) {
229
238
  fill: color
230
239
  }), /*#__PURE__*/_jsx(ChartsText, {
231
240
  style: labelStyle,
232
- dominantBaseline: "central",
233
- textAnchor: "start",
234
241
  text: label,
235
242
  x: itemMarkWidth + markGap,
236
243
  y: 0
@@ -1,4 +1,5 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import _extends from "@babel/runtime/helpers/esm/extends";
3
4
  var _excluded = ["scale", "tickNumber"];
4
5
  import * as React from 'react';
@@ -11,7 +12,9 @@ import { DrawingContext } from '../context/DrawingProvider';
11
12
  import useTicks from '../hooks/useTicks';
12
13
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
14
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
- import { ChartsText } from '../internals/components/ChartsText';
15
+ import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
16
+ import { getMinXTranslation } from '../internals/geometry';
17
+ import { useMounted } from '../hooks/useMounted';
15
18
  import { jsx as _jsx } from "react/jsx-runtime";
16
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
20
  var useUtilityClasses = function useUtilityClasses(ownerState) {
@@ -27,12 +30,65 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
27
30
  };
28
31
  return composeClasses(slots, getAxisUtilityClass, classes);
29
32
  };
33
+ function addLabelDimension(xTicks, _ref) {
34
+ var style = _ref.tickLabelStyle,
35
+ tickLabelInterval = _ref.tickLabelInterval,
36
+ isMounted = _ref.isMounted;
37
+ var withDimension = xTicks.map(function (tick) {
38
+ if (!isMounted || tick.formattedValue === undefined) {
39
+ return _extends({}, tick, {
40
+ width: 0,
41
+ height: 0
42
+ });
43
+ }
44
+ var tickSizes = getWordsByLines({
45
+ style: style,
46
+ needsComputation: true,
47
+ text: tick.formattedValue
48
+ });
49
+ return _extends({}, tick, {
50
+ width: Math.max.apply(Math, _toConsumableArray(tickSizes.map(function (size) {
51
+ return size.width;
52
+ }))),
53
+ height: Math.max(tickSizes.length * tickSizes[0].height)
54
+ });
55
+ });
56
+ if (typeof tickLabelInterval === 'function') {
57
+ return withDimension.map(function (item, index) {
58
+ return _extends({}, item, {
59
+ skipLabel: !tickLabelInterval(item.value, index)
60
+ });
61
+ });
62
+ }
63
+
64
+ // Filter label to avoid overlap
65
+ var textStart = 0;
66
+ var textEnd = 0;
67
+ return withDimension.map(function (item, labelIndex) {
68
+ var width = item.width,
69
+ offset = item.offset,
70
+ labelOffset = item.labelOffset,
71
+ height = item.height;
72
+ var distance = getMinXTranslation(width, height, style == null ? void 0 : style.angle);
73
+ var textPosition = offset + labelOffset;
74
+ var gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
75
+
76
+ textStart = textPosition - gapRatio * distance / 2;
77
+ if (labelIndex > 0 && textStart < textEnd) {
78
+ // Except for the first label, we skip all label that overlap with the last accepted.
79
+ // Notice that the early return prevents `textEnd` from being updated.
80
+ return _extends({}, item, {
81
+ skipLabel: true
82
+ });
83
+ }
84
+ textEnd = textPosition + gapRatio * distance / 2;
85
+ return item;
86
+ });
87
+ }
30
88
  var defaultProps = {
31
89
  position: 'bottom',
32
90
  disableLine: false,
33
91
  disableTicks: false,
34
- tickFontSize: 12,
35
- labelFontSize: 14,
36
92
  tickSize: 6
37
93
  };
38
94
  function ChartsXAxis(inProps) {
@@ -46,17 +102,22 @@ function ChartsXAxis(inProps) {
46
102
  xScale = _React$useContext$xAx.scale,
47
103
  tickNumber = _React$useContext$xAx.tickNumber,
48
104
  settings = _objectWithoutProperties(_React$useContext$xAx, _excluded);
105
+ var isMounted = useMounted();
49
106
  var defaultizedProps = _extends({}, defaultProps, settings, props);
50
107
  var position = defaultizedProps.position,
51
108
  disableLine = defaultizedProps.disableLine,
52
109
  disableTicks = defaultizedProps.disableTicks,
53
- tickFontSize = defaultizedProps.tickFontSize,
110
+ tickLabelStyle = defaultizedProps.tickLabelStyle,
54
111
  label = defaultizedProps.label,
112
+ labelStyle = defaultizedProps.labelStyle,
113
+ tickFontSize = defaultizedProps.tickFontSize,
55
114
  labelFontSize = defaultizedProps.labelFontSize,
56
115
  tickSizeProp = defaultizedProps.tickSize,
57
116
  valueFormatter = defaultizedProps.valueFormatter,
58
117
  slots = defaultizedProps.slots,
59
- slotProps = defaultizedProps.slotProps;
118
+ slotProps = defaultizedProps.slotProps,
119
+ tickInterval = defaultizedProps.tickInterval,
120
+ tickLabelInterval = defaultizedProps.tickLabelInterval;
60
121
  var theme = useTheme();
61
122
  var classes = useUtilityClasses(_extends({}, defaultizedProps, {
62
123
  theme: theme
@@ -67,16 +128,7 @@ function ChartsXAxis(inProps) {
67
128
  width = _React$useContext2.width,
68
129
  height = _React$useContext2.height;
69
130
  var tickSize = disableTicks ? 4 : tickSizeProp;
70
- var xTicks = useTicks({
71
- scale: xScale,
72
- tickNumber: tickNumber,
73
- valueFormatter: valueFormatter
74
- });
75
- var positionSigne = position === 'bottom' ? 1 : -1;
76
- var labelRefPoint = {
77
- x: left + width / 2,
78
- y: positionSigne * (tickFontSize + tickSize + 10)
79
- };
131
+ var positionSign = position === 'bottom' ? 1 : -1;
80
132
  var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
81
133
  var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
82
134
  var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
@@ -85,27 +137,40 @@ function ChartsXAxis(inProps) {
85
137
  elementType: TickLabel,
86
138
  externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
87
139
  additionalProps: {
88
- textAnchor: 'middle',
89
- dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
90
- style: {
91
- fontSize: tickFontSize
92
- },
140
+ style: _extends({
141
+ textAnchor: 'middle',
142
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
143
+ fontSize: tickFontSize != null ? tickFontSize : 12
144
+ }, tickLabelStyle),
93
145
  className: classes.tickLabel
94
146
  },
95
147
  className: classes.tickLabel,
96
148
  ownerState: {}
97
149
  });
150
+ var xTicks = useTicks({
151
+ scale: xScale,
152
+ tickNumber: tickNumber,
153
+ valueFormatter: valueFormatter,
154
+ tickInterval: tickInterval
155
+ });
156
+ var xTicksWithDimension = addLabelDimension(xTicks, {
157
+ tickLabelStyle: axisTickLabelProps.style,
158
+ tickLabelInterval: tickLabelInterval,
159
+ isMounted: isMounted
160
+ });
161
+ var labelRefPoint = {
162
+ x: left + width / 2,
163
+ y: positionSign * (tickSize + 22)
164
+ };
98
165
  var axisLabelProps = useSlotProps({
99
166
  elementType: Label,
100
167
  externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
101
168
  additionalProps: {
102
- textAnchor: 'middle',
103
- dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
104
- style: {
105
- fontSize: labelFontSize,
106
- transformOrigin: "".concat(labelRefPoint.x, "px ").concat(labelRefPoint.y, "px")
107
- },
108
- className: classes.label
169
+ style: _extends({
170
+ fontSize: labelFontSize != null ? labelFontSize : 14,
171
+ textAnchor: 'middle',
172
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
173
+ }, labelStyle)
109
174
  },
110
175
  ownerState: {}
111
176
  });
@@ -116,22 +181,22 @@ function ChartsXAxis(inProps) {
116
181
  x1: xScale.range()[0],
117
182
  x2: xScale.range()[1],
118
183
  className: classes.line
119
- }, slotProps == null ? void 0 : slotProps.axisLine)), xTicks.map(function (_ref, index) {
120
- var formattedValue = _ref.formattedValue,
121
- offset = _ref.offset,
122
- labelOffset = _ref.labelOffset;
184
+ }, slotProps == null ? void 0 : slotProps.axisLine)), xTicksWithDimension.map(function (_ref2, index) {
185
+ var formattedValue = _ref2.formattedValue,
186
+ offset = _ref2.offset,
187
+ labelOffset = _ref2.labelOffset,
188
+ skipLabel = _ref2.skipLabel;
123
189
  var xTickLabel = labelOffset != null ? labelOffset : 0;
124
- var yTickLabel = positionSigne * (tickSize + 3);
190
+ var yTickLabel = positionSign * (tickSize + 3);
125
191
  return /*#__PURE__*/_jsxs("g", {
126
192
  transform: "translate(".concat(offset, ", 0)"),
127
193
  className: classes.tickContainer,
128
194
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
129
- y2: positionSigne * tickSize,
195
+ y2: positionSign * tickSize,
130
196
  className: classes.tick
131
- }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
197
+ }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
132
198
  x: xTickLabel,
133
- y: yTickLabel,
134
- "transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px")
199
+ y: yTickLabel
135
200
  }, axisTickLabelProps, {
136
201
  text: formattedValue.toString()
137
202
  }))]
@@ -179,8 +244,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
179
244
  /**
180
245
  * The font size of the axis label.
181
246
  * @default 14
247
+ * @deprecated Consider using `labelStyle.fontSize` instead.
182
248
  */
183
249
  labelFontSize: PropTypes.number,
250
+ /**
251
+ * The style applied to the axis label.
252
+ */
253
+ labelStyle: PropTypes.object,
184
254
  /**
185
255
  * Position of the axis.
186
256
  */
@@ -203,8 +273,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
203
273
  /**
204
274
  * The font size of the axis ticks text.
205
275
  * @default 12
276
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
206
277
  */
207
278
  tickFontSize: PropTypes.number,
279
+ /**
280
+ * Defines which ticks are displayed. Its value can be:
281
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
282
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
283
+ * - an array containing the values where ticks should be displayed.
284
+ * @default 'auto'
285
+ */
286
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
287
+ /**
288
+ * Defines which ticks get its label displayed. Its value can be:
289
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
290
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
291
+ * @default 'auto'
292
+ */
293
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
294
+ /**
295
+ * The style applied to ticks text.
296
+ */
297
+ tickLabelStyle: PropTypes.object,
208
298
  /**
209
299
  * Maximal step between two ticks.
210
300
  * When using time data, the value is assumed to be in ms.