@mui/x-charts 8.9.2 → 8.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/BarChart/BarChart.js +20 -0
  2. package/CHANGELOG.md +217 -6
  3. package/ChartContainer/ChartContainer.js +30 -0
  4. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  5. package/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
  6. package/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
  7. package/ChartsLabel/labelGradientClasses.d.ts +1 -1
  8. package/ChartsLabel/labelMarkClasses.d.ts +1 -1
  9. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
  10. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
  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 +11 -5
  15. package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  16. package/ChartsTooltip/ChartsTooltipTable.js +1 -0
  17. package/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
  18. package/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
  19. package/ChartsXAxis/ChartsGroupedXAxis.js +143 -0
  20. package/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
  21. package/ChartsXAxis/ChartsSingleXAxis.js +144 -0
  22. package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  23. package/ChartsXAxis/ChartsXAxis.js +8 -210
  24. package/ChartsXAxis/getVisibleLabels.d.ts +2 -2
  25. package/ChartsXAxis/useAxisProps.d.ts +4526 -0
  26. package/ChartsXAxis/useAxisProps.js +105 -0
  27. package/ChartsXAxis/utilities.d.ts +11 -0
  28. package/ChartsXAxis/utilities.js +43 -0
  29. package/ChartsYAxis/ChartsGroupedYAxis.d.ts +7 -0
  30. package/ChartsYAxis/ChartsGroupedYAxis.js +144 -0
  31. package/ChartsYAxis/ChartsSingleYAxis.d.ts +7 -0
  32. package/ChartsYAxis/ChartsSingleYAxis.js +133 -0
  33. package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
  34. package/ChartsYAxis/ChartsYAxis.js +12 -211
  35. package/ChartsYAxis/useAxisProps.d.ts +4452 -0
  36. package/ChartsYAxis/useAxisProps.js +115 -0
  37. package/ChartsYAxis/utilities.d.ts +10 -0
  38. package/ChartsYAxis/utilities.js +42 -0
  39. package/LineChart/LineChart.js +20 -0
  40. package/RadarChart/index.d.ts +9 -2
  41. package/RadarChart/index.js +13 -14
  42. package/ScatterChart/ScatterChart.d.ts +8 -1
  43. package/ScatterChart/ScatterChart.js +20 -0
  44. package/SparkLineChart/SparkLineChart.d.ts +15 -5
  45. package/SparkLineChart/SparkLineChart.js +77 -34
  46. package/esm/BarChart/BarChart.js +20 -0
  47. package/esm/ChartContainer/ChartContainer.js +30 -0
  48. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  49. package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
  50. package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
  51. package/esm/ChartsLabel/labelGradientClasses.d.ts +1 -1
  52. package/esm/ChartsLabel/labelMarkClasses.d.ts +1 -1
  53. package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
  54. package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
  55. package/esm/ChartsTooltip/ChartsTooltip.d.ts +2 -1
  56. package/esm/ChartsTooltip/ChartsTooltip.js +3 -3
  57. package/esm/ChartsTooltip/ChartsTooltipContainer.d.ts +5 -5
  58. package/esm/ChartsTooltip/ChartsTooltipContainer.js +11 -5
  59. package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  60. package/esm/ChartsTooltip/ChartsTooltipTable.js +1 -0
  61. package/esm/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
  62. package/esm/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
  63. package/esm/ChartsXAxis/ChartsGroupedXAxis.js +137 -0
  64. package/esm/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
  65. package/esm/ChartsXAxis/ChartsSingleXAxis.js +140 -0
  66. package/esm/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  67. package/esm/ChartsXAxis/ChartsXAxis.js +7 -207
  68. package/esm/ChartsXAxis/getVisibleLabels.d.ts +2 -2
  69. package/esm/ChartsXAxis/useAxisProps.d.ts +4526 -0
  70. package/esm/ChartsXAxis/useAxisProps.js +98 -0
  71. package/esm/ChartsXAxis/utilities.d.ts +11 -0
  72. package/esm/ChartsXAxis/utilities.js +35 -0
  73. package/esm/ChartsYAxis/ChartsGroupedYAxis.d.ts +7 -0
  74. package/esm/ChartsYAxis/ChartsGroupedYAxis.js +138 -0
  75. package/esm/ChartsYAxis/ChartsSingleYAxis.d.ts +7 -0
  76. package/esm/ChartsYAxis/ChartsSingleYAxis.js +129 -0
  77. package/esm/ChartsYAxis/ChartsYAxis.d.ts +1 -1
  78. package/esm/ChartsYAxis/ChartsYAxis.js +10 -207
  79. package/esm/ChartsYAxis/useAxisProps.d.ts +4452 -0
  80. package/esm/ChartsYAxis/useAxisProps.js +108 -0
  81. package/esm/ChartsYAxis/utilities.d.ts +10 -0
  82. package/esm/ChartsYAxis/utilities.js +34 -0
  83. package/esm/LineChart/LineChart.js +20 -0
  84. package/esm/RadarChart/index.d.ts +9 -2
  85. package/esm/RadarChart/index.js +12 -2
  86. package/esm/ScatterChart/ScatterChart.d.ts +8 -1
  87. package/esm/ScatterChart/ScatterChart.js +20 -0
  88. package/esm/SparkLineChart/SparkLineChart.d.ts +15 -5
  89. package/esm/SparkLineChart/SparkLineChart.js +77 -34
  90. package/esm/hooks/useTicksGrouped.d.ts +28 -0
  91. package/esm/hooks/useTicksGrouped.js +98 -0
  92. package/esm/index.js +1 -1
  93. package/esm/internals/animation/Transition.js +2 -5
  94. package/esm/internals/configInit.js +2 -2
  95. package/esm/internals/getScale.d.ts +1 -1
  96. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
  97. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +32 -23
  98. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
  99. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +1 -1
  100. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -4
  101. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +2 -2
  102. package/esm/internals/plugins/utils/ChartStore.js +16 -18
  103. package/esm/models/axis.d.ts +46 -2
  104. package/esm/tests/web-components.js +2 -4
  105. package/hooks/useTicksGrouped.d.ts +28 -0
  106. package/hooks/useTicksGrouped.js +104 -0
  107. package/index.js +1 -1
  108. package/internals/animation/Transition.js +2 -5
  109. package/internals/configInit.js +2 -2
  110. package/internals/getScale.d.ts +1 -1
  111. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
  112. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +34 -23
  113. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
  114. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +1 -1
  115. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -4
  116. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +2 -2
  117. package/internals/plugins/utils/ChartStore.js +16 -18
  118. package/models/axis.d.ts +46 -2
  119. package/package.json +16 -18
  120. package/tests/web-components.js +2 -4
@@ -0,0 +1,98 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
+ const _excluded = ["scale", "tickNumber", "reverse"];
6
+ import useSlotProps from '@mui/utils/useSlotProps';
7
+ import { useThemeProps, useTheme } from '@mui/material/styles';
8
+ import { useRtl } from '@mui/system/RtlProvider';
9
+ import { ChartsText } from "../ChartsText/index.js";
10
+ import { useXAxes } from "../hooks/useAxis.js";
11
+ import { getDefaultBaseline, getDefaultTextAnchor } from "../ChartsText/defaultTextPlacement.js";
12
+ import { invertTextAnchor } from "../internals/invertTextAnchor.js";
13
+ import { defaultProps, useUtilityClasses } from "./utilities.js";
14
+ import { isBandScale } from "../internals/isBandScale.js";
15
+ import { isInfinity } from "../internals/isInfinity.js";
16
+ export const useAxisProps = inProps => {
17
+ const {
18
+ xAxis,
19
+ xAxisIds
20
+ } = useXAxes();
21
+ const _xAxis = xAxis[inProps.axisId ?? xAxisIds[0]],
22
+ {
23
+ scale: xScale,
24
+ tickNumber,
25
+ reverse
26
+ } = _xAxis,
27
+ settings = _objectWithoutPropertiesLoose(_xAxis, _excluded);
28
+
29
+ // eslint-disable-next-line material-ui/mui-name-matches-component-name
30
+ const themedProps = useThemeProps({
31
+ props: _extends({}, settings, inProps),
32
+ name: 'MuiChartsXAxis'
33
+ });
34
+ const defaultizedProps = _extends({}, defaultProps, themedProps);
35
+ const {
36
+ position,
37
+ tickLabelStyle,
38
+ labelStyle,
39
+ slots,
40
+ slotProps
41
+ } = defaultizedProps;
42
+ const theme = useTheme();
43
+ const isRtl = useRtl();
44
+ const classes = useUtilityClasses(defaultizedProps);
45
+ const positionSign = position === 'bottom' ? 1 : -1;
46
+ const Line = slots?.axisLine ?? 'line';
47
+ const Tick = slots?.axisTick ?? 'line';
48
+ const TickLabel = slots?.axisTickLabel ?? ChartsText;
49
+ const Label = slots?.axisLabel ?? ChartsText;
50
+ const defaultTextAnchor = getDefaultTextAnchor((position === 'bottom' ? 0 : 180) - (tickLabelStyle?.angle ?? 0));
51
+ const defaultDominantBaseline = getDefaultBaseline((position === 'bottom' ? 0 : 180) - (tickLabelStyle?.angle ?? 0));
52
+ const axisTickLabelProps = useSlotProps({
53
+ elementType: TickLabel,
54
+ externalSlotProps: slotProps?.axisTickLabel,
55
+ additionalProps: {
56
+ style: _extends({}, theme.typography.caption, {
57
+ fontSize: 12,
58
+ lineHeight: 1.25,
59
+ textAnchor: isRtl ? invertTextAnchor(defaultTextAnchor) : defaultTextAnchor,
60
+ dominantBaseline: defaultDominantBaseline
61
+ }, tickLabelStyle)
62
+ },
63
+ className: classes.tickLabel,
64
+ ownerState: {}
65
+ });
66
+ const axisLabelProps = useSlotProps({
67
+ elementType: Label,
68
+ externalSlotProps: slotProps?.axisLabel,
69
+ additionalProps: {
70
+ style: _extends({}, theme.typography.body1, {
71
+ lineHeight: 1,
72
+ fontSize: 14,
73
+ textAnchor: 'middle',
74
+ dominantBaseline: position === 'bottom' ? 'text-after-edge' : 'text-before-edge'
75
+ }, labelStyle)
76
+ },
77
+ ownerState: {}
78
+ });
79
+ const domain = xScale.domain();
80
+ const isScaleBand = isBandScale(xScale);
81
+ const skipAxisRendering = isScaleBand && domain.length === 0 || !isScaleBand && domain.some(isInfinity) || position === 'none';
82
+ return {
83
+ xScale,
84
+ defaultizedProps,
85
+ tickNumber,
86
+ positionSign,
87
+ skipAxisRendering,
88
+ classes,
89
+ Line,
90
+ Tick,
91
+ TickLabel,
92
+ Label,
93
+ axisTickLabelProps,
94
+ axisLabelProps,
95
+ reverse,
96
+ isRtl
97
+ };
98
+ };
@@ -0,0 +1,11 @@
1
+ import { AxisConfig, ChartsXAxisProps } from "../models/axis.js";
2
+ export declare const useUtilityClasses: (ownerState: AxisConfig<any, any, ChartsXAxisProps>) => Record<"line" | "root" | "label" | "tickContainer" | "tick" | "tickLabel", string>;
3
+ export declare const TICK_LABEL_GAP = 3;
4
+ export declare const AXIS_LABEL_TICK_LABEL_GAP = 4;
5
+ export declare const XAxisRoot: import("@emotion/styled").StyledComponent<Pick<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, keyof import("react").SVGProps<SVGGElement> | keyof import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
6
+ export declare const defaultProps: {
7
+ readonly disableLine: false;
8
+ readonly disableTicks: false;
9
+ readonly tickSize: 6;
10
+ readonly tickLabelMinGap: 4;
11
+ };
@@ -0,0 +1,35 @@
1
+ import composeClasses from '@mui/utils/composeClasses';
2
+ import { styled } from '@mui/material/styles';
3
+ import { getAxisUtilityClass } from "../ChartsAxis/axisClasses.js";
4
+ import { AxisRoot } from "../internals/components/AxisSharedComponents.js";
5
+ export const useUtilityClasses = ownerState => {
6
+ const {
7
+ classes,
8
+ position,
9
+ id
10
+ } = ownerState;
11
+ const slots = {
12
+ root: ['root', 'directionX', position, `id-${id}`],
13
+ line: ['line'],
14
+ tickContainer: ['tickContainer'],
15
+ tick: ['tick'],
16
+ tickLabel: ['tickLabel'],
17
+ label: ['label']
18
+ };
19
+ return composeClasses(slots, getAxisUtilityClass, classes);
20
+ };
21
+
22
+ /* Gap between a tick and its label. */
23
+ export const TICK_LABEL_GAP = 3;
24
+ /* Gap between the axis label and tick labels. */
25
+ export const AXIS_LABEL_TICK_LABEL_GAP = 4;
26
+ export const XAxisRoot = styled(AxisRoot, {
27
+ name: 'MuiChartsXAxis',
28
+ slot: 'Root'
29
+ })({});
30
+ export const defaultProps = {
31
+ disableLine: false,
32
+ disableTicks: false,
33
+ tickSize: 6,
34
+ tickLabelMinGap: 4
35
+ };
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { ChartsYAxisProps } from "../models/axis.js";
3
+ /**
4
+ * @ignore - internal component.
5
+ */
6
+ declare function ChartsGroupedYAxis(inProps: ChartsYAxisProps): React.JSX.Element | null;
7
+ export { ChartsGroupedYAxis };
@@ -0,0 +1,138 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import * as React from 'react';
5
+ import { useDrawingArea } from "../hooks/useDrawingArea.js";
6
+ import { isBandScale } from "../internals/isBandScale.js";
7
+ import { useChartContext } from "../context/ChartProvider/useChartContext.js";
8
+ import { TICK_LABEL_GAP, YAxisRoot } from "./utilities.js";
9
+ import { useTicksGrouped } from "../hooks/useTicksGrouped.js";
10
+ import { useAxisProps } from "./useAxisProps.js";
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ const DEFAULT_GROUPING_CONFIG = {
13
+ tickSize: 6
14
+ };
15
+ const getGroupingConfig = (groups, groupIndex, tickSize) => {
16
+ const config = groups[groupIndex] ?? {};
17
+ const defaultTickSize = tickSize ?? DEFAULT_GROUPING_CONFIG.tickSize;
18
+ const calculatedTickSize = defaultTickSize * groupIndex * 2 + defaultTickSize;
19
+ return _extends({}, DEFAULT_GROUPING_CONFIG, config, {
20
+ tickSize: config.tickSize ?? calculatedTickSize
21
+ });
22
+ };
23
+
24
+ /**
25
+ * @ignore - internal component.
26
+ */
27
+ function ChartsGroupedYAxis(inProps) {
28
+ const {
29
+ yScale,
30
+ defaultizedProps,
31
+ tickNumber,
32
+ positionSign,
33
+ skipAxisRendering,
34
+ classes,
35
+ Line,
36
+ Tick,
37
+ TickLabel,
38
+ Label,
39
+ axisTickLabelProps,
40
+ axisLabelProps,
41
+ lineProps
42
+ } = useAxisProps(inProps);
43
+ if (!isBandScale(yScale)) {
44
+ throw new Error('MUI X Charts: ChartsGroupedYAxis only supports the `band` and `point` scale types.');
45
+ }
46
+ const {
47
+ position,
48
+ disableLine,
49
+ disableTicks,
50
+ label,
51
+ tickSize,
52
+ valueFormatter,
53
+ slotProps,
54
+ tickInterval,
55
+ tickPlacement,
56
+ tickLabelPlacement,
57
+ sx,
58
+ offset,
59
+ width: axisWidth
60
+ } = defaultizedProps;
61
+ const groups = defaultizedProps.groups;
62
+ const drawingArea = useDrawingArea();
63
+ const {
64
+ left,
65
+ top,
66
+ width,
67
+ height
68
+ } = drawingArea;
69
+ const {
70
+ instance
71
+ } = useChartContext();
72
+ const labelRefPoint = {
73
+ x: positionSign * axisWidth,
74
+ y: top + height / 2
75
+ };
76
+ const yTicks = useTicksGrouped({
77
+ scale: yScale,
78
+ tickNumber,
79
+ valueFormatter,
80
+ tickInterval,
81
+ tickPlacement,
82
+ tickLabelPlacement,
83
+ direction: 'y',
84
+ groups
85
+ });
86
+
87
+ // Skip axis rendering if no data is available
88
+ // - The domain is an empty array for band/point scales.
89
+ // - The domains contains Infinity for continuous scales.
90
+ // - The position is set to 'none'.
91
+ if (skipAxisRendering) {
92
+ return null;
93
+ }
94
+ return /*#__PURE__*/_jsxs(YAxisRoot, {
95
+ transform: `translate(${position === 'right' ? left + width + offset : left - offset}, 0)`,
96
+ className: classes.root,
97
+ sx: sx,
98
+ children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
99
+ y1: top,
100
+ y2: top + height,
101
+ className: classes.line
102
+ }, lineProps)), yTicks.map((item, index) => {
103
+ const {
104
+ offset: tickOffset,
105
+ labelOffset
106
+ } = item;
107
+ const yTickLabel = labelOffset ?? 0;
108
+ const showTick = instance.isYInside(tickOffset);
109
+ const tickLabel = item.formattedValue;
110
+ const ignoreTick = item.ignoreTick ?? false;
111
+ const groupIndex = item.groupIndex ?? 0;
112
+ const groupConfig = getGroupingConfig(groups, groupIndex, tickSize);
113
+ const tickXSize = positionSign * groupConfig.tickSize;
114
+ const labelPositionX = positionSign * (groupConfig.tickSize + TICK_LABEL_GAP);
115
+ return /*#__PURE__*/_jsxs("g", {
116
+ transform: `translate(0, ${tickOffset})`,
117
+ className: classes.tickContainer,
118
+ "data-group-index": groupIndex,
119
+ children: [!disableTicks && !ignoreTick && showTick && /*#__PURE__*/_jsx(Tick, _extends({
120
+ x2: tickXSize,
121
+ className: classes.tick
122
+ }, slotProps?.axisTick)), tickLabel !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
123
+ x: labelPositionX,
124
+ y: yTickLabel
125
+ }, axisTickLabelProps, {
126
+ style: _extends({}, axisTickLabelProps.style, groupConfig.tickLabelStyle),
127
+ text: tickLabel
128
+ }))]
129
+ }, index);
130
+ }), label && /*#__PURE__*/_jsx("g", {
131
+ className: classes.label,
132
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
133
+ text: label
134
+ }))
135
+ })]
136
+ });
137
+ }
138
+ export { ChartsGroupedYAxis };
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { ChartsYAxisProps } from "../models/axis.js";
3
+ /**
4
+ * @ignore - internal component.
5
+ */
6
+ declare function ChartsSingleYAxis(inProps: ChartsYAxisProps): React.JSX.Element | null;
7
+ export { ChartsSingleYAxis };
@@ -0,0 +1,129 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import * as React from 'react';
5
+ import { useIsHydrated } from "../hooks/useIsHydrated.js";
6
+ import { getStringSize } from "../internals/domUtils.js";
7
+ import { useTicks } from "../hooks/useTicks.js";
8
+ import { useDrawingArea } from "../hooks/useDrawingArea.js";
9
+ import { useChartContext } from "../context/ChartProvider/index.js";
10
+ import { shortenLabels } from "./shortenLabels.js";
11
+ import { AXIS_LABEL_TICK_LABEL_GAP, TICK_LABEL_GAP, YAxisRoot } from "./utilities.js";
12
+ import { useAxisProps } from "./useAxisProps.js";
13
+
14
+ /**
15
+ * @ignore - internal component.
16
+ */
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ function ChartsSingleYAxis(inProps) {
19
+ const {
20
+ yScale,
21
+ defaultizedProps,
22
+ tickNumber,
23
+ positionSign,
24
+ skipAxisRendering,
25
+ classes,
26
+ Line,
27
+ Tick,
28
+ TickLabel,
29
+ Label,
30
+ axisTickLabelProps,
31
+ axisLabelProps,
32
+ lineProps,
33
+ isRtl
34
+ } = useAxisProps(inProps);
35
+ const {
36
+ position,
37
+ disableLine,
38
+ disableTicks,
39
+ label,
40
+ tickSize: tickSizeProp,
41
+ valueFormatter,
42
+ slotProps,
43
+ tickPlacement,
44
+ tickLabelPlacement,
45
+ tickInterval,
46
+ tickLabelInterval,
47
+ sx,
48
+ offset,
49
+ width: axisWidth
50
+ } = defaultizedProps;
51
+ const drawingArea = useDrawingArea();
52
+ const {
53
+ left,
54
+ top,
55
+ width,
56
+ height
57
+ } = drawingArea;
58
+ const {
59
+ instance
60
+ } = useChartContext();
61
+ const isHydrated = useIsHydrated();
62
+ const tickSize = disableTicks ? 4 : tickSizeProp;
63
+ const yTicks = useTicks({
64
+ scale: yScale,
65
+ tickNumber,
66
+ valueFormatter,
67
+ tickPlacement,
68
+ tickLabelPlacement,
69
+ tickInterval,
70
+ direction: 'y'
71
+ });
72
+
73
+ // Skip axis rendering if no data is available
74
+ // - The domain is an empty array for band/point scales.
75
+ // - The domains contains Infinity for continuous scales.
76
+ // - The position is set to 'none'.
77
+ if (skipAxisRendering) {
78
+ return null;
79
+ }
80
+ const labelRefPoint = {
81
+ x: positionSign * axisWidth,
82
+ y: top + height / 2
83
+ };
84
+ /* If there's an axis title, the tick labels have less space to render */
85
+ const tickLabelsMaxWidth = Math.max(0, axisWidth - (label ? getStringSize(label, axisLabelProps.style).height + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
86
+ const tickLabels = isHydrated ? shortenLabels(yTicks, drawingArea, tickLabelsMaxWidth, isRtl, axisTickLabelProps.style) : new Map(Array.from(yTicks).map(item => [item, item.formattedValue]));
87
+ return /*#__PURE__*/_jsxs(YAxisRoot, {
88
+ transform: `translate(${position === 'right' ? left + width + offset : left - offset}, 0)`,
89
+ className: classes.root,
90
+ sx: sx,
91
+ children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
92
+ y1: top,
93
+ y2: top + height,
94
+ className: classes.line
95
+ }, lineProps)), yTicks.map((item, index) => {
96
+ const {
97
+ offset: tickOffset,
98
+ labelOffset,
99
+ value
100
+ } = item;
101
+ const xTickLabel = positionSign * (tickSize + TICK_LABEL_GAP);
102
+ const yTickLabel = labelOffset;
103
+ const skipLabel = typeof tickLabelInterval === 'function' && !tickLabelInterval?.(value, index);
104
+ const showLabel = instance.isYInside(tickOffset);
105
+ const tickLabel = tickLabels.get(item);
106
+ if (!showLabel) {
107
+ return null;
108
+ }
109
+ return /*#__PURE__*/_jsxs("g", {
110
+ transform: `translate(0, ${tickOffset})`,
111
+ className: classes.tickContainer,
112
+ children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
113
+ x2: positionSign * tickSize,
114
+ className: classes.tick
115
+ }, slotProps?.axisTick)), tickLabel !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
116
+ x: xTickLabel,
117
+ y: yTickLabel,
118
+ text: tickLabel
119
+ }, axisTickLabelProps))]
120
+ }, index);
121
+ }), label && isHydrated && /*#__PURE__*/_jsx("g", {
122
+ className: classes.label,
123
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
124
+ text: label
125
+ }))
126
+ })]
127
+ });
128
+ }
129
+ export { ChartsSingleYAxis };
@@ -9,7 +9,7 @@ import { ChartsYAxisProps } from "../models/axis.js";
9
9
  *
10
10
  * - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
11
11
  */
12
- declare function ChartsYAxis(inProps: ChartsYAxisProps): React.JSX.Element | null;
12
+ declare function ChartsYAxis(inProps: ChartsYAxisProps): React.JSX.Element;
13
13
  declare namespace ChartsYAxis {
14
14
  var propTypes: any;
15
15
  }
@@ -1,59 +1,11 @@
1
1
  'use client';
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["scale", "tickNumber"];
6
4
  import * as React from 'react';
7
5
  import PropTypes from 'prop-types';
8
- import useSlotProps from '@mui/utils/useSlotProps';
9
- import composeClasses from '@mui/utils/composeClasses';
10
- import { useThemeProps, styled, useTheme } from '@mui/material/styles';
11
- import { useRtl } from '@mui/system/RtlProvider';
12
- import { useIsHydrated } from "../hooks/useIsHydrated.js";
13
- import { getDefaultBaseline, getDefaultTextAnchor } from "../ChartsText/defaultTextPlacement.js";
14
- import { getStringSize } from "../internals/domUtils.js";
15
- import { useTicks } from "../hooks/useTicks.js";
16
- import { useDrawingArea } from "../hooks/useDrawingArea.js";
17
- import { AxisRoot } from "../internals/components/AxisSharedComponents.js";
18
- import { ChartsText } from "../ChartsText/index.js";
19
- import { getAxisUtilityClass } from "../ChartsAxis/axisClasses.js";
20
- import { isInfinity } from "../internals/isInfinity.js";
21
- import { isBandScale } from "../internals/isBandScale.js";
22
- import { useChartContext } from "../context/ChartProvider/index.js";
23
- import { useYAxes } from "../hooks/index.js";
24
- import { invertTextAnchor } from "../internals/invertTextAnchor.js";
25
- import { shortenLabels } from "./shortenLabels.js";
26
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
27
- const useUtilityClasses = ownerState => {
28
- const {
29
- classes,
30
- position,
31
- id
32
- } = ownerState;
33
- const slots = {
34
- root: ['root', 'directionY', position, `id-${id}`],
35
- line: ['line'],
36
- tickContainer: ['tickContainer'],
37
- tick: ['tick'],
38
- tickLabel: ['tickLabel'],
39
- label: ['label']
40
- };
41
- return composeClasses(slots, getAxisUtilityClass, classes);
42
- };
43
-
44
- /* Gap between a tick and its label. */
45
- const TICK_LABEL_GAP = 2;
46
- /* Gap between the axis label and tick labels. */
47
- const AXIS_LABEL_TICK_LABEL_GAP = 2;
48
- const YAxisRoot = styled(AxisRoot, {
49
- name: 'MuiChartsYAxis',
50
- slot: 'Root'
51
- })({});
52
- const defaultProps = {
53
- disableLine: false,
54
- disableTicks: false,
55
- tickSize: 6
56
- };
6
+ import { useYAxes } from "../hooks/useAxis.js";
7
+ import { ChartsSingleYAxis } from "./ChartsSingleYAxis.js";
8
+ import { ChartsGroupedYAxis } from "./ChartsGroupedYAxis.js";
57
9
 
58
10
  /**
59
11
  * Demos:
@@ -64,166 +16,17 @@ const defaultProps = {
64
16
  *
65
17
  * - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
66
18
  */
19
+ import { jsx as _jsx } from "react/jsx-runtime";
67
20
  function ChartsYAxis(inProps) {
68
21
  const {
69
- yAxisIds,
70
- yAxis
22
+ yAxis,
23
+ yAxisIds
71
24
  } = useYAxes();
72
- const _yAxis = yAxis[inProps.axisId ?? yAxisIds[0]],
73
- {
74
- scale: yScale,
75
- tickNumber
76
- } = _yAxis,
77
- settings = _objectWithoutPropertiesLoose(_yAxis, _excluded);
78
- const themedProps = useThemeProps({
79
- props: _extends({}, settings, inProps),
80
- name: 'MuiChartsYAxis'
81
- });
82
- const defaultizedProps = _extends({}, defaultProps, themedProps);
83
- const {
84
- position,
85
- disableLine,
86
- disableTicks,
87
- label,
88
- labelStyle,
89
- tickLabelStyle,
90
- tickSize: tickSizeProp,
91
- valueFormatter,
92
- slots,
93
- slotProps,
94
- tickPlacement,
95
- tickLabelPlacement,
96
- tickInterval,
97
- tickLabelInterval,
98
- sx,
99
- offset,
100
- width: axisWidth
101
- } = defaultizedProps;
102
- const theme = useTheme();
103
- const isRtl = useRtl();
104
- const isHydrated = useIsHydrated();
105
- const classes = useUtilityClasses(defaultizedProps);
106
- const {
107
- instance
108
- } = useChartContext();
109
- const drawingArea = useDrawingArea();
110
- const {
111
- left,
112
- top,
113
- width,
114
- height
115
- } = drawingArea;
116
- const tickSize = disableTicks ? 4 : tickSizeProp;
117
- const yTicks = useTicks({
118
- scale: yScale,
119
- tickNumber,
120
- valueFormatter,
121
- tickPlacement,
122
- tickLabelPlacement,
123
- tickInterval,
124
- direction: 'y'
125
- });
126
- const positionSign = position === 'right' ? 1 : -1;
127
- const tickFontSize = typeof tickLabelStyle?.fontSize === 'number' ? tickLabelStyle.fontSize : 12;
128
- const Line = slots?.axisLine ?? 'line';
129
- const Tick = slots?.axisTick ?? 'line';
130
- const TickLabel = slots?.axisTickLabel ?? ChartsText;
131
- const Label = slots?.axisLabel ?? ChartsText;
132
- const defaultTextAnchor = getDefaultTextAnchor((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0));
133
- const defaultDominantBaseline = getDefaultBaseline((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0));
134
- const axisTickLabelProps = useSlotProps({
135
- elementType: TickLabel,
136
- externalSlotProps: slotProps?.axisTickLabel,
137
- additionalProps: {
138
- style: _extends({}, theme.typography.caption, {
139
- fontSize: tickFontSize,
140
- textAnchor: isRtl ? invertTextAnchor(defaultTextAnchor) : defaultTextAnchor,
141
- dominantBaseline: defaultDominantBaseline
142
- }, tickLabelStyle)
143
- },
144
- className: classes.tickLabel,
145
- ownerState: {}
146
- });
147
- const axisLabelProps = useSlotProps({
148
- elementType: Label,
149
- externalSlotProps: slotProps?.axisLabel,
150
- additionalProps: {
151
- style: _extends({}, theme.typography.body1, {
152
- lineHeight: 1,
153
- fontSize: 14,
154
- angle: positionSign * 90,
155
- textAnchor: 'middle',
156
- dominantBaseline: 'text-before-edge'
157
- }, labelStyle)
158
- },
159
- ownerState: {}
160
- });
161
- const lineSlotProps = useSlotProps({
162
- elementType: Line,
163
- externalSlotProps: slotProps?.axisLine,
164
- additionalProps: {
165
- strokeLinecap: 'square'
166
- },
167
- ownerState: {}
168
- });
169
- const domain = yScale.domain();
170
- const ordinalAxis = isBandScale(yScale);
171
-
172
- // Skip axis rendering if no data is available
173
- // - The domain is an empty array for band/point scales.
174
- // - The domains contains Infinity for continuous scales.
175
- // - The position is 'none'.
176
- if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(isInfinity) || position === 'none') {
177
- return null;
25
+ const axis = yAxis[inProps.axisId ?? yAxisIds[0]];
26
+ if ('groups' in axis && Array.isArray(axis.groups)) {
27
+ return /*#__PURE__*/_jsx(ChartsGroupedYAxis, _extends({}, inProps));
178
28
  }
179
- const labelRefPoint = {
180
- x: positionSign * axisWidth,
181
- y: top + height / 2
182
- };
183
- /* If there's an axis title, the tick labels have less space to render */
184
- const tickLabelsMaxWidth = Math.max(0, axisWidth - (label ? getStringSize(label, axisLabelProps.style).height + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
185
- const tickLabels = isHydrated ? shortenLabels(yTicks, drawingArea, tickLabelsMaxWidth, isRtl, axisTickLabelProps.style) : new Map(Array.from(yTicks).map(item => [item, item.formattedValue]));
186
- return /*#__PURE__*/_jsxs(YAxisRoot, {
187
- transform: `translate(${position === 'right' ? left + width + offset : left - offset}, 0)`,
188
- className: classes.root,
189
- sx: sx,
190
- children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
191
- y1: top,
192
- y2: top + height,
193
- className: classes.line
194
- }, lineSlotProps)), yTicks.map((item, index) => {
195
- const {
196
- offset: tickOffset,
197
- labelOffset,
198
- value
199
- } = item;
200
- const xTickLabel = positionSign * (tickSize + TICK_LABEL_GAP);
201
- const yTickLabel = labelOffset;
202
- const skipLabel = typeof tickLabelInterval === 'function' && !tickLabelInterval?.(value, index);
203
- const showLabel = instance.isYInside(tickOffset);
204
- const tickLabel = tickLabels.get(item);
205
- if (!showLabel) {
206
- return null;
207
- }
208
- return /*#__PURE__*/_jsxs("g", {
209
- transform: `translate(0, ${tickOffset})`,
210
- className: classes.tickContainer,
211
- children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
212
- x2: positionSign * tickSize,
213
- className: classes.tick
214
- }, slotProps?.axisTick)), tickLabel !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
215
- x: xTickLabel,
216
- y: yTickLabel,
217
- text: tickLabel
218
- }, axisTickLabelProps))]
219
- }, index);
220
- }), label && isHydrated && /*#__PURE__*/_jsx("g", {
221
- className: classes.label,
222
- children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
223
- text: label
224
- }))
225
- })]
226
- });
29
+ return /*#__PURE__*/_jsx(ChartsSingleYAxis, _extends({}, inProps));
227
30
  }
228
31
  process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
229
32
  // ----------------------------- Warning --------------------------------