@mui/x-charts 6.18.0 → 7.0.0-alpha.0

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 (132) hide show
  1. package/BarChart/BarChart.d.ts +15 -8
  2. package/BarChart/BarChart.js +41 -4
  3. package/BarChart/BarPlot.d.ts +2 -2
  4. package/CHANGELOG.md +212 -5
  5. package/ChartsAxis/ChartsAxis.d.ts +3 -3
  6. package/ChartsAxis/ChartsAxis.js +5 -5
  7. package/ChartsAxis/axisClasses.d.ts +2 -2
  8. package/ChartsLegend/ChartsLegend.d.ts +10 -6
  9. package/ChartsLegend/ChartsLegend.js +137 -2
  10. package/ChartsLegend/chartsLegendClasses.d.ts +1 -1
  11. package/ChartsLegend/chartsLegendClasses.js +2 -2
  12. package/ChartsReferenceLine/ChartsReferenceLine.d.ts +10 -0
  13. package/ChartsReferenceLine/ChartsReferenceLine.js +78 -0
  14. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +13 -0
  15. package/ChartsReferenceLine/ChartsXReferenceLine.js +112 -0
  16. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +13 -0
  17. package/ChartsReferenceLine/ChartsYReferenceLine.js +112 -0
  18. package/ChartsReferenceLine/chartsReferenceLineClasses.d.ts +15 -0
  19. package/ChartsReferenceLine/chartsReferenceLineClasses.js +14 -0
  20. package/ChartsReferenceLine/common.d.ts +41 -0
  21. package/ChartsReferenceLine/common.js +27 -0
  22. package/ChartsReferenceLine/index.d.ts +2 -0
  23. package/ChartsReferenceLine/index.js +27 -0
  24. package/ChartsReferenceLine/package.json +6 -0
  25. package/ChartsSurface.d.ts +11 -0
  26. package/ChartsTooltip/ChartsTooltip.d.ts +4 -4
  27. package/ChartsXAxis/ChartsXAxis.js +9 -5
  28. package/ChartsYAxis/ChartsYAxis.js +9 -5
  29. package/LineChart/AreaPlot.d.ts +2 -2
  30. package/LineChart/LineChart.d.ts +18 -11
  31. package/LineChart/LineChart.js +41 -4
  32. package/LineChart/LineHighlightPlot.d.ts +4 -4
  33. package/LineChart/LineHighlightPlot.js +1 -1
  34. package/LineChart/LinePlot.d.ts +2 -2
  35. package/LineChart/MarkPlot.d.ts +4 -4
  36. package/LineChart/MarkPlot.js +2 -1
  37. package/PieChart/PieArcLabelPlot.d.ts +4 -4
  38. package/PieChart/PieArcPlot.d.ts +4 -4
  39. package/PieChart/PieChart.d.ts +8 -8
  40. package/PieChart/PieChart.js +34 -4
  41. package/PieChart/PiePlot.d.ts +6 -6
  42. package/ResponsiveChartContainer/index.d.ts +13 -3
  43. package/ScatterChart/ScatterChart.d.ts +8 -8
  44. package/ScatterChart/ScatterChart.js +34 -4
  45. package/ScatterChart/ScatterPlot.d.ts +4 -4
  46. package/SparkLineChart/SparkLineChart.d.ts +10 -10
  47. package/SparkLineChart/SparkLineChart.js +22 -0
  48. package/context/CartesianContextProvider.d.ts +21 -1
  49. package/context/CartesianContextProvider.js +11 -0
  50. package/context/DrawingProvider.d.ts +18 -0
  51. package/context/DrawingProvider.js +6 -0
  52. package/context/HighlightProvider.d.ts +17 -0
  53. package/context/InteractionProvider.d.ts +6 -0
  54. package/context/SeriesContextProvider.d.ts +5 -0
  55. package/esm/BarChart/BarChart.js +41 -4
  56. package/esm/ChartsAxis/ChartsAxis.js +6 -5
  57. package/esm/ChartsLegend/ChartsLegend.js +140 -4
  58. package/esm/ChartsLegend/chartsLegendClasses.js +1 -1
  59. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
  60. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
  61. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
  62. package/esm/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
  63. package/esm/ChartsReferenceLine/common.js +20 -0
  64. package/esm/ChartsReferenceLine/index.js +2 -0
  65. package/esm/ChartsXAxis/ChartsXAxis.js +10 -6
  66. package/esm/ChartsYAxis/ChartsYAxis.js +10 -6
  67. package/esm/LineChart/LineChart.js +41 -4
  68. package/esm/LineChart/LineHighlightPlot.js +1 -1
  69. package/esm/LineChart/MarkPlot.js +2 -1
  70. package/esm/PieChart/PieChart.js +34 -4
  71. package/esm/ScatterChart/ScatterChart.js +34 -4
  72. package/esm/SparkLineChart/SparkLineChart.js +22 -0
  73. package/esm/context/CartesianContextProvider.js +11 -0
  74. package/esm/context/DrawingProvider.js +6 -0
  75. package/esm/index.js +2 -0
  76. package/esm/internals/geometry.js +2 -2
  77. package/hooks/useScale.d.ts +2 -2
  78. package/index.d.ts +2 -0
  79. package/index.js +23 -1
  80. package/internals/components/ChartsText.d.ts +1 -1
  81. package/internals/geometry.d.ts +2 -2
  82. package/internals/geometry.js +2 -2
  83. package/internals/isBandScale.d.ts +3 -1
  84. package/internals/utils.d.ts +5 -0
  85. package/legacy/BarChart/BarChart.js +41 -4
  86. package/legacy/ChartsAxis/ChartsAxis.js +6 -5
  87. package/legacy/ChartsLegend/ChartsLegend.js +140 -4
  88. package/legacy/ChartsLegend/chartsLegendClasses.js +1 -1
  89. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
  90. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
  91. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
  92. package/legacy/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
  93. package/legacy/ChartsReferenceLine/common.js +20 -0
  94. package/legacy/ChartsReferenceLine/index.js +2 -0
  95. package/legacy/ChartsXAxis/ChartsXAxis.js +15 -12
  96. package/legacy/ChartsYAxis/ChartsYAxis.js +15 -12
  97. package/legacy/LineChart/LineChart.js +41 -4
  98. package/legacy/LineChart/LineHighlightPlot.js +1 -1
  99. package/legacy/LineChart/MarkPlot.js +2 -1
  100. package/legacy/PieChart/PieChart.js +34 -4
  101. package/legacy/ScatterChart/ScatterChart.js +34 -4
  102. package/legacy/SparkLineChart/SparkLineChart.js +22 -0
  103. package/legacy/context/CartesianContextProvider.js +11 -0
  104. package/legacy/context/DrawingProvider.js +6 -0
  105. package/legacy/index.js +3 -1
  106. package/legacy/internals/geometry.js +2 -2
  107. package/models/axis.d.ts +37 -17
  108. package/models/layout.d.ts +6 -0
  109. package/models/seriesType/common.d.ts +16 -0
  110. package/modern/BarChart/BarChart.js +41 -4
  111. package/modern/ChartsAxis/ChartsAxis.js +5 -5
  112. package/modern/ChartsLegend/ChartsLegend.js +140 -4
  113. package/modern/ChartsLegend/chartsLegendClasses.js +1 -1
  114. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
  115. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +104 -0
  116. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +104 -0
  117. package/modern/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
  118. package/modern/ChartsReferenceLine/common.js +20 -0
  119. package/modern/ChartsReferenceLine/index.js +2 -0
  120. package/modern/ChartsXAxis/ChartsXAxis.js +9 -5
  121. package/modern/ChartsYAxis/ChartsYAxis.js +9 -5
  122. package/modern/LineChart/LineChart.js +41 -4
  123. package/modern/LineChart/LineHighlightPlot.js +1 -1
  124. package/modern/LineChart/MarkPlot.js +2 -1
  125. package/modern/PieChart/PieChart.js +34 -4
  126. package/modern/ScatterChart/ScatterChart.js +34 -4
  127. package/modern/SparkLineChart/SparkLineChart.js +22 -0
  128. package/modern/context/CartesianContextProvider.js +11 -0
  129. package/modern/context/DrawingProvider.js +6 -0
  130. package/modern/index.js +3 -1
  131. package/modern/internals/geometry.js +2 -2
  132. package/package.json +1 -1
@@ -3,6 +3,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["rotate", "dominantBaseline"],
4
4
  _excluded2 = ["label"];
5
5
  import * as React from 'react';
6
+ import PropTypes from 'prop-types';
6
7
  import { useSlotProps } from '@mui/base/utils';
7
8
  import { NoSsr } from '@mui/base/NoSsr';
8
9
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
@@ -10,7 +11,7 @@ import { useThemeProps, useTheme, styled } from '@mui/material/styles';
10
11
  import { DrawingContext } from '../context/DrawingProvider';
11
12
  import { getSeriesToDisplay } from './utils';
12
13
  import { SeriesContext } from '../context/SeriesContextProvider';
13
- import { getChartsLegendUtilityClass } from './chartsLegendClasses';
14
+ import { getLegendUtilityClass } from './chartsLegendClasses';
14
15
  import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -25,7 +26,7 @@ const useUtilityClasses = ownerState => {
25
26
  label: ['label'],
26
27
  series: ['series']
27
28
  };
28
- return composeClasses(slots, getChartsLegendUtilityClass, classes);
29
+ return composeClasses(slots, getLegendUtilityClass, classes);
29
30
  };
30
31
  export const ChartsLegendRoot = styled('g', {
31
32
  name: 'MuiChartsLegend',
@@ -233,7 +234,107 @@ function DefaultChartsLegend(props) {
233
234
  })
234
235
  });
235
236
  }
236
- export function ChartsLegend(inProps) {
237
+ process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
238
+ // ----------------------------- Warning --------------------------------
239
+ // | These PropTypes are generated from the TypeScript type definitions |
240
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
241
+ // ----------------------------------------------------------------------
242
+ /**
243
+ * Override or extend the styles applied to the component.
244
+ */
245
+ classes: PropTypes.object.isRequired,
246
+ /**
247
+ * The direction of the legend layout.
248
+ * The default depends on the chart.
249
+ */
250
+ direction: PropTypes.oneOf(['column', 'row']).isRequired,
251
+ drawingArea: PropTypes.shape({
252
+ bottom: PropTypes.number.isRequired,
253
+ height: PropTypes.number.isRequired,
254
+ left: PropTypes.number.isRequired,
255
+ right: PropTypes.number.isRequired,
256
+ top: PropTypes.number.isRequired,
257
+ width: PropTypes.number.isRequired
258
+ }).isRequired,
259
+ /**
260
+ * Set to true to hide the legend.
261
+ */
262
+ hidden: PropTypes.bool,
263
+ /**
264
+ * Space between two legend items (in px).
265
+ * @default 10
266
+ */
267
+ itemGap: PropTypes.number,
268
+ /**
269
+ * Height of the item mark (in px).
270
+ * @default 20
271
+ */
272
+ itemMarkHeight: PropTypes.number,
273
+ /**
274
+ * Width of the item mark (in px).
275
+ * @default 20
276
+ */
277
+ itemMarkWidth: PropTypes.number,
278
+ /**
279
+ * Style applied to legend labels.
280
+ * @default theme.typography.subtitle1
281
+ */
282
+ labelStyle: PropTypes.object,
283
+ /**
284
+ * Space between the mark and the label (in px).
285
+ * @default 5
286
+ */
287
+ markGap: PropTypes.number,
288
+ /**
289
+ * Legend padding (in px).
290
+ * Can either be a single number, or an object with top, left, bottom, right properties.
291
+ * @default 0
292
+ */
293
+ padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
294
+ bottom: PropTypes.number,
295
+ left: PropTypes.number,
296
+ right: PropTypes.number,
297
+ top: PropTypes.number
298
+ })]),
299
+ position: PropTypes.shape({
300
+ horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
301
+ vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
302
+ }).isRequired,
303
+ series: PropTypes.shape({
304
+ bar: PropTypes.shape({
305
+ series: PropTypes.object.isRequired,
306
+ seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired,
307
+ stackingGroups: PropTypes.arrayOf(PropTypes.shape({
308
+ ids: PropTypes.arrayOf(PropTypes.string).isRequired,
309
+ stackingOffset: PropTypes.func.isRequired,
310
+ stackingOrder: PropTypes.func.isRequired
311
+ })).isRequired
312
+ }),
313
+ line: PropTypes.shape({
314
+ series: PropTypes.object.isRequired,
315
+ seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired,
316
+ stackingGroups: PropTypes.arrayOf(PropTypes.shape({
317
+ ids: PropTypes.arrayOf(PropTypes.string).isRequired,
318
+ stackingOffset: PropTypes.func.isRequired,
319
+ stackingOrder: PropTypes.func.isRequired
320
+ })).isRequired
321
+ }),
322
+ pie: PropTypes.shape({
323
+ series: PropTypes.object.isRequired,
324
+ seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired
325
+ }),
326
+ scatter: PropTypes.shape({
327
+ series: PropTypes.object.isRequired,
328
+ seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired
329
+ })
330
+ }).isRequired,
331
+ seriesToDisplay: PropTypes.arrayOf(PropTypes.shape({
332
+ color: PropTypes.string.isRequired,
333
+ id: PropTypes.string.isRequired,
334
+ label: PropTypes.string.isRequired
335
+ })).isRequired
336
+ } : void 0;
337
+ function ChartsLegend(inProps) {
237
338
  var _slots$legend;
238
339
  const props = useThemeProps({
239
340
  props: _extends({}, defaultProps, inProps),
@@ -269,4 +370,39 @@ export function ChartsLegend(inProps) {
269
370
  ownerState: {}
270
371
  });
271
372
  return /*#__PURE__*/_jsx(ChartLegendRender, _extends({}, chartLegendRenderProps));
272
- }
373
+ }
374
+ process.env.NODE_ENV !== "production" ? ChartsLegend.propTypes = {
375
+ // ----------------------------- Warning --------------------------------
376
+ // | These PropTypes are generated from the TypeScript type definitions |
377
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
378
+ // ----------------------------------------------------------------------
379
+ /**
380
+ * Override or extend the styles applied to the component.
381
+ */
382
+ classes: PropTypes.object,
383
+ /**
384
+ * The direction of the legend layout.
385
+ * The default depends on the chart.
386
+ */
387
+ direction: PropTypes.oneOf(['column', 'row']),
388
+ /**
389
+ * Set to true to hide the legend.
390
+ * @default false
391
+ */
392
+ hidden: PropTypes.bool,
393
+ position: PropTypes.shape({
394
+ horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
395
+ vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
396
+ }),
397
+ /**
398
+ * The props used for each component slot.
399
+ * @default {}
400
+ */
401
+ slotProps: PropTypes.object,
402
+ /**
403
+ * Overridable component slots.
404
+ * @default {}
405
+ */
406
+ slots: PropTypes.object
407
+ } : void 0;
408
+ export { ChartsLegend };
@@ -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 const 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 * as React from 'react';
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ import { useDrawingArea, useXScale } from '../hooks';
5
+ import { ReferenceLineRoot } from './common';
6
+ import { ChartsText } from '../internals/components/ChartsText';
7
+ import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ const getTextParams = ({
11
+ top,
12
+ height,
13
+ spacingY,
14
+ labelAlign = 'middle'
15
+ }) => {
16
+ switch (labelAlign) {
17
+ case 'start':
18
+ return {
19
+ y: top + spacingY,
20
+ style: {
21
+ dominantBaseline: 'hanging',
22
+ textAnchor: 'start'
23
+ }
24
+ };
25
+ case 'end':
26
+ return {
27
+ y: top + height - spacingY,
28
+ style: {
29
+ dominantBaseline: 'auto',
30
+ textAnchor: 'start'
31
+ }
32
+ };
33
+ default:
34
+ return {
35
+ y: top + height / 2,
36
+ style: {
37
+ dominantBaseline: 'central',
38
+ textAnchor: 'start'
39
+ }
40
+ };
41
+ }
42
+ };
43
+ export function getXReferenceLineClasses(classes) {
44
+ return composeClasses({
45
+ root: ['root', 'vertical'],
46
+ line: ['line'],
47
+ label: ['label']
48
+ }, getReferenceLineUtilityClass, classes);
49
+ }
50
+ let warnedOnce = false;
51
+ function ChartsXReferenceLine(props) {
52
+ var _spacing$x, _spacing$y;
53
+ const {
54
+ x,
55
+ label = '',
56
+ spacing = 5,
57
+ classes: inClasses,
58
+ labelAlign,
59
+ lineStyle,
60
+ labelStyle,
61
+ axisId
62
+ } = props;
63
+ const {
64
+ top,
65
+ height
66
+ } = useDrawingArea();
67
+ const xAxisScale = useXScale(axisId);
68
+ const 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 ${x} does not exist in the data of x axis with id ${axisId}.`);
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+ const d = `M ${xPosition} ${top} l 0 ${height}`;
79
+ const classes = getXReferenceLineClasses(inClasses);
80
+ const spacingX = typeof spacing === 'object' ? (_spacing$x = spacing.x) != null ? _spacing$x : 0 : spacing;
81
+ const spacingY = typeof spacing === 'object' ? (_spacing$y = spacing.y) != null ? _spacing$y : 0 : spacing;
82
+ const textParams = _extends({
83
+ x: xPosition + spacingX,
84
+ text: label,
85
+ fontSize: 12
86
+ }, getTextParams({
87
+ top,
88
+ height,
89
+ spacingY,
90
+ 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 * as React from 'react';
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ import { useDrawingArea, useYScale } from '../hooks';
5
+ import { ReferenceLineRoot } from './common';
6
+ import { ChartsText } from '../internals/components/ChartsText';
7
+ import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ const getTextParams = ({
11
+ left,
12
+ width,
13
+ spacingX,
14
+ labelAlign = 'middle'
15
+ }) => {
16
+ switch (labelAlign) {
17
+ case 'start':
18
+ return {
19
+ x: left + spacingX,
20
+ style: {
21
+ dominantBaseline: 'auto',
22
+ textAnchor: 'start'
23
+ }
24
+ };
25
+ case 'end':
26
+ return {
27
+ x: left + width - spacingX,
28
+ style: {
29
+ dominantBaseline: 'auto',
30
+ textAnchor: 'end'
31
+ }
32
+ };
33
+ default:
34
+ return {
35
+ x: left + width / 2,
36
+ style: {
37
+ dominantBaseline: 'auto',
38
+ textAnchor: 'middle'
39
+ }
40
+ };
41
+ }
42
+ };
43
+ let warnedOnce = false;
44
+ export function getYReferenceLineClasses(classes) {
45
+ return composeClasses({
46
+ root: ['root', 'horizontal'],
47
+ line: ['line'],
48
+ label: ['label']
49
+ }, getReferenceLineUtilityClass, classes);
50
+ }
51
+ function ChartsYReferenceLine(props) {
52
+ var _spacing$x, _spacing$y;
53
+ const {
54
+ y,
55
+ label = '',
56
+ spacing = 5,
57
+ classes: inClasses,
58
+ labelAlign,
59
+ lineStyle,
60
+ labelStyle,
61
+ axisId
62
+ } = props;
63
+ const {
64
+ left,
65
+ width
66
+ } = useDrawingArea();
67
+ const yAxisScale = useYScale(axisId);
68
+ const 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 ${y} does not exist in the data of y axis with id ${axisId}.`);
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+ const d = `M ${left} ${yPosition} l ${width} 0`;
79
+ const classes = getYReferenceLineClasses(inClasses);
80
+ const spacingX = typeof spacing === 'object' ? (_spacing$x = spacing.x) != null ? _spacing$x : 0 : spacing;
81
+ const spacingY = typeof spacing === 'object' ? (_spacing$y = spacing.y) != null ? _spacing$y : 0 : spacing;
82
+ const textParams = _extends({
83
+ y: yPosition - spacingY,
84
+ text: label,
85
+ fontSize: 12
86
+ }, getTextParams({
87
+ left,
88
+ width,
89
+ spacingX,
90
+ 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 const referenceLineClasses = generateUtilityClasses('MuiChartsReferenceLine', ['root', 'vertical', 'horizontal', 'line', 'label']);
@@ -0,0 +1,20 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { styled } from '@mui/material/styles';
3
+ import { referenceLineClasses } from './chartsReferenceLineClasses';
4
+ export const ReferenceLineRoot = styled('g')(({
5
+ theme
6
+ }) => ({
7
+ [`& .${referenceLineClasses.line}`]: {
8
+ fill: 'none',
9
+ stroke: (theme.vars || theme).palette.text.primary,
10
+ shapeRendering: 'crispEdges',
11
+ strokeWidth: 1,
12
+ pointerEvents: 'none'
13
+ },
14
+ [`& .${referenceLineClasses.label}`]: _extends({
15
+ fill: (theme.vars || theme).palette.text.primary,
16
+ stroke: 'none',
17
+ pointerEvents: 'none',
18
+ fontSize: 12
19
+ }, theme.typography.body1)
20
+ }));
@@ -0,0 +1,2 @@
1
+ export * from './ChartsReferenceLine';
2
+ export * from './chartsReferenceLineClasses';
@@ -102,22 +102,25 @@ const 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
  const props = useThemeProps({
107
107
  props: _extends({}, defaultProps, inProps),
108
108
  name: 'MuiChartsXAxis'
109
109
  });
110
+ const {
111
+ xAxisIds
112
+ } = React.useContext(CartesianContext);
110
113
  const _React$useContext = React.useContext(CartesianContext),
111
- _props$axisId = props.axisId,
114
+ _ref = (_props$axisId = props.axisId) != null ? _props$axisId : xAxisIds[0],
112
115
  {
113
116
  xAxis: {
114
- [_props$axisId]: {
117
+ [_ref]: {
115
118
  scale: xScale,
116
119
  tickNumber
117
120
  }
118
121
  }
119
122
  } = _React$useContext,
120
- settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_props$axisId], _excluded);
123
+ settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_ref], _excluded);
121
124
  const isMounted = useMounted();
122
125
  const defaultizedProps = _extends({}, defaultProps, settings, props);
123
126
  const {
@@ -235,9 +238,10 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
235
238
  // | To update them edit the TypeScript types and run "yarn proptypes" |
236
239
  // ----------------------------------------------------------------------
237
240
  /**
238
- * Id of the axis to render.
241
+ * The id of the axis to render.
242
+ * If undefined, it will be the first defined axis.
239
243
  */
240
- axisId: PropTypes.string.isRequired,
244
+ axisId: PropTypes.string,
241
245
  /**
242
246
  * Override or extend the styles applied to the component.
243
247
  */
@@ -48,22 +48,25 @@ const defaultProps = {
48
48
  * - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
49
49
  */
50
50
  function ChartsYAxis(inProps) {
51
- var _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
51
+ var _props$axisId, _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
52
52
  const props = useThemeProps({
53
53
  props: _extends({}, defaultProps, inProps),
54
54
  name: 'MuiChartsYAxis'
55
55
  });
56
+ const {
57
+ yAxisIds
58
+ } = React.useContext(CartesianContext);
56
59
  const _React$useContext = React.useContext(CartesianContext),
57
- _props$axisId = props.axisId,
60
+ _ref = (_props$axisId = props.axisId) != null ? _props$axisId : yAxisIds[0],
58
61
  {
59
62
  yAxis: {
60
- [_props$axisId]: {
63
+ [_ref]: {
61
64
  scale: yScale,
62
65
  tickNumber
63
66
  }
64
67
  }
65
68
  } = _React$useContext,
66
- settings = _objectWithoutPropertiesLoose(_React$useContext.yAxis[_props$axisId], _excluded);
69
+ settings = _objectWithoutPropertiesLoose(_React$useContext.yAxis[_ref], _excluded);
67
70
  const defaultizedProps = _extends({}, defaultProps, settings, props);
68
71
  const {
69
72
  position,
@@ -168,9 +171,10 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
168
171
  // | To update them edit the TypeScript types and run "yarn proptypes" |
169
172
  // ----------------------------------------------------------------------
170
173
  /**
171
- * Id of the axis to render.
174
+ * The id of the axis to render.
175
+ * If undefined, it will be the first defined axis.
172
176
  */
173
- axisId: PropTypes.string.isRequired,
177
+ axisId: PropTypes.string,
174
178
  /**
175
179
  * Override or extend the styles applied to the component.
176
180
  */