@mui/x-charts 6.18.0 → 6.18.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 (118) hide show
  1. package/BarChart/BarChart.d.ts +7 -0
  2. package/BarChart/BarChart.js +41 -4
  3. package/CHANGELOG.md +63 -5
  4. package/ChartsAxis/ChartsAxis.js +5 -5
  5. package/ChartsAxis/axisClasses.d.ts +2 -2
  6. package/ChartsLegend/ChartsLegend.d.ts +1 -0
  7. package/ChartsLegend/ChartsLegend.js +1 -1
  8. package/ChartsLegend/chartsLegendClasses.d.ts +1 -1
  9. package/ChartsLegend/chartsLegendClasses.js +2 -2
  10. package/ChartsReferenceLine/ChartsReferenceLine.d.ts +10 -0
  11. package/ChartsReferenceLine/ChartsReferenceLine.js +78 -0
  12. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +13 -0
  13. package/ChartsReferenceLine/ChartsXReferenceLine.js +112 -0
  14. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +13 -0
  15. package/ChartsReferenceLine/ChartsYReferenceLine.js +112 -0
  16. package/ChartsReferenceLine/chartsReferenceLineClasses.d.ts +15 -0
  17. package/ChartsReferenceLine/chartsReferenceLineClasses.js +14 -0
  18. package/ChartsReferenceLine/common.d.ts +41 -0
  19. package/ChartsReferenceLine/common.js +27 -0
  20. package/ChartsReferenceLine/index.d.ts +2 -0
  21. package/ChartsReferenceLine/index.js +27 -0
  22. package/ChartsReferenceLine/package.json +6 -0
  23. package/ChartsSurface.d.ts +11 -0
  24. package/ChartsXAxis/ChartsXAxis.js +9 -5
  25. package/ChartsYAxis/ChartsYAxis.js +9 -5
  26. package/LineChart/LineChart.d.ts +7 -0
  27. package/LineChart/LineChart.js +41 -4
  28. package/LineChart/LineHighlightPlot.js +1 -1
  29. package/LineChart/MarkPlot.js +2 -1
  30. package/PieChart/PieChart.js +34 -4
  31. package/ResponsiveChartContainer/index.d.ts +13 -3
  32. package/ScatterChart/ScatterChart.js +34 -4
  33. package/SparkLineChart/SparkLineChart.js +22 -0
  34. package/context/CartesianContextProvider.d.ts +21 -1
  35. package/context/CartesianContextProvider.js +11 -0
  36. package/context/DrawingProvider.d.ts +18 -0
  37. package/context/DrawingProvider.js +6 -0
  38. package/context/HighlightProvider.d.ts +17 -0
  39. package/context/InteractionProvider.d.ts +6 -0
  40. package/context/SeriesContextProvider.d.ts +5 -0
  41. package/esm/BarChart/BarChart.js +41 -4
  42. package/esm/ChartsAxis/ChartsAxis.js +6 -5
  43. package/esm/ChartsLegend/ChartsLegend.js +2 -2
  44. package/esm/ChartsLegend/chartsLegendClasses.js +1 -1
  45. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
  46. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
  47. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
  48. package/esm/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
  49. package/esm/ChartsReferenceLine/common.js +20 -0
  50. package/esm/ChartsReferenceLine/index.js +2 -0
  51. package/esm/ChartsXAxis/ChartsXAxis.js +10 -6
  52. package/esm/ChartsYAxis/ChartsYAxis.js +10 -6
  53. package/esm/LineChart/LineChart.js +41 -4
  54. package/esm/LineChart/LineHighlightPlot.js +1 -1
  55. package/esm/LineChart/MarkPlot.js +2 -1
  56. package/esm/PieChart/PieChart.js +34 -4
  57. package/esm/ScatterChart/ScatterChart.js +34 -4
  58. package/esm/SparkLineChart/SparkLineChart.js +22 -0
  59. package/esm/context/CartesianContextProvider.js +11 -0
  60. package/esm/context/DrawingProvider.js +6 -0
  61. package/esm/index.js +1 -0
  62. package/esm/internals/geometry.js +2 -2
  63. package/hooks/useScale.d.ts +2 -2
  64. package/index.d.ts +1 -0
  65. package/index.js +12 -1
  66. package/internals/components/ChartsText.d.ts +1 -1
  67. package/internals/geometry.d.ts +2 -2
  68. package/internals/geometry.js +2 -2
  69. package/internals/isBandScale.d.ts +3 -1
  70. package/internals/utils.d.ts +5 -0
  71. package/legacy/BarChart/BarChart.js +41 -4
  72. package/legacy/ChartsAxis/ChartsAxis.js +6 -5
  73. package/legacy/ChartsLegend/ChartsLegend.js +2 -2
  74. package/legacy/ChartsLegend/chartsLegendClasses.js +1 -1
  75. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
  76. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
  77. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
  78. package/legacy/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
  79. package/legacy/ChartsReferenceLine/common.js +20 -0
  80. package/legacy/ChartsReferenceLine/index.js +2 -0
  81. package/legacy/ChartsXAxis/ChartsXAxis.js +15 -12
  82. package/legacy/ChartsYAxis/ChartsYAxis.js +15 -12
  83. package/legacy/LineChart/LineChart.js +41 -4
  84. package/legacy/LineChart/LineHighlightPlot.js +1 -1
  85. package/legacy/LineChart/MarkPlot.js +2 -1
  86. package/legacy/PieChart/PieChart.js +34 -4
  87. package/legacy/ScatterChart/ScatterChart.js +34 -4
  88. package/legacy/SparkLineChart/SparkLineChart.js +22 -0
  89. package/legacy/context/CartesianContextProvider.js +11 -0
  90. package/legacy/context/DrawingProvider.js +6 -0
  91. package/legacy/index.js +2 -1
  92. package/legacy/internals/geometry.js +2 -2
  93. package/models/axis.d.ts +33 -13
  94. package/models/layout.d.ts +6 -0
  95. package/models/seriesType/common.d.ts +16 -0
  96. package/modern/BarChart/BarChart.js +41 -4
  97. package/modern/ChartsAxis/ChartsAxis.js +5 -5
  98. package/modern/ChartsLegend/ChartsLegend.js +2 -2
  99. package/modern/ChartsLegend/chartsLegendClasses.js +1 -1
  100. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
  101. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +104 -0
  102. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +104 -0
  103. package/modern/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
  104. package/modern/ChartsReferenceLine/common.js +20 -0
  105. package/modern/ChartsReferenceLine/index.js +2 -0
  106. package/modern/ChartsXAxis/ChartsXAxis.js +9 -5
  107. package/modern/ChartsYAxis/ChartsYAxis.js +9 -5
  108. package/modern/LineChart/LineChart.js +41 -4
  109. package/modern/LineChart/LineHighlightPlot.js +1 -1
  110. package/modern/LineChart/MarkPlot.js +2 -1
  111. package/modern/PieChart/PieChart.js +34 -4
  112. package/modern/ScatterChart/ScatterChart.js +34 -4
  113. package/modern/SparkLineChart/SparkLineChart.js +22 -0
  114. package/modern/context/CartesianContextProvider.js +11 -0
  115. package/modern/context/DrawingProvider.js +6 -0
  116. package/modern/index.js +2 -1
  117. package/modern/internals/geometry.js +2 -2
  118. package/package.json +1 -1
@@ -119,6 +119,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
119
119
  // | These PropTypes are generated from the TypeScript type definitions |
120
120
  // | To update them edit the TypeScript types and run "yarn proptypes" |
121
121
  // ----------------------------------------------------------------------
122
+ /**
123
+ * Object `{ x, y }` that defines how the charts highlight the mouse position along the x- and y-axes.
124
+ * The two properties accept the following values:
125
+ * - 'none': display nothing.
126
+ * - 'line': display a line at the current mouse position.
127
+ * - 'band': display a band at the current mouse position. Only available with band scale.
128
+ */
122
129
  axisHighlight: PropTypes.shape({
123
130
  x: PropTypes.oneOf(['band', 'line', 'none']),
124
131
  y: PropTypes.oneOf(['band', 'line', 'none'])
@@ -129,7 +136,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
129
136
  * @default xAxisIds[0] The id of the first provided axis
130
137
  */
131
138
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
132
- axisId: PropTypes.string.isRequired,
139
+ axisId: PropTypes.string,
133
140
  classes: PropTypes.object,
134
141
  disableLine: PropTypes.bool,
135
142
  disableTicks: PropTypes.bool,
@@ -156,9 +163,21 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
156
163
  * Color palette used to colorize multiple series.
157
164
  */
158
165
  colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
166
+ /**
167
+ * An array of objects that can be used to populate series and axes data using their `dataKey` property.
168
+ */
159
169
  dataset: PropTypes.arrayOf(PropTypes.object),
160
170
  desc: PropTypes.string,
171
+ /**
172
+ * If `true`, the charts will not listen to the mouse move event.
173
+ * It might break interactive features, but will improve performance.
174
+ * @default false
175
+ */
161
176
  disableAxisListener: PropTypes.bool,
177
+ /**
178
+ * The height of the chart in px. If not defined, it takes the height of the parent element.
179
+ * @default undefined
180
+ */
162
181
  height: PropTypes.number,
163
182
  layout: PropTypes.oneOf(['horizontal', 'vertical']),
164
183
  /**
@@ -167,7 +186,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
167
186
  * @default yAxisIds[0] The id of the first provided axis
168
187
  */
169
188
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
170
- axisId: PropTypes.string.isRequired,
189
+ axisId: PropTypes.string,
171
190
  classes: PropTypes.object,
172
191
  disableLine: PropTypes.bool,
173
192
  disableTicks: PropTypes.bool,
@@ -202,6 +221,12 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
202
221
  slotProps: PropTypes.object,
203
222
  slots: PropTypes.object
204
223
  }),
224
+ /**
225
+ * The margin between the SVG and the drawing area.
226
+ * It's used for leaving some space for extra information such as the x- and y-axis or legend.
227
+ * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
228
+ * @default object Depends on the charts type.
229
+ */
205
230
  margin: PropTypes.shape({
206
231
  bottom: PropTypes.number,
207
232
  left: PropTypes.number,
@@ -214,7 +239,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
214
239
  * @default null
215
240
  */
216
241
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
217
- axisId: PropTypes.string.isRequired,
242
+ axisId: PropTypes.string,
218
243
  classes: PropTypes.object,
219
244
  disableLine: PropTypes.bool,
220
245
  disableTicks: PropTypes.bool,
@@ -285,7 +310,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
285
310
  * @default null
286
311
  */
287
312
  topAxis: PropTypes.oneOfType([PropTypes.shape({
288
- axisId: PropTypes.string.isRequired,
313
+ axisId: PropTypes.string,
289
314
  classes: PropTypes.object,
290
315
  disableLine: PropTypes.bool,
291
316
  disableTicks: PropTypes.bool,
@@ -312,7 +337,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
312
337
  x: PropTypes.number,
313
338
  y: PropTypes.number
314
339
  }),
340
+ /**
341
+ * The width of the chart in px. If not defined, it takes the width of the parent element.
342
+ * @default undefined
343
+ */
315
344
  width: PropTypes.number,
345
+ /**
346
+ * The configuration of the x-axes.
347
+ * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
348
+ */
316
349
  xAxis: PropTypes.arrayOf(PropTypes.shape({
317
350
  axisId: PropTypes.string,
318
351
  classes: PropTypes.object,
@@ -343,6 +376,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
343
376
  tickSize: PropTypes.number,
344
377
  valueFormatter: PropTypes.func
345
378
  })),
379
+ /**
380
+ * The configuration of the y-axes.
381
+ * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
382
+ */
346
383
  yAxis: PropTypes.arrayOf(PropTypes.shape({
347
384
  axisId: PropTypes.string,
348
385
  classes: PropTypes.object,
@@ -12,7 +12,8 @@ var getAxisId = function getAxisId(propsValue) {
12
12
  return null;
13
13
  }
14
14
  if (_typeof(propsValue) === 'object') {
15
- return propsValue.axisId;
15
+ var _propsValue$axisId;
16
+ return (_propsValue$axisId = propsValue.axisId) != null ? _propsValue$axisId : null;
16
17
  }
17
18
  return propsValue;
18
19
  };
@@ -98,7 +99,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
98
99
  * @default xAxisIds[0] The id of the first provided axis
99
100
  */
100
101
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
101
- axisId: PropTypes.string.isRequired,
102
+ axisId: PropTypes.string,
102
103
  classes: PropTypes.object,
103
104
  disableLine: PropTypes.bool,
104
105
  disableTicks: PropTypes.bool,
@@ -125,7 +126,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
125
126
  * @default yAxisIds[0] The id of the first provided axis
126
127
  */
127
128
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
128
- axisId: PropTypes.string.isRequired,
129
+ axisId: PropTypes.string,
129
130
  classes: PropTypes.object,
130
131
  disableLine: PropTypes.bool,
131
132
  disableTicks: PropTypes.bool,
@@ -152,7 +153,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
152
153
  * @default null
153
154
  */
154
155
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
155
- axisId: PropTypes.string.isRequired,
156
+ axisId: PropTypes.string,
156
157
  classes: PropTypes.object,
157
158
  disableLine: PropTypes.bool,
158
159
  disableTicks: PropTypes.bool,
@@ -189,7 +190,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
189
190
  * @default null
190
191
  */
191
192
  topAxis: PropTypes.oneOfType([PropTypes.shape({
192
- axisId: PropTypes.string.isRequired,
193
+ axisId: PropTypes.string,
193
194
  classes: PropTypes.object,
194
195
  disableLine: PropTypes.bool,
195
196
  disableTicks: PropTypes.bool,
@@ -11,7 +11,7 @@ import { useThemeProps, useTheme, styled } from '@mui/material/styles';
11
11
  import { DrawingContext } from '../context/DrawingProvider';
12
12
  import { getSeriesToDisplay } from './utils';
13
13
  import { SeriesContext } from '../context/SeriesContextProvider';
14
- import { getChartsLegendUtilityClass } from './chartsLegendClasses';
14
+ import { getLegendUtilityClass } from './chartsLegendClasses';
15
15
  import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
16
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -24,7 +24,7 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
24
24
  label: ['label'],
25
25
  series: ['series']
26
26
  };
27
- return composeClasses(slots, getChartsLegendUtilityClass, classes);
27
+ return composeClasses(slots, getLegendUtilityClass, classes);
28
28
  };
29
29
  export var ChartsLegendRoot = styled('g', {
30
30
  name: 'MuiChartsLegend',
@@ -1,5 +1,5 @@
1
1
  import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
2
- export function getChartsLegendUtilityClass(slot) {
2
+ export function getLegendUtilityClass(slot) {
3
3
  return generateUtilityClass('MuiChartsLegend', slot);
4
4
  }
5
5
  export var legendClasses = generateUtilityClasses('MuiChartsLegend', ['root', 'series', 'mark', 'label', 'column', 'row']);
@@ -0,0 +1,70 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { ChartsXReferenceLine } from './ChartsXReferenceLine';
5
+ import { ChartsYReferenceLine } from './ChartsYReferenceLine';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ function ChartsReferenceLine(props) {
8
+ if (props.x !== undefined && props.y !== undefined) {
9
+ throw new Error('MUI-X: The ChartsReferenceLine can not have both `x` and `y` props set.');
10
+ }
11
+ if (props.x === undefined && props.y === undefined) {
12
+ throw new Error('MUI-X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
13
+ }
14
+ if (props.x !== undefined) {
15
+ return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
16
+ }
17
+ return /*#__PURE__*/_jsx(ChartsYReferenceLine, _extends({}, props));
18
+ }
19
+ process.env.NODE_ENV !== "production" ? ChartsReferenceLine.propTypes = {
20
+ // ----------------------------- Warning --------------------------------
21
+ // | These PropTypes are generated from the TypeScript type definitions |
22
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
23
+ // ----------------------------------------------------------------------
24
+ /**
25
+ * The id of the axis used for the reference value.
26
+ * @default The `id` of the first defined axis.
27
+ */
28
+ axisId: PropTypes.string,
29
+ /**
30
+ * Override or extend the styles applied to the component.
31
+ */
32
+ classes: PropTypes.object,
33
+ /**
34
+ * The label to display along the reference line.
35
+ */
36
+ label: PropTypes.string,
37
+ /**
38
+ * The alignment if the label is in the chart drawing area.
39
+ * @default 'middle'
40
+ */
41
+ labelAlign: PropTypes.oneOf(['end', 'middle', 'start']),
42
+ /**
43
+ * The style applied to the label.
44
+ */
45
+ labelStyle: PropTypes.object,
46
+ /**
47
+ * The style applied to the line.
48
+ */
49
+ lineStyle: PropTypes.object,
50
+ /**
51
+ * Additional space arround the label in px.
52
+ * Can be a number or an object `{ x, y }` to distinguish space with the reference line and space with axes.
53
+ * @default 5
54
+ */
55
+ spacing: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
56
+ x: PropTypes.number,
57
+ y: PropTypes.number
58
+ })]),
59
+ /**
60
+ * The x value associated with the reference line.
61
+ * If defined the reference line will be vertical.
62
+ */
63
+ x: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
64
+ /**
65
+ * The y value associated with the reference line.
66
+ * If defined the reference line will be horizontal.
67
+ */
68
+ y: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string])
69
+ } : void 0;
70
+ export { ChartsReferenceLine };
@@ -0,0 +1,105 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import * as React from 'react';
4
+ import composeClasses from '@mui/utils/composeClasses';
5
+ import { useDrawingArea, useXScale } from '../hooks';
6
+ import { ReferenceLineRoot } from './common';
7
+ import { ChartsText } from '../internals/components/ChartsText';
8
+ import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ var getTextParams = function getTextParams(_ref) {
12
+ var top = _ref.top,
13
+ height = _ref.height,
14
+ spacingY = _ref.spacingY,
15
+ _ref$labelAlign = _ref.labelAlign,
16
+ labelAlign = _ref$labelAlign === void 0 ? 'middle' : _ref$labelAlign;
17
+ switch (labelAlign) {
18
+ case 'start':
19
+ return {
20
+ y: top + spacingY,
21
+ style: {
22
+ dominantBaseline: 'hanging',
23
+ textAnchor: 'start'
24
+ }
25
+ };
26
+ case 'end':
27
+ return {
28
+ y: top + height - spacingY,
29
+ style: {
30
+ dominantBaseline: 'auto',
31
+ textAnchor: 'start'
32
+ }
33
+ };
34
+ default:
35
+ return {
36
+ y: top + height / 2,
37
+ style: {
38
+ dominantBaseline: 'central',
39
+ textAnchor: 'start'
40
+ }
41
+ };
42
+ }
43
+ };
44
+ export function getXReferenceLineClasses(classes) {
45
+ return composeClasses({
46
+ root: ['root', 'vertical'],
47
+ line: ['line'],
48
+ label: ['label']
49
+ }, getReferenceLineUtilityClass, classes);
50
+ }
51
+ var warnedOnce = false;
52
+ function ChartsXReferenceLine(props) {
53
+ var _spacing$x, _spacing$y;
54
+ var x = props.x,
55
+ _props$label = props.label,
56
+ label = _props$label === void 0 ? '' : _props$label,
57
+ _props$spacing = props.spacing,
58
+ spacing = _props$spacing === void 0 ? 5 : _props$spacing,
59
+ inClasses = props.classes,
60
+ labelAlign = props.labelAlign,
61
+ lineStyle = props.lineStyle,
62
+ labelStyle = props.labelStyle,
63
+ axisId = props.axisId;
64
+ var _useDrawingArea = useDrawingArea(),
65
+ top = _useDrawingArea.top,
66
+ height = _useDrawingArea.height;
67
+ var xAxisScale = useXScale(axisId);
68
+ var xPosition = xAxisScale(x);
69
+ if (xPosition === undefined) {
70
+ if (process.env.NODE_ENV !== 'production') {
71
+ if (!warnedOnce) {
72
+ warnedOnce = true;
73
+ console.error("MUI X: the value ".concat(x, " does not exist in the data of x axis with id ").concat(axisId, "."));
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+ var d = "M ".concat(xPosition, " ").concat(top, " l 0 ").concat(height);
79
+ var classes = getXReferenceLineClasses(inClasses);
80
+ var spacingX = _typeof(spacing) === 'object' ? (_spacing$x = spacing.x) != null ? _spacing$x : 0 : spacing;
81
+ var spacingY = _typeof(spacing) === 'object' ? (_spacing$y = spacing.y) != null ? _spacing$y : 0 : spacing;
82
+ var textParams = _extends({
83
+ x: xPosition + spacingX,
84
+ text: label,
85
+ fontSize: 12
86
+ }, getTextParams({
87
+ top: top,
88
+ height: height,
89
+ spacingY: spacingY,
90
+ labelAlign: labelAlign
91
+ }), {
92
+ className: classes.label
93
+ });
94
+ return /*#__PURE__*/_jsxs(ReferenceLineRoot, {
95
+ className: classes.root,
96
+ children: [/*#__PURE__*/_jsx("path", {
97
+ d: d,
98
+ className: classes.line,
99
+ style: lineStyle
100
+ }), /*#__PURE__*/_jsx(ChartsText, _extends({}, textParams, {
101
+ style: _extends({}, textParams.style, labelStyle)
102
+ }))]
103
+ });
104
+ }
105
+ export { ChartsXReferenceLine };
@@ -0,0 +1,105 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import * as React from 'react';
4
+ import composeClasses from '@mui/utils/composeClasses';
5
+ import { useDrawingArea, useYScale } from '../hooks';
6
+ import { ReferenceLineRoot } from './common';
7
+ import { ChartsText } from '../internals/components/ChartsText';
8
+ import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ var getTextParams = function getTextParams(_ref) {
12
+ var left = _ref.left,
13
+ width = _ref.width,
14
+ spacingX = _ref.spacingX,
15
+ _ref$labelAlign = _ref.labelAlign,
16
+ labelAlign = _ref$labelAlign === void 0 ? 'middle' : _ref$labelAlign;
17
+ switch (labelAlign) {
18
+ case 'start':
19
+ return {
20
+ x: left + spacingX,
21
+ style: {
22
+ dominantBaseline: 'auto',
23
+ textAnchor: 'start'
24
+ }
25
+ };
26
+ case 'end':
27
+ return {
28
+ x: left + width - spacingX,
29
+ style: {
30
+ dominantBaseline: 'auto',
31
+ textAnchor: 'end'
32
+ }
33
+ };
34
+ default:
35
+ return {
36
+ x: left + width / 2,
37
+ style: {
38
+ dominantBaseline: 'auto',
39
+ textAnchor: 'middle'
40
+ }
41
+ };
42
+ }
43
+ };
44
+ var warnedOnce = false;
45
+ export function getYReferenceLineClasses(classes) {
46
+ return composeClasses({
47
+ root: ['root', 'horizontal'],
48
+ line: ['line'],
49
+ label: ['label']
50
+ }, getReferenceLineUtilityClass, classes);
51
+ }
52
+ function ChartsYReferenceLine(props) {
53
+ var _spacing$x, _spacing$y;
54
+ var y = props.y,
55
+ _props$label = props.label,
56
+ label = _props$label === void 0 ? '' : _props$label,
57
+ _props$spacing = props.spacing,
58
+ spacing = _props$spacing === void 0 ? 5 : _props$spacing,
59
+ inClasses = props.classes,
60
+ labelAlign = props.labelAlign,
61
+ lineStyle = props.lineStyle,
62
+ labelStyle = props.labelStyle,
63
+ axisId = props.axisId;
64
+ var _useDrawingArea = useDrawingArea(),
65
+ left = _useDrawingArea.left,
66
+ width = _useDrawingArea.width;
67
+ var yAxisScale = useYScale(axisId);
68
+ var yPosition = yAxisScale(y);
69
+ if (yPosition === undefined) {
70
+ if (process.env.NODE_ENV !== 'production') {
71
+ if (!warnedOnce) {
72
+ warnedOnce = true;
73
+ console.error("MUI X: the value ".concat(y, " does not exist in the data of y axis with id ").concat(axisId, "."));
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+ var d = "M ".concat(left, " ").concat(yPosition, " l ").concat(width, " 0");
79
+ var classes = getYReferenceLineClasses(inClasses);
80
+ var spacingX = _typeof(spacing) === 'object' ? (_spacing$x = spacing.x) != null ? _spacing$x : 0 : spacing;
81
+ var spacingY = _typeof(spacing) === 'object' ? (_spacing$y = spacing.y) != null ? _spacing$y : 0 : spacing;
82
+ var textParams = _extends({
83
+ y: yPosition - spacingY,
84
+ text: label,
85
+ fontSize: 12
86
+ }, getTextParams({
87
+ left: left,
88
+ width: width,
89
+ spacingX: spacingX,
90
+ labelAlign: labelAlign
91
+ }), {
92
+ className: classes.label
93
+ });
94
+ return /*#__PURE__*/_jsxs(ReferenceLineRoot, {
95
+ className: classes.root,
96
+ children: [/*#__PURE__*/_jsx("path", {
97
+ d: d,
98
+ className: classes.line,
99
+ style: lineStyle
100
+ }), /*#__PURE__*/_jsx(ChartsText, _extends({}, textParams, {
101
+ style: _extends({}, textParams.style, labelStyle)
102
+ }))]
103
+ });
104
+ }
105
+ export { ChartsYReferenceLine };
@@ -0,0 +1,6 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
+ export function getReferenceLineUtilityClass(slot) {
4
+ return generateUtilityClass('MuiChartsReferenceLine', slot);
5
+ }
6
+ export var referenceLineClasses = generateUtilityClasses('MuiChartsReferenceLine', ['root', 'vertical', 'horizontal', 'line', 'label']);
@@ -0,0 +1,20 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import { styled } from '@mui/material/styles';
4
+ import { referenceLineClasses } from './chartsReferenceLineClasses';
5
+ export var ReferenceLineRoot = styled('g')(function (_ref) {
6
+ var _ref2;
7
+ var theme = _ref.theme;
8
+ return _ref2 = {}, _defineProperty(_ref2, "& .".concat(referenceLineClasses.line), {
9
+ fill: 'none',
10
+ stroke: (theme.vars || theme).palette.text.primary,
11
+ shapeRendering: 'crispEdges',
12
+ strokeWidth: 1,
13
+ pointerEvents: 'none'
14
+ }), _defineProperty(_ref2, "& .".concat(referenceLineClasses.label), _extends({
15
+ fill: (theme.vars || theme).palette.text.primary,
16
+ stroke: 'none',
17
+ pointerEvents: 'none',
18
+ fontSize: 12
19
+ }, theme.typography.body1)), _ref2;
20
+ });
@@ -0,0 +1,2 @@
1
+ export * from './ChartsReferenceLine';
2
+ export * from './chartsReferenceLineClasses';
@@ -102,16 +102,18 @@ var defaultProps = {
102
102
  * - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
103
103
  */
104
104
  function ChartsXAxis(inProps) {
105
- var _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
105
+ var _props$axisId, _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
106
106
  var props = useThemeProps({
107
107
  props: _extends({}, defaultProps, inProps),
108
108
  name: 'MuiChartsXAxis'
109
109
  });
110
110
  var _React$useContext = React.useContext(CartesianContext),
111
- _React$useContext$xAx = _React$useContext.xAxis[props.axisId],
112
- xScale = _React$useContext$xAx.scale,
113
- tickNumber = _React$useContext$xAx.tickNumber,
114
- settings = _objectWithoutProperties(_React$useContext$xAx, _excluded);
111
+ xAxisIds = _React$useContext.xAxisIds;
112
+ var _React$useContext2 = React.useContext(CartesianContext),
113
+ _React$useContext2$xA = _React$useContext2.xAxis[(_props$axisId = props.axisId) != null ? _props$axisId : xAxisIds[0]],
114
+ xScale = _React$useContext2$xA.scale,
115
+ tickNumber = _React$useContext2$xA.tickNumber,
116
+ settings = _objectWithoutProperties(_React$useContext2$xA, _excluded);
115
117
  var isMounted = useMounted();
116
118
  var defaultizedProps = _extends({}, defaultProps, settings, props);
117
119
  var position = defaultizedProps.position,
@@ -132,11 +134,11 @@ function ChartsXAxis(inProps) {
132
134
  var classes = useUtilityClasses(_extends({}, defaultizedProps, {
133
135
  theme: theme
134
136
  }));
135
- var _React$useContext2 = React.useContext(DrawingContext),
136
- left = _React$useContext2.left,
137
- top = _React$useContext2.top,
138
- width = _React$useContext2.width,
139
- height = _React$useContext2.height;
137
+ var _React$useContext3 = React.useContext(DrawingContext),
138
+ left = _React$useContext3.left,
139
+ top = _React$useContext3.top,
140
+ width = _React$useContext3.width,
141
+ height = _React$useContext3.height;
140
142
  var tickSize = disableTicks ? 4 : tickSizeProp;
141
143
  var positionSign = position === 'bottom' ? 1 : -1;
142
144
  var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
@@ -225,9 +227,10 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
225
227
  // | To update them edit the TypeScript types and run "yarn proptypes" |
226
228
  // ----------------------------------------------------------------------
227
229
  /**
228
- * Id of the axis to render.
230
+ * The id of the axis to render.
231
+ * If undefined, it will be the first defined axis.
229
232
  */
230
- axisId: PropTypes.string.isRequired,
233
+ axisId: PropTypes.string,
231
234
  /**
232
235
  * Override or extend the styles applied to the component.
233
236
  */
@@ -46,16 +46,18 @@ var defaultProps = {
46
46
  * - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
47
47
  */
48
48
  function ChartsYAxis(inProps) {
49
- var _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
49
+ var _props$axisId, _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
50
50
  var props = useThemeProps({
51
51
  props: _extends({}, defaultProps, inProps),
52
52
  name: 'MuiChartsYAxis'
53
53
  });
54
54
  var _React$useContext = React.useContext(CartesianContext),
55
- _React$useContext$yAx = _React$useContext.yAxis[props.axisId],
56
- yScale = _React$useContext$yAx.scale,
57
- tickNumber = _React$useContext$yAx.tickNumber,
58
- settings = _objectWithoutProperties(_React$useContext$yAx, _excluded);
55
+ yAxisIds = _React$useContext.yAxisIds;
56
+ var _React$useContext2 = React.useContext(CartesianContext),
57
+ _React$useContext2$yA = _React$useContext2.yAxis[(_props$axisId = props.axisId) != null ? _props$axisId : yAxisIds[0]],
58
+ yScale = _React$useContext2$yA.scale,
59
+ tickNumber = _React$useContext2$yA.tickNumber,
60
+ settings = _objectWithoutProperties(_React$useContext2$yA, _excluded);
59
61
  var defaultizedProps = _extends({}, defaultProps, settings, props);
60
62
  var position = defaultizedProps.position,
61
63
  disableLine = defaultizedProps.disableLine,
@@ -71,11 +73,11 @@ function ChartsYAxis(inProps) {
71
73
  var classes = useUtilityClasses(_extends({}, defaultizedProps, {
72
74
  theme: theme
73
75
  }));
74
- var _React$useContext2 = React.useContext(DrawingContext),
75
- left = _React$useContext2.left,
76
- top = _React$useContext2.top,
77
- width = _React$useContext2.width,
78
- height = _React$useContext2.height;
76
+ var _React$useContext3 = React.useContext(DrawingContext),
77
+ left = _React$useContext3.left,
78
+ top = _React$useContext3.top,
79
+ width = _React$useContext3.width,
80
+ height = _React$useContext3.height;
79
81
  var tickSize = disableTicks ? 4 : tickSizeProp;
80
82
  var yTicks = useTicks({
81
83
  scale: yScale,
@@ -156,9 +158,10 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
156
158
  // | To update them edit the TypeScript types and run "yarn proptypes" |
157
159
  // ----------------------------------------------------------------------
158
160
  /**
159
- * Id of the axis to render.
161
+ * The id of the axis to render.
162
+ * If undefined, it will be the first defined axis.
160
163
  */
161
- axisId: PropTypes.string.isRequired,
164
+ axisId: PropTypes.string,
162
165
  /**
163
166
  * Override or extend the styles applied to the component.
164
167
  */