@mui/x-charts 8.9.0 → 8.10.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 (128) hide show
  1. package/BarChart/BarChart.js +110 -1
  2. package/BarChart/BarClipPath.d.ts +17 -12
  3. package/BarChart/BarClipPath.js +70 -57
  4. package/BarChart/BarPlot.js +4 -0
  5. package/BarChart/seriesConfig/extremums.js +2 -3
  6. package/BarChart/useBarChartProps.d.ts +1 -1
  7. package/CHANGELOG.md +245 -6
  8. package/ChartContainer/ChartContainer.js +165 -0
  9. package/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
  10. package/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
  11. package/ChartsTooltip/ChartsTooltip.d.ts +2 -1
  12. package/ChartsTooltip/ChartsTooltip.js +3 -3
  13. package/ChartsTooltip/ChartsTooltipContainer.d.ts +5 -5
  14. package/ChartsTooltip/ChartsTooltipContainer.js +3 -3
  15. package/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.d.ts +13 -4
  16. package/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.js +33 -7
  17. package/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
  18. package/ChartsXAxis/ChartsGroupedXAxis.js +142 -0
  19. package/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
  20. package/ChartsXAxis/ChartsSingleXAxis.js +144 -0
  21. package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  22. package/ChartsXAxis/ChartsXAxis.js +8 -210
  23. package/ChartsXAxis/getVisibleLabels.d.ts +2 -2
  24. package/ChartsXAxis/useAxisProps.d.ts +4526 -0
  25. package/ChartsXAxis/useAxisProps.js +105 -0
  26. package/ChartsXAxis/utilities.d.ts +11 -0
  27. package/ChartsXAxis/utilities.js +43 -0
  28. package/LineChart/LineChart.js +110 -1
  29. package/LineChart/seriesConfig/extremums.js +2 -3
  30. package/LineChart/useLineChartProps.d.ts +1 -1
  31. package/PieChart/PieChart.js +1 -1
  32. package/RadarChart/RadarChart.d.ts +1 -1
  33. package/RadarChart/RadarChart.js +1 -1
  34. package/RadarChart/index.d.ts +9 -2
  35. package/RadarChart/index.js +13 -14
  36. package/RadarChart/useRadarChartProps.d.ts +1 -1
  37. package/ScatterChart/ScatterChart.d.ts +8 -1
  38. package/ScatterChart/ScatterChart.js +110 -1
  39. package/ScatterChart/seriesConfig/extremums.js +50 -23
  40. package/ScatterChart/useScatterChartProps.d.ts +1 -1
  41. package/SparkLineChart/SparkLineChart.js +109 -0
  42. package/esm/BarChart/BarChart.js +110 -1
  43. package/esm/BarChart/BarClipPath.d.ts +17 -12
  44. package/esm/BarChart/BarClipPath.js +69 -55
  45. package/esm/BarChart/BarPlot.js +4 -0
  46. package/esm/BarChart/seriesConfig/extremums.js +2 -3
  47. package/esm/BarChart/useBarChartProps.d.ts +1 -1
  48. package/esm/ChartContainer/ChartContainer.js +165 -0
  49. package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
  50. package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
  51. package/esm/ChartsTooltip/ChartsTooltip.d.ts +2 -1
  52. package/esm/ChartsTooltip/ChartsTooltip.js +3 -3
  53. package/esm/ChartsTooltip/ChartsTooltipContainer.d.ts +5 -5
  54. package/esm/ChartsTooltip/ChartsTooltipContainer.js +3 -3
  55. package/esm/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.d.ts +13 -4
  56. package/esm/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.js +31 -6
  57. package/esm/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
  58. package/esm/ChartsXAxis/ChartsGroupedXAxis.js +136 -0
  59. package/esm/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
  60. package/esm/ChartsXAxis/ChartsSingleXAxis.js +140 -0
  61. package/esm/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  62. package/esm/ChartsXAxis/ChartsXAxis.js +7 -207
  63. package/esm/ChartsXAxis/getVisibleLabels.d.ts +2 -2
  64. package/esm/ChartsXAxis/useAxisProps.d.ts +4526 -0
  65. package/esm/ChartsXAxis/useAxisProps.js +98 -0
  66. package/esm/ChartsXAxis/utilities.d.ts +11 -0
  67. package/esm/ChartsXAxis/utilities.js +35 -0
  68. package/esm/LineChart/LineChart.js +110 -1
  69. package/esm/LineChart/seriesConfig/extremums.js +2 -3
  70. package/esm/LineChart/useLineChartProps.d.ts +1 -1
  71. package/esm/PieChart/PieChart.js +1 -1
  72. package/esm/RadarChart/RadarChart.d.ts +1 -1
  73. package/esm/RadarChart/RadarChart.js +1 -1
  74. package/esm/RadarChart/index.d.ts +9 -2
  75. package/esm/RadarChart/index.js +12 -2
  76. package/esm/RadarChart/useRadarChartProps.d.ts +1 -1
  77. package/esm/ScatterChart/ScatterChart.d.ts +8 -1
  78. package/esm/ScatterChart/ScatterChart.js +110 -1
  79. package/esm/ScatterChart/seriesConfig/extremums.js +50 -23
  80. package/esm/ScatterChart/useScatterChartProps.d.ts +1 -1
  81. package/esm/SparkLineChart/SparkLineChart.js +109 -0
  82. package/esm/hooks/useTicksGrouped.d.ts +28 -0
  83. package/esm/hooks/useTicksGrouped.js +98 -0
  84. package/esm/index.d.ts +2 -1
  85. package/esm/index.js +6 -2
  86. package/esm/internals/findMinMax.d.ts +1 -0
  87. package/esm/internals/findMinMax.js +13 -0
  88. package/esm/internals/getScale.d.ts +1 -1
  89. package/esm/internals/getScale.js +3 -0
  90. package/esm/internals/index.d.ts +1 -1
  91. package/esm/internals/index.js +1 -1
  92. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -1
  93. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
  94. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +32 -23
  95. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
  96. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +17 -12
  97. package/esm/internals/symlogScale.d.ts +2 -0
  98. package/esm/internals/symlogScale.js +94 -0
  99. package/esm/models/axis.d.ts +81 -4
  100. package/esm/models/axis.js +3 -0
  101. package/hooks/useTicksGrouped.d.ts +28 -0
  102. package/hooks/useTicksGrouped.js +104 -0
  103. package/index.d.ts +2 -1
  104. package/index.js +13 -1
  105. package/internals/findMinMax.d.ts +1 -0
  106. package/internals/findMinMax.js +19 -0
  107. package/internals/getScale.d.ts +1 -1
  108. package/internals/getScale.js +3 -0
  109. package/internals/index.d.ts +1 -1
  110. package/internals/index.js +12 -12
  111. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +3 -0
  112. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
  113. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +34 -23
  114. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
  115. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +17 -12
  116. package/internals/symlogScale.d.ts +2 -0
  117. package/internals/symlogScale.js +100 -0
  118. package/models/axis.d.ts +81 -4
  119. package/models/axis.js +4 -0
  120. package/package.json +5 -7
  121. package/BarChart/getRadius.d.ts +0 -20
  122. package/BarChart/getRadius.js +0 -37
  123. package/esm/BarChart/getRadius.d.ts +0 -20
  124. package/esm/BarChart/getRadius.js +0 -30
  125. /package/{esm/internals/components/ChartsWrapper → ChartsWrapper}/index.d.ts +0 -0
  126. /package/{internals/components/ChartsWrapper → ChartsWrapper}/index.js +0 -0
  127. /package/{internals/components → esm}/ChartsWrapper/index.d.ts +0 -0
  128. /package/esm/{internals/components/ChartsWrapper → ChartsWrapper}/index.js +0 -0
@@ -1,17 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.ChartsWrapper = ChartsWrapper;
8
9
  var React = _interopRequireWildcard(require("react"));
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
11
  var _styles = require("@mui/material/styles");
10
12
  var _createStyled = require("@mui/system/createStyled");
11
- var _useChartRootRef = require("../../../hooks/useChartRootRef");
12
- var _useStore = require("../../store/useStore");
13
- var _useSelector = require("../../store/useSelector");
14
- var _useChartDimensions = require("../../plugins/corePlugins/useChartDimensions");
13
+ var _useChartRootRef = require("../hooks/useChartRootRef");
14
+ var _useStore = require("../internals/store/useStore");
15
+ var _useSelector = require("../internals/store/useSelector");
16
+ var _useChartDimensions = require("../internals/plugins/corePlugins/useChartDimensions");
15
17
  var _jsxRuntime = require("react/jsx-runtime");
16
18
  const getDirection = (direction, position) => {
17
19
  if (direction === 'vertical') {
@@ -67,8 +69,6 @@ const Root = (0, _styles.styled)('div', {
67
69
  }));
68
70
 
69
71
  /**
70
- * @ignore - internal component.
71
- *
72
72
  * Wrapper for the charts components.
73
73
  * Its main purpose is to position the HTML legend in the correct place.
74
74
  */
@@ -90,4 +90,30 @@ function ChartsWrapper(props) {
90
90
  extendVertically: extendVertically ?? propsHeight === undefined,
91
91
  children: children
92
92
  });
93
- }
93
+ }
94
+ process.env.NODE_ENV !== "production" ? ChartsWrapper.propTypes = {
95
+ // ----------------------------- Warning --------------------------------
96
+ // | These PropTypes are generated from the TypeScript type definitions |
97
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
98
+ // ----------------------------------------------------------------------
99
+ children: _propTypes.default.node,
100
+ /**
101
+ * If `true`, the chart wrapper set `height: 100%`.
102
+ * @default `false` if the `height` prop is set. And `true` otherwise.
103
+ */
104
+ extendVertically: _propTypes.default.bool,
105
+ /**
106
+ * The direction of the legend.
107
+ * @default 'horizontal'
108
+ */
109
+ legendDirection: _propTypes.default.oneOf(['horizontal', 'vertical']),
110
+ /**
111
+ * The position of the legend.
112
+ * @default { horizontal: 'center', vertical: 'bottom' }
113
+ */
114
+ legendPosition: _propTypes.default.shape({
115
+ horizontal: _propTypes.default.oneOf(['center', 'end', 'start']),
116
+ vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top'])
117
+ }),
118
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
119
+ } : void 0;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { ChartsXAxisProps } from "../models/axis.js";
3
+ /**
4
+ * @ignore - internal component.
5
+ */
6
+ declare function ChartsGroupedXAxis(inProps: ChartsXAxisProps): React.JSX.Element | null;
7
+ export { ChartsGroupedXAxis };
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.ChartsGroupedXAxis = ChartsGroupedXAxis;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var React = _interopRequireWildcard(require("react"));
12
+ var _useDrawingArea = require("../hooks/useDrawingArea");
13
+ var _isBandScale = require("../internals/isBandScale");
14
+ var _useChartContext = require("../context/ChartProvider/useChartContext");
15
+ var _utilities = require("./utilities");
16
+ var _useTicksGrouped = require("../hooks/useTicksGrouped");
17
+ var _useAxisProps = require("./useAxisProps");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ const DEFAULT_GROUPING_CONFIG = {
20
+ tickSize: 6
21
+ };
22
+ const getGroupingConfig = (groups, groupIndex, tickSize) => {
23
+ const config = groups[groupIndex] ?? {};
24
+ const defaultTickSize = tickSize ?? DEFAULT_GROUPING_CONFIG.tickSize;
25
+ const calculatedTickSize = defaultTickSize * groupIndex * 2 + defaultTickSize;
26
+ return (0, _extends2.default)({}, DEFAULT_GROUPING_CONFIG, config, {
27
+ tickSize: config.tickSize ?? calculatedTickSize
28
+ });
29
+ };
30
+
31
+ /**
32
+ * @ignore - internal component.
33
+ */
34
+ function ChartsGroupedXAxis(inProps) {
35
+ const {
36
+ xScale,
37
+ defaultizedProps,
38
+ tickNumber,
39
+ positionSign,
40
+ skipAxisRendering,
41
+ classes,
42
+ Line,
43
+ Tick,
44
+ TickLabel,
45
+ Label,
46
+ axisTickLabelProps,
47
+ axisLabelProps
48
+ } = (0, _useAxisProps.useAxisProps)(inProps);
49
+ if (!(0, _isBandScale.isBandScale)(xScale)) {
50
+ throw new Error('MUI X Charts: ChartsGroupedXAxis only supports the `band` and `point` scale types.');
51
+ }
52
+ const {
53
+ position,
54
+ disableLine,
55
+ disableTicks,
56
+ label,
57
+ tickSize,
58
+ valueFormatter,
59
+ slotProps,
60
+ tickInterval,
61
+ tickPlacement,
62
+ tickLabelPlacement,
63
+ sx,
64
+ offset,
65
+ height: axisHeight
66
+ } = defaultizedProps;
67
+ const groups = defaultizedProps.groups;
68
+ const drawingArea = (0, _useDrawingArea.useDrawingArea)();
69
+ const {
70
+ left,
71
+ top,
72
+ width,
73
+ height
74
+ } = drawingArea;
75
+ const {
76
+ instance
77
+ } = (0, _useChartContext.useChartContext)();
78
+ const labelRefPoint = {
79
+ x: left + width / 2,
80
+ y: positionSign * axisHeight
81
+ };
82
+ const xTicks = (0, _useTicksGrouped.useTicksGrouped)({
83
+ scale: xScale,
84
+ tickNumber,
85
+ valueFormatter,
86
+ tickInterval,
87
+ tickPlacement,
88
+ tickLabelPlacement,
89
+ direction: 'x',
90
+ groups
91
+ });
92
+
93
+ // Skip axis rendering if no data is available
94
+ // - The domain is an empty array for band/point scales.
95
+ // - The domains contains Infinity for continuous scales.
96
+ // - The position is set to 'none'.
97
+ if (skipAxisRendering) {
98
+ return null;
99
+ }
100
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_utilities.XAxisRoot, {
101
+ transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
102
+ className: classes.root,
103
+ sx: sx,
104
+ children: [!disableLine && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _extends2.default)({
105
+ x1: left,
106
+ x2: left + width,
107
+ className: classes.line
108
+ }, slotProps?.axisLine)), xTicks.map((item, index) => {
109
+ const {
110
+ offset: tickOffset,
111
+ labelOffset
112
+ } = item;
113
+ const xTickLabel = labelOffset ?? 0;
114
+ const showTick = instance.isXInside(tickOffset);
115
+ const tickLabel = item.formattedValue;
116
+ const ignoreTick = item.ignoreTick ?? false;
117
+ const groupIndex = item.groupIndex ?? 0;
118
+ const groupConfig = getGroupingConfig(groups, groupIndex, tickSize);
119
+ const tickYSize = positionSign * groupConfig.tickSize;
120
+ const labelPositionY = positionSign * (groupConfig.tickSize + _utilities.TICK_LABEL_GAP);
121
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
122
+ transform: `translate(${tickOffset}, 0)`,
123
+ className: classes.tickContainer,
124
+ "data-group-index": groupIndex,
125
+ children: [!disableTicks && !ignoreTick && showTick && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tick, (0, _extends2.default)({
126
+ y2: tickYSize,
127
+ className: classes.tick
128
+ }, slotProps?.axisTick)), tickLabel !== undefined && /*#__PURE__*/(0, _jsxRuntime.jsx)(TickLabel, (0, _extends2.default)({
129
+ x: xTickLabel,
130
+ y: labelPositionY
131
+ }, axisTickLabelProps, {
132
+ text: tickLabel
133
+ }))]
134
+ }, index);
135
+ }), label && /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
136
+ className: classes.label,
137
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, (0, _extends2.default)({}, labelRefPoint, axisLabelProps, {
138
+ text: label
139
+ }))
140
+ })]
141
+ });
142
+ }
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { ChartsXAxisProps } from "../models/axis.js";
3
+ /**
4
+ * @ignore - internal component.
5
+ */
6
+ declare function ChartsSingleXAxis(inProps: ChartsXAxisProps): React.JSX.Element | null;
7
+ export { ChartsSingleXAxis };
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.ChartsSingleXAxis = ChartsSingleXAxis;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var React = _interopRequireWildcard(require("react"));
12
+ var _useIsHydrated = require("../hooks/useIsHydrated");
13
+ var _domUtils = require("../internals/domUtils");
14
+ var _useTicks = require("../hooks/useTicks");
15
+ var _useMounted = require("../hooks/useMounted");
16
+ var _useDrawingArea = require("../hooks/useDrawingArea");
17
+ var _useChartContext = require("../context/ChartProvider/useChartContext");
18
+ var _shortenLabels = require("./shortenLabels");
19
+ var _getVisibleLabels = require("./getVisibleLabels");
20
+ var _utilities = require("./utilities");
21
+ var _useAxisProps = require("./useAxisProps");
22
+ var _jsxRuntime = require("react/jsx-runtime");
23
+ /**
24
+ * @ignore - internal component.
25
+ */function ChartsSingleXAxis(inProps) {
26
+ const {
27
+ xScale,
28
+ defaultizedProps,
29
+ tickNumber,
30
+ positionSign,
31
+ skipAxisRendering,
32
+ classes,
33
+ Line,
34
+ Tick,
35
+ TickLabel,
36
+ Label,
37
+ axisTickLabelProps,
38
+ axisLabelProps,
39
+ reverse,
40
+ isRtl
41
+ } = (0, _useAxisProps.useAxisProps)(inProps);
42
+ const isMounted = (0, _useMounted.useMounted)();
43
+ const {
44
+ position,
45
+ disableLine,
46
+ disableTicks,
47
+ label,
48
+ tickSize: tickSizeProp,
49
+ valueFormatter,
50
+ slotProps,
51
+ tickInterval,
52
+ tickLabelInterval,
53
+ tickPlacement,
54
+ tickLabelPlacement,
55
+ tickLabelMinGap,
56
+ sx,
57
+ offset,
58
+ height: axisHeight
59
+ } = defaultizedProps;
60
+ const drawingArea = (0, _useDrawingArea.useDrawingArea)();
61
+ const {
62
+ left,
63
+ top,
64
+ width,
65
+ height
66
+ } = drawingArea;
67
+ const {
68
+ instance
69
+ } = (0, _useChartContext.useChartContext)();
70
+ const isHydrated = (0, _useIsHydrated.useIsHydrated)();
71
+ const tickSize = disableTicks ? 4 : tickSizeProp;
72
+ const xTicks = (0, _useTicks.useTicks)({
73
+ scale: xScale,
74
+ tickNumber,
75
+ valueFormatter,
76
+ tickInterval,
77
+ tickPlacement,
78
+ tickLabelPlacement,
79
+ direction: 'x'
80
+ });
81
+ const visibleLabels = (0, _getVisibleLabels.getVisibleLabels)(xTicks, {
82
+ tickLabelStyle: axisTickLabelProps.style,
83
+ tickLabelInterval,
84
+ tickLabelMinGap,
85
+ reverse,
86
+ isMounted,
87
+ isXInside: instance.isXInside
88
+ });
89
+
90
+ // Skip axis rendering if no data is available
91
+ // - The domain is an empty array for band/point scales.
92
+ // - The domains contains Infinity for continuous scales.
93
+ // - The position is set to 'none'.
94
+ if (skipAxisRendering) {
95
+ return null;
96
+ }
97
+ const labelHeight = label ? (0, _domUtils.getStringSize)(label, axisLabelProps.style).height : 0;
98
+ const labelRefPoint = {
99
+ x: left + width / 2,
100
+ y: positionSign * axisHeight
101
+ };
102
+
103
+ /* If there's an axis title, the tick labels have less space to render */
104
+ const tickLabelsMaxHeight = Math.max(0, axisHeight - (label ? labelHeight + _utilities.AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - _utilities.TICK_LABEL_GAP);
105
+ const tickLabels = isHydrated ? (0, _shortenLabels.shortenLabels)(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
106
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_utilities.XAxisRoot, {
107
+ transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
108
+ className: classes.root,
109
+ sx: sx,
110
+ children: [!disableLine && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _extends2.default)({
111
+ x1: left,
112
+ x2: left + width,
113
+ className: classes.line
114
+ }, slotProps?.axisLine)), xTicks.map((item, index) => {
115
+ const {
116
+ offset: tickOffset,
117
+ labelOffset
118
+ } = item;
119
+ const xTickLabel = labelOffset ?? 0;
120
+ const yTickLabel = positionSign * (tickSize + _utilities.TICK_LABEL_GAP);
121
+ const showTick = instance.isXInside(tickOffset);
122
+ const tickLabel = tickLabels.get(item);
123
+ const showTickLabel = visibleLabels.has(item);
124
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
125
+ transform: `translate(${tickOffset}, 0)`,
126
+ className: classes.tickContainer,
127
+ children: [!disableTicks && showTick && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tick, (0, _extends2.default)({
128
+ y2: positionSign * tickSize,
129
+ className: classes.tick
130
+ }, slotProps?.axisTick)), tickLabel !== undefined && showTickLabel && /*#__PURE__*/(0, _jsxRuntime.jsx)(TickLabel, (0, _extends2.default)({
131
+ x: xTickLabel,
132
+ y: yTickLabel
133
+ }, axisTickLabelProps, {
134
+ text: tickLabel
135
+ }))]
136
+ }, index);
137
+ }), label && /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
138
+ className: classes.label,
139
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, (0, _extends2.default)({}, labelRefPoint, axisLabelProps, {
140
+ text: label
141
+ }))
142
+ })]
143
+ });
144
+ }
@@ -9,7 +9,7 @@ import { ChartsXAxisProps } from "../models/axis.js";
9
9
  *
10
10
  * - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
11
11
  */
12
- declare function ChartsXAxis(inProps: ChartsXAxisProps): React.JSX.Element | null;
12
+ declare function ChartsXAxis(inProps: ChartsXAxisProps): React.JSX.Element;
13
13
  declare namespace ChartsXAxis {
14
14
  var propTypes: any;
15
15
  }
@@ -1,70 +1,19 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
6
  Object.defineProperty(exports, "__esModule", {
7
7
  value: true
8
8
  });
9
9
  exports.ChartsXAxis = ChartsXAxis;
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
11
  var React = _interopRequireWildcard(require("react"));
13
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
- var _useSlotProps = _interopRequireDefault(require("@mui/utils/useSlotProps"));
15
- var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
16
- var _styles = require("@mui/material/styles");
17
- var _RtlProvider = require("@mui/system/RtlProvider");
18
- var _useIsHydrated = require("../hooks/useIsHydrated");
19
- var _domUtils = require("../internals/domUtils");
20
- var _useTicks = require("../hooks/useTicks");
21
- var _axisClasses = require("../ChartsAxis/axisClasses");
22
- var _AxisSharedComponents = require("../internals/components/AxisSharedComponents");
23
- var _ChartsText = require("../ChartsText");
24
- var _useMounted = require("../hooks/useMounted");
25
- var _useDrawingArea = require("../hooks/useDrawingArea");
26
- var _isInfinity = require("../internals/isInfinity");
27
- var _isBandScale = require("../internals/isBandScale");
28
- var _useChartContext = require("../context/ChartProvider/useChartContext");
29
13
  var _useAxis = require("../hooks/useAxis");
30
- var _defaultTextPlacement = require("../ChartsText/defaultTextPlacement");
31
- var _invertTextAnchor = require("../internals/invertTextAnchor");
32
- var _shortenLabels = require("./shortenLabels");
33
- var _getVisibleLabels = require("./getVisibleLabels");
14
+ var _ChartsSingleXAxis = require("./ChartsSingleXAxis");
15
+ var _ChartsGroupedXAxis = require("./ChartsGroupedXAxis");
34
16
  var _jsxRuntime = require("react/jsx-runtime");
35
- const _excluded = ["scale", "tickNumber", "reverse"];
36
- const useUtilityClasses = ownerState => {
37
- const {
38
- classes,
39
- position,
40
- id
41
- } = ownerState;
42
- const slots = {
43
- root: ['root', 'directionX', position, `id-${id}`],
44
- line: ['line'],
45
- tickContainer: ['tickContainer'],
46
- tick: ['tick'],
47
- tickLabel: ['tickLabel'],
48
- label: ['label']
49
- };
50
- return (0, _composeClasses.default)(slots, _axisClasses.getAxisUtilityClass, classes);
51
- };
52
-
53
- /* Gap between a tick and its label. */
54
- const TICK_LABEL_GAP = 3;
55
- /* Gap between the axis label and tick labels. */
56
- const AXIS_LABEL_TICK_LABEL_GAP = 4;
57
- const XAxisRoot = (0, _styles.styled)(_AxisSharedComponents.AxisRoot, {
58
- name: 'MuiChartsXAxis',
59
- slot: 'Root'
60
- })({});
61
- const defaultProps = {
62
- disableLine: false,
63
- disableTicks: false,
64
- tickSize: 6,
65
- tickLabelMinGap: 4
66
- };
67
-
68
17
  /**
69
18
  * Demos:
70
19
  *
@@ -73,167 +22,16 @@ const defaultProps = {
73
22
  * API:
74
23
  *
75
24
  * - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
76
- */
77
- function ChartsXAxis(inProps) {
25
+ */function ChartsXAxis(inProps) {
78
26
  const {
79
27
  xAxis,
80
28
  xAxisIds
81
29
  } = (0, _useAxis.useXAxes)();
82
- const _xAxis = xAxis[inProps.axisId ?? xAxisIds[0]],
83
- {
84
- scale: xScale,
85
- tickNumber,
86
- reverse
87
- } = _xAxis,
88
- settings = (0, _objectWithoutPropertiesLoose2.default)(_xAxis, _excluded);
89
- const isMounted = (0, _useMounted.useMounted)();
90
- const themedProps = (0, _styles.useThemeProps)({
91
- props: (0, _extends2.default)({}, settings, inProps),
92
- name: 'MuiChartsXAxis'
93
- });
94
- const defaultizedProps = (0, _extends2.default)({}, defaultProps, themedProps);
95
- const {
96
- position,
97
- disableLine,
98
- disableTicks,
99
- tickLabelStyle,
100
- label,
101
- labelStyle,
102
- tickSize: tickSizeProp,
103
- valueFormatter,
104
- slots,
105
- slotProps,
106
- tickInterval,
107
- tickLabelInterval,
108
- tickPlacement,
109
- tickLabelPlacement,
110
- tickLabelMinGap,
111
- sx,
112
- offset,
113
- height: axisHeight
114
- } = defaultizedProps;
115
- const theme = (0, _styles.useTheme)();
116
- const isRtl = (0, _RtlProvider.useRtl)();
117
- const classes = useUtilityClasses(defaultizedProps);
118
- const drawingArea = (0, _useDrawingArea.useDrawingArea)();
119
- const {
120
- left,
121
- top,
122
- width,
123
- height
124
- } = drawingArea;
125
- const {
126
- instance
127
- } = (0, _useChartContext.useChartContext)();
128
- const isHydrated = (0, _useIsHydrated.useIsHydrated)();
129
- const tickSize = disableTicks ? 4 : tickSizeProp;
130
- const positionSign = position === 'bottom' ? 1 : -1;
131
- const Line = slots?.axisLine ?? 'line';
132
- const Tick = slots?.axisTick ?? 'line';
133
- const TickLabel = slots?.axisTickLabel ?? _ChartsText.ChartsText;
134
- const Label = slots?.axisLabel ?? _ChartsText.ChartsText;
135
- const defaultTextAnchor = (0, _defaultTextPlacement.getDefaultTextAnchor)((position === 'bottom' ? 0 : 180) - (tickLabelStyle?.angle ?? 0));
136
- const defaultDominantBaseline = (0, _defaultTextPlacement.getDefaultBaseline)((position === 'bottom' ? 0 : 180) - (tickLabelStyle?.angle ?? 0));
137
- const axisTickLabelProps = (0, _useSlotProps.default)({
138
- elementType: TickLabel,
139
- externalSlotProps: slotProps?.axisTickLabel,
140
- additionalProps: {
141
- style: (0, _extends2.default)({}, theme.typography.caption, {
142
- fontSize: 12,
143
- lineHeight: 1.25,
144
- textAnchor: isRtl ? (0, _invertTextAnchor.invertTextAnchor)(defaultTextAnchor) : defaultTextAnchor,
145
- dominantBaseline: defaultDominantBaseline
146
- }, tickLabelStyle)
147
- },
148
- className: classes.tickLabel,
149
- ownerState: {}
150
- });
151
- const xTicks = (0, _useTicks.useTicks)({
152
- scale: xScale,
153
- tickNumber,
154
- valueFormatter,
155
- tickInterval,
156
- tickPlacement,
157
- tickLabelPlacement,
158
- direction: 'x'
159
- });
160
- const visibleLabels = (0, _getVisibleLabels.getVisibleLabels)(xTicks, {
161
- tickLabelStyle: axisTickLabelProps.style,
162
- tickLabelInterval,
163
- tickLabelMinGap,
164
- reverse,
165
- isMounted,
166
- isXInside: instance.isXInside
167
- });
168
- const axisLabelProps = (0, _useSlotProps.default)({
169
- elementType: Label,
170
- externalSlotProps: slotProps?.axisLabel,
171
- additionalProps: {
172
- style: (0, _extends2.default)({}, theme.typography.body1, {
173
- lineHeight: 1,
174
- fontSize: 14,
175
- textAnchor: 'middle',
176
- dominantBaseline: position === 'bottom' ? 'text-after-edge' : 'text-before-edge'
177
- }, labelStyle)
178
- },
179
- ownerState: {}
180
- });
181
- const domain = xScale.domain();
182
- const ordinalAxis = (0, _isBandScale.isBandScale)(xScale);
183
- // Skip axis rendering if no data is available
184
- // - The domain is an empty array for band/point scales.
185
- // - The domains contains Infinity for continuous scales.
186
- // - The position is set to 'none'.
187
- if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(_isInfinity.isInfinity) || position === 'none') {
188
- return null;
30
+ const axis = xAxis[inProps.axisId ?? xAxisIds[0]];
31
+ if ('groups' in axis && Array.isArray(axis.groups)) {
32
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsGroupedXAxis.ChartsGroupedXAxis, (0, _extends2.default)({}, inProps));
189
33
  }
190
- const labelHeight = label ? (0, _domUtils.getStringSize)(label, axisLabelProps.style).height : 0;
191
- const labelRefPoint = {
192
- x: left + width / 2,
193
- y: positionSign * axisHeight
194
- };
195
-
196
- /* If there's an axis title, the tick labels have less space to render */
197
- const tickLabelsMaxHeight = Math.max(0, axisHeight - (label ? labelHeight + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
198
- const tickLabels = isHydrated ? (0, _shortenLabels.shortenLabels)(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
199
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(XAxisRoot, {
200
- transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
201
- className: classes.root,
202
- sx: sx,
203
- children: [!disableLine && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _extends2.default)({
204
- x1: left,
205
- x2: left + width,
206
- className: classes.line
207
- }, slotProps?.axisLine)), xTicks.map((item, index) => {
208
- const {
209
- offset: tickOffset,
210
- labelOffset
211
- } = item;
212
- const xTickLabel = labelOffset ?? 0;
213
- const yTickLabel = positionSign * (tickSize + TICK_LABEL_GAP);
214
- const showTick = instance.isXInside(tickOffset);
215
- const tickLabel = tickLabels.get(item);
216
- const showTickLabel = visibleLabels.has(item);
217
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
218
- transform: `translate(${tickOffset}, 0)`,
219
- className: classes.tickContainer,
220
- children: [!disableTicks && showTick && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tick, (0, _extends2.default)({
221
- y2: positionSign * tickSize,
222
- className: classes.tick
223
- }, slotProps?.axisTick)), tickLabel !== undefined && showTickLabel && /*#__PURE__*/(0, _jsxRuntime.jsx)(TickLabel, (0, _extends2.default)({
224
- x: xTickLabel,
225
- y: yTickLabel
226
- }, axisTickLabelProps, {
227
- text: tickLabel
228
- }))]
229
- }, index);
230
- }), label && /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
231
- className: classes.label,
232
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, (0, _extends2.default)({}, labelRefPoint, axisLabelProps, {
233
- text: label
234
- }))
235
- })]
236
- });
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsSingleXAxis.ChartsSingleXAxis, (0, _extends2.default)({}, inProps));
237
35
  }
238
36
  process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
239
37
  // ----------------------------- Warning --------------------------------
@@ -1,6 +1,6 @@
1
1
  import { TickItemType } from "../hooks/useTicks.js";
2
2
  import { ChartsXAxisProps, ComputedXAxis } from "../models/axis.js";
3
- export declare function getVisibleLabels(xTicks: TickItemType[], {
3
+ export declare function getVisibleLabels<T extends TickItemType>(xTicks: T[], {
4
4
  tickLabelStyle: style,
5
5
  tickLabelInterval,
6
6
  tickLabelMinGap,
@@ -11,4 +11,4 @@ export declare function getVisibleLabels(xTicks: TickItemType[], {
11
11
  isMounted: boolean;
12
12
  tickLabelMinGap: NonNullable<ChartsXAxisProps['tickLabelMinGap']>;
13
13
  isXInside: (x: number) => boolean;
14
- }): Set<TickItemType>;
14
+ }): Set<T>;