@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?.x,
160
- offsetY: 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) {
@@ -193,7 +237,6 @@ export function ChartsLegend(inProps) {
193
237
  const {
194
238
  position,
195
239
  direction,
196
- offset,
197
240
  hidden,
198
241
  slots,
199
242
  slotProps
@@ -212,7 +255,6 @@ export function ChartsLegend(inProps) {
212
255
  additionalProps: {
213
256
  position,
214
257
  direction,
215
- offset,
216
258
  classes,
217
259
  drawingArea,
218
260
  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 => {
@@ -46,7 +48,7 @@ function ChartsXAxis(inProps) {
46
48
  xAxis: {
47
49
  [_props$axisId]: {
48
50
  scale: xScale,
49
- ticksNumber
51
+ tickNumber
50
52
  }
51
53
  }
52
54
  } = _React$useContext,
@@ -77,7 +79,7 @@ function ChartsXAxis(inProps) {
77
79
  const tickSize = disableTicks ? 4 : tickSizeProp;
78
80
  const xTicks = useTicks({
79
81
  scale: xScale,
80
- ticksNumber,
82
+ tickNumber,
81
83
  valueFormatter
82
84
  });
83
85
  const positionSigne = position === 'bottom' ? 1 : -1;
@@ -85,10 +87,38 @@ function ChartsXAxis(inProps) {
85
87
  x: left + width / 2,
86
88
  y: positionSigne * (tickFontSize + tickSize + 10)
87
89
  };
88
- const Line = slots?.axisLine ?? ChartsLine;
89
- const Tick = slots?.axisTick ?? ChartsTick;
90
- const TickLabel = slots?.axisTickLabel ?? ChartsTickLabel;
91
- const Label = slots?.axisLabel ?? ChartsLabel;
90
+ const Line = slots?.axisLine ?? 'line';
91
+ const Tick = slots?.axisTick ?? 'line';
92
+ const TickLabel = slots?.axisTickLabel ?? ChartsText;
93
+ const Label = slots?.axisLabel ?? ChartsText;
94
+ const axisTickLabelProps = useSlotProps({
95
+ elementType: TickLabel,
96
+ externalSlotProps: slotProps?.axisTickLabel,
97
+ additionalProps: {
98
+ textAnchor: 'middle',
99
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
100
+ style: {
101
+ fontSize: tickFontSize
102
+ },
103
+ className: classes.tickLabel
104
+ },
105
+ className: classes.tickLabel,
106
+ ownerState: {}
107
+ });
108
+ const axisLabelProps = useSlotProps({
109
+ elementType: Label,
110
+ externalSlotProps: slotProps?.axisLabel,
111
+ additionalProps: {
112
+ textAnchor: 'middle',
113
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
114
+ style: {
115
+ fontSize: labelFontSize,
116
+ transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
117
+ },
118
+ className: classes.label
119
+ },
120
+ ownerState: {}
121
+ });
92
122
  return /*#__PURE__*/_jsxs(AxisRoot, {
93
123
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
94
124
  className: classes.root,
@@ -112,24 +142,17 @@ function ChartsXAxis(inProps) {
112
142
  }, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
113
143
  x: xTickLabel,
114
144
  y: yTickLabel,
115
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
116
- sx: {
117
- fontSize: tickFontSize
118
- },
119
- className: classes.tickLabel
120
- }, slotProps?.axisTickLabel, {
121
- children: formattedValue
145
+ "transform-origin": `${xTickLabel}px ${yTickLabel}px`
146
+ }, axisTickLabelProps, {
147
+ text: formattedValue.toString()
122
148
  }))]
123
149
  }, index);
124
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
125
- sx: {
126
- fontSize: labelFontSize,
127
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
128
- },
129
- className: classes.label
130
- }, slotProps?.axisLabel, {
131
- children: label
132
- }))]
150
+ }), label && /*#__PURE__*/_jsx("g", {
151
+ className: classes.label,
152
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
153
+ text: label
154
+ }))
155
+ })]
133
156
  });
134
157
  }
135
158
  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";
@@ -46,7 +48,7 @@ function ChartsYAxis(inProps) {
46
48
  yAxis: {
47
49
  [_props$axisId]: {
48
50
  scale: yScale,
49
- ticksNumber
51
+ tickNumber
50
52
  }
51
53
  }
52
54
  } = _React$useContext,
@@ -77,7 +79,7 @@ function ChartsYAxis(inProps) {
77
79
  const tickSize = disableTicks ? 4 : tickSizeProp;
78
80
  const yTicks = useTicks({
79
81
  scale: yScale,
80
- ticksNumber,
82
+ tickNumber,
81
83
  valueFormatter
82
84
  });
83
85
  const positionSigne = position === 'right' ? 1 : -1;
@@ -85,10 +87,38 @@ function ChartsYAxis(inProps) {
85
87
  x: positionSigne * (tickFontSize + tickSize + 10),
86
88
  y: top + height / 2
87
89
  };
88
- const Line = slots?.axisLine ?? ChartsLine;
89
- const Tick = slots?.axisTick ?? ChartsTick;
90
- const TickLabel = slots?.axisTickLabel ?? ChartsTickLabel;
91
- const Label = slots?.axisLabel ?? ChartsLabel;
90
+ const Line = slots?.axisLine ?? 'line';
91
+ const Tick = slots?.axisTick ?? 'line';
92
+ const TickLabel = slots?.axisTickLabel ?? ChartsText;
93
+ const Label = slots?.axisLabel ?? ChartsText;
94
+ const axisTickLabelProps = useSlotProps({
95
+ elementType: TickLabel,
96
+ externalSlotProps: slotProps?.axisTickLabel,
97
+ additionalProps: {
98
+ textAnchor: position === 'right' ? 'start' : 'end',
99
+ dominantBaseline: 'central',
100
+ style: {
101
+ fontSize: tickFontSize
102
+ },
103
+ className: classes.tickLabel
104
+ },
105
+ ownerState: {}
106
+ });
107
+ const axisLabelProps = useSlotProps({
108
+ elementType: Label,
109
+ externalSlotProps: slotProps?.axisLabel,
110
+ additionalProps: {
111
+ textAnchor: 'middle',
112
+ dominantBaseline: 'auto',
113
+ style: {
114
+ fontSize: labelFontSize,
115
+ transform: `rotate(${positionSigne * 90}deg)`,
116
+ transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
117
+ },
118
+ className: classes.label
119
+ },
120
+ ownerState: {}
121
+ });
92
122
  return /*#__PURE__*/_jsxs(AxisRoot, {
93
123
  transform: `translate(${position === 'right' ? left + width : left}, 0)`,
94
124
  className: classes.root,
@@ -113,24 +143,15 @@ function ChartsYAxis(inProps) {
113
143
  x: xTickLabel,
114
144
  y: yTickLabel,
115
145
  "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
116
- sx: {
117
- fontSize: tickFontSize
118
- },
119
- className: classes.tickLabel
120
- }, slotProps?.axisTickLabel, {
121
- children: formattedValue.toLocaleString()
122
- }))]
146
+ text: formattedValue.toString()
147
+ }, axisTickLabelProps))]
123
148
  }, index);
124
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
125
- sx: {
126
- fontSize: labelFontSize,
127
- transform: `rotate(${positionSigne * 90}deg)`,
128
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
129
- },
130
- className: classes.label
131
- }, slotProps?.axisLabel, {
132
- children: label
133
- }))]
149
+ }), label && /*#__PURE__*/_jsx("g", {
150
+ className: classes.label,
151
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
152
+ text: label
153
+ }))
154
+ })]
134
155
  });
135
156
  }
136
157
  process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
@@ -165,23 +165,19 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
165
165
  tickNumber: PropTypes.number,
166
166
  tickSize: PropTypes.number
167
167
  }), PropTypes.string]),
168
+ /**
169
+ * @deprecated Consider using `slotProps.legend` instead.
170
+ */
168
171
  legend: PropTypes.shape({
169
172
  classes: PropTypes.object,
170
173
  direction: PropTypes.oneOf(['column', 'row']),
171
174
  hidden: PropTypes.bool,
172
- itemWidth: PropTypes.number,
173
- markSize: PropTypes.number,
174
- offset: PropTypes.shape({
175
- x: PropTypes.number,
176
- y: PropTypes.number
177
- }),
178
175
  position: PropTypes.shape({
179
176
  horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
180
177
  vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
181
178
  }),
182
179
  slotProps: PropTypes.object,
183
- slots: PropTypes.object,
184
- spacing: PropTypes.number
180
+ slots: PropTypes.object
185
181
  }),
186
182
  margin: PropTypes.shape({
187
183
  bottom: PropTypes.number,