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

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 (83) hide show
  1. package/BarChart/BarChart.d.ts +3 -0
  2. package/BarChart/BarChart.js +4 -8
  3. package/CHANGELOG.md +104 -0
  4. package/ChartsLegend/ChartsLegend.d.ts +43 -24
  5. package/ChartsLegend/ChartsLegend.js +185 -143
  6. package/ChartsLegend/utils.d.ts +1 -6
  7. package/ChartsSurface.js +3 -11
  8. package/ChartsXAxis/ChartsXAxis.js +48 -25
  9. package/ChartsYAxis/ChartsYAxis.js +47 -26
  10. package/LineChart/LineChart.d.ts +3 -0
  11. package/LineChart/LineChart.js +4 -8
  12. package/PieChart/PieChart.d.ts +3 -0
  13. package/PieChart/PieChart.js +4 -8
  14. package/ScatterChart/ScatterChart.d.ts +3 -0
  15. package/ScatterChart/ScatterChart.js +4 -8
  16. package/constants.js +1 -1
  17. package/context/CartesianContextProvider.js +10 -10
  18. package/context/DrawingProvider.d.ts +2 -0
  19. package/context/DrawingProvider.js +2 -0
  20. package/esm/BarChart/BarChart.js +4 -8
  21. package/esm/ChartsLegend/ChartsLegend.js +184 -142
  22. package/esm/ChartsSurface.js +3 -11
  23. package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
  24. package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
  25. package/esm/LineChart/LineChart.js +4 -8
  26. package/esm/PieChart/PieChart.js +4 -8
  27. package/esm/ScatterChart/ScatterChart.js +4 -8
  28. package/esm/constants.js +1 -1
  29. package/esm/context/CartesianContextProvider.js +11 -11
  30. package/esm/context/DrawingProvider.js +2 -0
  31. package/esm/hooks/useChartDimensions.js +2 -0
  32. package/esm/hooks/useTicks.js +5 -5
  33. package/esm/internals/components/AxisSharedComponents.js +15 -70
  34. package/esm/internals/components/ChartsText.js +71 -0
  35. package/esm/internals/domUtils.js +113 -0
  36. package/hooks/useChartDimensions.d.ts +2 -0
  37. package/hooks/useChartDimensions.js +2 -0
  38. package/hooks/useTicks.d.ts +2 -3
  39. package/hooks/useTicks.js +6 -6
  40. package/index.js +1 -1
  41. package/internals/components/AxisSharedComponents.d.ts +0 -4
  42. package/internals/components/AxisSharedComponents.js +16 -71
  43. package/internals/components/ChartsText.d.ts +32 -0
  44. package/internals/components/ChartsText.js +81 -0
  45. package/internals/domUtils.d.ts +14 -0
  46. package/internals/domUtils.js +122 -0
  47. package/legacy/BarChart/BarChart.js +4 -8
  48. package/legacy/ChartsLegend/ChartsLegend.js +196 -140
  49. package/legacy/ChartsSurface.js +2 -11
  50. package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
  51. package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
  52. package/legacy/LineChart/LineChart.js +4 -8
  53. package/legacy/PieChart/PieChart.js +4 -8
  54. package/legacy/ScatterChart/ScatterChart.js +4 -8
  55. package/legacy/constants.js +1 -1
  56. package/legacy/context/CartesianContextProvider.js +11 -11
  57. package/legacy/context/DrawingProvider.js +2 -0
  58. package/legacy/hooks/useChartDimensions.js +2 -0
  59. package/legacy/hooks/useTicks.js +5 -5
  60. package/legacy/index.js +1 -1
  61. package/legacy/internals/components/AxisSharedComponents.js +9 -63
  62. package/legacy/internals/components/ChartsText.js +77 -0
  63. package/legacy/internals/domUtils.js +121 -0
  64. package/models/axis.d.ts +6 -5
  65. package/models/layout.d.ts +7 -6
  66. package/modern/BarChart/BarChart.js +4 -8
  67. package/modern/ChartsLegend/ChartsLegend.js +184 -142
  68. package/modern/ChartsSurface.js +3 -11
  69. package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
  70. package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
  71. package/modern/LineChart/LineChart.js +4 -8
  72. package/modern/PieChart/PieChart.js +4 -8
  73. package/modern/ScatterChart/ScatterChart.js +4 -8
  74. package/modern/constants.js +1 -1
  75. package/modern/context/CartesianContextProvider.js +11 -11
  76. package/modern/context/DrawingProvider.js +2 -0
  77. package/modern/hooks/useChartDimensions.js +2 -0
  78. package/modern/hooks/useTicks.js +5 -5
  79. package/modern/index.js +1 -1
  80. package/modern/internals/components/AxisSharedComponents.js +15 -70
  81. package/modern/internals/components/ChartsText.js +71 -0
  82. package/modern/internals/domUtils.js +113 -0
  83. package/package.json +1 -1
@@ -1,12 +1,16 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
1
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["label"];
2
4
  import * as React from 'react';
3
5
  import { useSlotProps } from '@mui/base/utils';
6
+ import { NoSsr } from '@mui/base/NoSsr';
4
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
5
8
  import { useThemeProps, useTheme, styled } from '@mui/material/styles';
6
9
  import { DrawingContext } from '../context/DrawingProvider';
7
10
  import { getSeriesToDisplay } from './utils';
8
11
  import { SeriesContext } from '../context/SeriesContextProvider';
9
12
  import { getChartsLegendUtilityClass } from './chartsLegendClasses';
13
+ import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
10
14
  import { jsx as _jsx } from "react/jsx-runtime";
11
15
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
16
  const useUtilityClasses = ownerState => {
@@ -22,167 +26,207 @@ const useUtilityClasses = ownerState => {
22
26
  };
23
27
  return composeClasses(slots, getChartsLegendUtilityClass, classes);
24
28
  };
25
- function getTranslePosition({
26
- position,
27
- drawingArea
28
- }) {
29
- let xValue;
30
- switch (position.horizontal) {
31
- case 'left':
32
- xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left}px - var(--ChartsLegend-rootWidth))`;
33
- break;
34
- case 'middle':
35
- xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left + drawingArea.width / 2}px - 0.5 * var(--ChartsLegend-rootWidth))`;
36
- break;
37
- default:
38
- xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left + drawingArea.width}px)`;
39
- break;
40
- }
41
- let yValue;
42
- switch (position.vertical) {
43
- case 'top':
44
- yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top}px - var(--ChartsLegend-rootHeight))`;
45
- break;
46
- case 'middle':
47
- yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top + drawingArea.height / 2}px - 0.5 * var(--ChartsLegend-rootHeight))`;
48
- break;
49
- default:
50
- yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top + drawingArea.height}px)`;
51
- break;
52
- }
53
- return {
54
- transform: `translate(${xValue}, ${yValue})`
55
- };
56
- }
57
29
  export const ChartsLegendRoot = styled('g', {
58
30
  name: 'MuiChartsLegend',
59
31
  slot: 'Root',
60
32
  overridesResolver: (props, styles) => styles.root
61
- })(({
62
- ownerState
63
- }) => {
64
- const {
65
- direction,
66
- drawingArea,
67
- offsetX,
68
- offsetY,
69
- seriesNumber,
70
- position
71
- } = ownerState;
72
- return _extends({
73
- '--ChartsLegend-rootOffsetX': typeof offsetX === 'number' ? `${offsetX}px` : undefined,
74
- '--ChartsLegend-rootOffsetY': typeof offsetY === 'number' ? `${offsetY}px` : undefined,
75
- '--ChartsLegend-rootWidth': direction === 'row' ? `calc(var(--ChartsLegend-itemWidth) * ${seriesNumber} + var(--ChartsLegend-rootSpacing) * ${seriesNumber - 1} )` : 'var(--ChartsLegend-itemWidth)',
76
- '--ChartsLegend-rootHeight': direction === 'row' ? 'var(--ChartsLegend-itemMarkSize)' : `calc(var(--ChartsLegend-itemMarkSize) * ${seriesNumber} + var(--ChartsLegend-rootSpacing) * ${seriesNumber - 1} )`
77
- }, getTranslePosition({
78
- position,
79
- drawingArea,
80
- offsetX,
81
- offsetY
82
- }));
83
- });
84
- export const ChartsSeriesLegendGroup = styled('g', {
85
- name: 'MuiChartsLegend',
86
- slot: 'ChartsSeriesLegendGroup',
87
- overridesResolver: (props, styles) => styles.series
88
- })(({
89
- ownerState
90
- }) => {
91
- const {
92
- direction,
93
- seriesIndex
94
- } = ownerState;
95
- if (direction === 'row') {
96
- return {
97
- transform: `translate(calc(${seriesIndex} * (var(--ChartsLegend-itemWidth) + var(--ChartsLegend-rootSpacing))), 0)`
98
- };
99
- }
100
- return {
101
- transform: `translate(0, calc(${seriesIndex} * (var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-rootSpacing))))`
102
- };
103
- });
104
- export const ChartsLegendMark = styled('rect', {
105
- name: 'MuiChartsLegend',
106
- slot: 'Mark',
107
- overridesResolver: (props, styles) => styles.mark
108
- })(({
109
- ownerState
110
- }) => ({
111
- x: 0,
112
- y: 0,
113
- width: 'var(--ChartsLegend-itemMarkSize)',
114
- height: 'var(--ChartsLegend-itemMarkSize)',
115
- fill: ownerState.color
116
- }));
117
- export const ChartsLegendLabel = styled('text', {
118
- name: 'MuiChartsLegend',
119
- slot: 'Label',
120
- overridesResolver: (props, styles) => styles.label
121
- })(({
122
- theme
123
- }) => _extends({}, theme.typography.body1, {
124
- color: 'inherit',
125
- transform: `translate(
126
- calc(var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-labelSpacing)),
127
- calc(0.5 * var(--ChartsLegend-itemMarkSize))
128
- )`,
129
- fill: (theme.vars || theme).palette.text.primary,
130
- dominantBaseline: 'central'
131
- }));
33
+ })({});
132
34
  const defaultProps = {
133
35
  position: {
134
36
  horizontal: 'middle',
135
37
  vertical: 'top'
136
38
  },
137
- direction: 'row',
138
- markSize: 20,
139
- itemWidth: 100,
140
- spacing: 2
39
+ direction: 'row'
40
+ };
41
+ /**
42
+ * Transforms number or partial padding object to a defaultized padding object.
43
+ */
44
+ const getStandardizedPadding = padding => {
45
+ if (typeof padding === 'number') {
46
+ return {
47
+ left: padding,
48
+ right: padding,
49
+ top: padding,
50
+ bottom: padding
51
+ };
52
+ }
53
+ return _extends({
54
+ left: 0,
55
+ right: 0,
56
+ top: 0,
57
+ bottom: 0
58
+ }, padding);
141
59
  };
142
60
  function DefaultChartsLegend(props) {
143
61
  const {
144
62
  hidden,
145
63
  position,
146
64
  direction,
147
- offset,
148
- series,
149
65
  seriesToDisplay,
150
66
  drawingArea,
151
- classes
67
+ classes,
68
+ itemMarkWidth = 20,
69
+ itemMarkHeight = 20,
70
+ markGap = 5,
71
+ itemGap = 10,
72
+ padding: paddingProps = 10,
73
+ labelStyle: inLabelStyle
152
74
  } = props;
75
+ const theme = useTheme();
76
+ const labelStyle = React.useMemo(() => _extends({}, theme.typography.subtitle1, {
77
+ color: 'inherit',
78
+ fill: (theme.vars || theme).palette.text.primary,
79
+ lineHeight: 1
80
+ }, inLabelStyle), [inLabelStyle, theme]);
81
+ const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
82
+ const getItemSpace = React.useCallback((label, style) => {
83
+ const linesSize = getWordsByLines({
84
+ style,
85
+ needsComputation: true,
86
+ text: label
87
+ });
88
+ const innerSize = {
89
+ innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
90
+ innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
91
+ };
92
+ return _extends({}, innerSize, {
93
+ outerWidth: innerSize.innerWidth + itemGap,
94
+ outerHeight: innerSize.innerHeight + itemGap
95
+ });
96
+ }, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
97
+ const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
98
+ const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
99
+ const availableWidth = totalWidth - padding.left - padding.right;
100
+ const availableHeight = totalHeight - padding.top - padding.bottom;
101
+ const seriesWithPosition = React.useMemo(() => {
102
+ // Start at 0, 0. Will be modified later by padding and position.
103
+ let x = 0;
104
+ let y = 0;
105
+
106
+ // total values used to align legend later.
107
+ let totalWidthUsed = 0;
108
+ let totalHeightUsed = 0;
109
+ let rowIndex = 0;
110
+ const rowMaxHeight = [0];
111
+ const seriesWithRawPosition = seriesToDisplay.map(_ref => {
112
+ let {
113
+ label
114
+ } = _ref,
115
+ other = _objectWithoutPropertiesLoose(_ref, _excluded);
116
+ const itemSpace = getItemSpace(label, labelStyle);
117
+ const rep = _extends({}, other, {
118
+ label,
119
+ positionX: x,
120
+ positionY: y,
121
+ innerHeight: itemSpace.innerHeight,
122
+ innerWidth: itemSpace.innerWidth,
123
+ outerHeight: itemSpace.outerHeight,
124
+ outerWidth: itemSpace.outerWidth,
125
+ rowIndex
126
+ });
127
+ if (direction === 'row') {
128
+ if (x + itemSpace.innerWidth > availableWidth) {
129
+ // This legend item would create overflow along the x-axis, so we start a new row.
130
+ x = 0;
131
+ y += rowMaxHeight[rowIndex];
132
+ rowIndex += 1;
133
+ if (rowMaxHeight.length <= rowIndex) {
134
+ rowMaxHeight.push(0);
135
+ }
136
+ rep.positionX = x;
137
+ rep.positionY = y;
138
+ rep.rowIndex = rowIndex;
139
+ }
140
+ totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
141
+ totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
142
+ rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
143
+ x += itemSpace.outerWidth;
144
+ }
145
+ if (direction === 'column') {
146
+ if (y + itemSpace.innerHeight > availableHeight) {
147
+ // This legend item would create overflow along the y-axis, so we start a new column.
148
+ x = totalWidthUsed + itemGap;
149
+ y = 0;
150
+ rowIndex = 0;
151
+ rep.positionX = x;
152
+ rep.positionY = y;
153
+ rep.rowIndex = rowIndex;
154
+ }
155
+ if (rowMaxHeight.length <= rowIndex) {
156
+ rowMaxHeight.push(0);
157
+ }
158
+ totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
159
+ totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
160
+ rowIndex += 1;
161
+ y += itemSpace.outerHeight;
162
+ }
163
+ return rep;
164
+ });
165
+
166
+ // Move the legend according to padding and position
167
+ let gapX = 0;
168
+ let gapY = 0;
169
+ switch (position.horizontal) {
170
+ case 'left':
171
+ gapX = padding.left;
172
+ break;
173
+ case 'right':
174
+ gapX = totalWidth - padding.right - totalWidthUsed;
175
+ break;
176
+ default:
177
+ gapX = (totalWidth - totalWidthUsed) / 2;
178
+ break;
179
+ }
180
+ switch (position.vertical) {
181
+ case 'top':
182
+ gapY = padding.top;
183
+ break;
184
+ case 'bottom':
185
+ gapY = totalHeight - padding.bottom - totalHeightUsed;
186
+ break;
187
+ default:
188
+ gapY = (totalHeight - totalHeightUsed) / 2;
189
+ break;
190
+ }
191
+ return seriesWithRawPosition.map(item => _extends({}, item, {
192
+ // Add the gap due to the position
193
+ positionX: item.positionX + gapX,
194
+ // Add the gap due to the position
195
+ positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
196
+ : item.outerHeight / 2) // Get the center of the item
197
+ }));
198
+ }, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
153
199
  if (hidden) {
154
200
  return null;
155
201
  }
156
- return /*#__PURE__*/_jsx(ChartsLegendRoot, {
157
- ownerState: {
158
- direction,
159
- offsetX: offset == null ? void 0 : offset.x,
160
- offsetY: offset == null ? void 0 : offset.y,
161
- seriesNumber: seriesToDisplay.length,
162
- position,
163
- drawingArea
164
- },
165
- className: classes.root,
166
- children: seriesToDisplay.map(({
167
- id,
168
- label,
169
- color
170
- }, seriesIndex) => /*#__PURE__*/_jsxs(ChartsSeriesLegendGroup, {
171
- ownerState: _extends({
172
- direction,
173
- seriesIndex
174
- }, series),
175
- className: classes.series,
176
- children: [/*#__PURE__*/_jsx(ChartsLegendMark, {
177
- ownerState: {
178
- color
179
- },
180
- className: classes.mark
181
- }), /*#__PURE__*/_jsx(ChartsLegendLabel, {
182
- className: classes.label,
183
- children: label
184
- })]
185
- }, id))
202
+ return /*#__PURE__*/_jsx(NoSsr, {
203
+ children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
204
+ className: classes.root,
205
+ children: seriesWithPosition.map(({
206
+ id,
207
+ label,
208
+ color,
209
+ positionX,
210
+ positionY
211
+ }) => /*#__PURE__*/_jsxs("g", {
212
+ className: classes.series,
213
+ transform: `translate(${positionX} ${positionY})`,
214
+ children: [/*#__PURE__*/_jsx("rect", {
215
+ className: classes.mark,
216
+ y: -itemMarkHeight / 2,
217
+ width: itemMarkWidth,
218
+ height: itemMarkHeight,
219
+ fill: color
220
+ }), /*#__PURE__*/_jsx(ChartsText, {
221
+ style: labelStyle,
222
+ dominantBaseline: "central",
223
+ textAnchor: "start",
224
+ text: label,
225
+ x: itemMarkWidth + markGap,
226
+ y: 0
227
+ })]
228
+ }, id))
229
+ })
186
230
  });
187
231
  }
188
232
  export function ChartsLegend(inProps) {
@@ -194,7 +238,6 @@ export function ChartsLegend(inProps) {
194
238
  const {
195
239
  position,
196
240
  direction,
197
- offset,
198
241
  hidden,
199
242
  slots,
200
243
  slotProps
@@ -213,7 +256,6 @@ export function ChartsLegend(inProps) {
213
256
  additionalProps: {
214
257
  position,
215
258
  direction,
216
- offset,
217
259
  classes,
218
260
  drawingArea,
219
261
  series,
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className", "sx"];
3
+ const _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"];
4
4
  import { styled } from '@mui/material/styles';
5
5
  import * as React from 'react';
6
6
  import { useAxisEvents } from './hooks/useAxisEvents';
@@ -16,8 +16,7 @@ export const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurfac
16
16
  width,
17
17
  height,
18
18
  viewBox,
19
- disableAxisListener = false,
20
- sx
19
+ disableAxisListener = false
21
20
  } = props,
22
21
  other = _objectWithoutPropertiesLoose(props, _excluded);
23
22
  const svgView = _extends({
@@ -31,14 +30,7 @@ export const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurfac
31
30
  width: width,
32
31
  height: height,
33
32
  viewBox: `${svgView.x} ${svgView.y} ${svgView.width} ${svgView.height}`,
34
- ref: ref,
35
- sx: [{
36
- '--ChartsLegend-itemWidth': '100px',
37
- '--ChartsLegend-itemMarkSize': '20px',
38
- '--ChartsLegend-rootSpacing': '5px',
39
- '--ChartsLegend-labelSpacing': '5px',
40
- '--ChartsLegend-rootOffsetY': '-20px'
41
- }, ...(Array.isArray(sx) ? sx : [sx])]
33
+ ref: ref
42
34
  }, other, {
43
35
  children: [/*#__PURE__*/_jsx("title", {
44
36
  children: props.title
@@ -1,15 +1,17 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["scale", "ticksNumber"];
3
+ const _excluded = ["scale", "tickNumber"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
+ import { useSlotProps } from '@mui/base/utils';
6
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
8
9
  import { CartesianContext } from '../context/CartesianContextProvider';
9
10
  import { DrawingContext } from '../context/DrawingProvider';
10
11
  import useTicks from '../hooks/useTicks';
11
12
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
12
- import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
13
+ import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
+ import { ChartsText } from '../internals/components/ChartsText';
13
15
  import { jsx as _jsx } from "react/jsx-runtime";
14
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
17
  const useUtilityClasses = ownerState => {
@@ -47,7 +49,7 @@ function ChartsXAxis(inProps) {
47
49
  xAxis: {
48
50
  [_props$axisId]: {
49
51
  scale: xScale,
50
- ticksNumber
52
+ tickNumber
51
53
  }
52
54
  }
53
55
  } = _React$useContext,
@@ -78,7 +80,7 @@ function ChartsXAxis(inProps) {
78
80
  const tickSize = disableTicks ? 4 : tickSizeProp;
79
81
  const xTicks = useTicks({
80
82
  scale: xScale,
81
- ticksNumber,
83
+ tickNumber,
82
84
  valueFormatter
83
85
  });
84
86
  const positionSigne = position === 'bottom' ? 1 : -1;
@@ -86,10 +88,38 @@ function ChartsXAxis(inProps) {
86
88
  x: left + width / 2,
87
89
  y: positionSigne * (tickFontSize + tickSize + 10)
88
90
  };
89
- const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
90
- const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
91
- const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
92
- const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
91
+ const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
92
+ const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
93
+ const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
94
+ const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
95
+ const axisTickLabelProps = useSlotProps({
96
+ elementType: TickLabel,
97
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
98
+ additionalProps: {
99
+ textAnchor: 'middle',
100
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
101
+ style: {
102
+ fontSize: tickFontSize
103
+ },
104
+ className: classes.tickLabel
105
+ },
106
+ className: classes.tickLabel,
107
+ ownerState: {}
108
+ });
109
+ const axisLabelProps = useSlotProps({
110
+ elementType: Label,
111
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
112
+ additionalProps: {
113
+ textAnchor: 'middle',
114
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
115
+ style: {
116
+ fontSize: labelFontSize,
117
+ transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
118
+ },
119
+ className: classes.label
120
+ },
121
+ ownerState: {}
122
+ });
93
123
  return /*#__PURE__*/_jsxs(AxisRoot, {
94
124
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
95
125
  className: classes.root,
@@ -113,24 +143,17 @@ function ChartsXAxis(inProps) {
113
143
  }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
114
144
  x: xTickLabel,
115
145
  y: yTickLabel,
116
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
117
- sx: {
118
- fontSize: tickFontSize
119
- },
120
- className: classes.tickLabel
121
- }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
122
- children: formattedValue
146
+ "transform-origin": `${xTickLabel}px ${yTickLabel}px`
147
+ }, axisTickLabelProps, {
148
+ text: formattedValue.toString()
123
149
  }))]
124
150
  }, index);
125
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
126
- sx: {
127
- fontSize: labelFontSize,
128
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
129
- },
130
- className: classes.label
131
- }, slotProps == null ? void 0 : slotProps.axisLabel, {
132
- children: label
133
- }))]
151
+ }), label && /*#__PURE__*/_jsx("g", {
152
+ className: classes.label,
153
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
154
+ text: label
155
+ }))
156
+ })]
134
157
  });
135
158
  }
136
159
  process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
@@ -1,14 +1,16 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["scale", "ticksNumber"];
3
+ const _excluded = ["scale", "tickNumber"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
+ import { useSlotProps } from '@mui/base/utils';
6
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
8
9
  import { CartesianContext } from '../context/CartesianContextProvider';
9
10
  import { DrawingContext } from '../context/DrawingProvider';
10
11
  import useTicks from '../hooks/useTicks';
11
- import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
12
+ import { AxisRoot } from '../internals/components/AxisSharedComponents';
13
+ import { ChartsText } from '../internals/components/ChartsText';
12
14
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
15
  import { jsx as _jsx } from "react/jsx-runtime";
14
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -47,7 +49,7 @@ function ChartsYAxis(inProps) {
47
49
  yAxis: {
48
50
  [_props$axisId]: {
49
51
  scale: yScale,
50
- ticksNumber
52
+ tickNumber
51
53
  }
52
54
  }
53
55
  } = _React$useContext,
@@ -78,7 +80,7 @@ function ChartsYAxis(inProps) {
78
80
  const tickSize = disableTicks ? 4 : tickSizeProp;
79
81
  const yTicks = useTicks({
80
82
  scale: yScale,
81
- ticksNumber,
83
+ tickNumber,
82
84
  valueFormatter
83
85
  });
84
86
  const positionSigne = position === 'right' ? 1 : -1;
@@ -86,10 +88,38 @@ function ChartsYAxis(inProps) {
86
88
  x: positionSigne * (tickFontSize + tickSize + 10),
87
89
  y: top + height / 2
88
90
  };
89
- const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
90
- const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
91
- const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
92
- const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
91
+ const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
92
+ const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
93
+ const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
94
+ const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
95
+ const axisTickLabelProps = useSlotProps({
96
+ elementType: TickLabel,
97
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
98
+ additionalProps: {
99
+ textAnchor: position === 'right' ? 'start' : 'end',
100
+ dominantBaseline: 'central',
101
+ style: {
102
+ fontSize: tickFontSize
103
+ },
104
+ className: classes.tickLabel
105
+ },
106
+ ownerState: {}
107
+ });
108
+ const axisLabelProps = useSlotProps({
109
+ elementType: Label,
110
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
111
+ additionalProps: {
112
+ textAnchor: 'middle',
113
+ dominantBaseline: 'auto',
114
+ style: {
115
+ fontSize: labelFontSize,
116
+ transform: `rotate(${positionSigne * 90}deg)`,
117
+ transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
118
+ },
119
+ className: classes.label
120
+ },
121
+ ownerState: {}
122
+ });
93
123
  return /*#__PURE__*/_jsxs(AxisRoot, {
94
124
  transform: `translate(${position === 'right' ? left + width : left}, 0)`,
95
125
  className: classes.root,
@@ -114,24 +144,15 @@ function ChartsYAxis(inProps) {
114
144
  x: xTickLabel,
115
145
  y: yTickLabel,
116
146
  "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
117
- sx: {
118
- fontSize: tickFontSize
119
- },
120
- className: classes.tickLabel
121
- }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
122
- children: formattedValue.toLocaleString()
123
- }))]
147
+ text: formattedValue.toString()
148
+ }, axisTickLabelProps))]
124
149
  }, index);
125
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
126
- sx: {
127
- fontSize: labelFontSize,
128
- transform: `rotate(${positionSigne * 90}deg)`,
129
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
130
- },
131
- className: classes.label
132
- }, slotProps == null ? void 0 : slotProps.axisLabel, {
133
- children: label
134
- }))]
150
+ }), label && /*#__PURE__*/_jsx("g", {
151
+ className: classes.label,
152
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
153
+ text: label
154
+ }))
155
+ })]
135
156
  });
136
157
  }
137
158
  process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
@@ -168,23 +168,19 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
168
168
  tickNumber: PropTypes.number,
169
169
  tickSize: PropTypes.number
170
170
  }), PropTypes.string]),
171
+ /**
172
+ * @deprecated Consider using `slotProps.legend` instead.
173
+ */
171
174
  legend: PropTypes.shape({
172
175
  classes: PropTypes.object,
173
176
  direction: PropTypes.oneOf(['column', 'row']),
174
177
  hidden: PropTypes.bool,
175
- itemWidth: PropTypes.number,
176
- markSize: PropTypes.number,
177
- offset: PropTypes.shape({
178
- x: PropTypes.number,
179
- y: PropTypes.number
180
- }),
181
178
  position: PropTypes.shape({
182
179
  horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
183
180
  vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
184
181
  }),
185
182
  slotProps: PropTypes.object,
186
- slots: PropTypes.object,
187
- spacing: PropTypes.number
183
+ slots: PropTypes.object
188
184
  }),
189
185
  margin: PropTypes.shape({
190
186
  bottom: PropTypes.number,