@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
@@ -1,67 +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.ChartsYAxis = ChartsYAxis;
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 _defaultTextPlacement = require("../ChartsText/defaultTextPlacement");
20
- var _domUtils = require("../internals/domUtils");
21
- var _useTicks = require("../hooks/useTicks");
22
- var _useDrawingArea = require("../hooks/useDrawingArea");
23
- var _AxisSharedComponents = require("../internals/components/AxisSharedComponents");
24
- var _ChartsText = require("../ChartsText");
25
- var _axisClasses = require("../ChartsAxis/axisClasses");
26
- var _isInfinity = require("../internals/isInfinity");
27
- var _isBandScale = require("../internals/isBandScale");
28
- var _ChartProvider = require("../context/ChartProvider");
29
- var _hooks = require("../hooks");
30
- var _invertTextAnchor = require("../internals/invertTextAnchor");
31
- var _shortenLabels = require("./shortenLabels");
13
+ var _useAxis = require("../hooks/useAxis");
14
+ var _ChartsSingleYAxis = require("./ChartsSingleYAxis");
15
+ var _ChartsGroupedYAxis = require("./ChartsGroupedYAxis");
32
16
  var _jsxRuntime = require("react/jsx-runtime");
33
- const _excluded = ["scale", "tickNumber"];
34
- const useUtilityClasses = ownerState => {
35
- const {
36
- classes,
37
- position,
38
- id
39
- } = ownerState;
40
- const slots = {
41
- root: ['root', 'directionY', position, `id-${id}`],
42
- line: ['line'],
43
- tickContainer: ['tickContainer'],
44
- tick: ['tick'],
45
- tickLabel: ['tickLabel'],
46
- label: ['label']
47
- };
48
- return (0, _composeClasses.default)(slots, _axisClasses.getAxisUtilityClass, classes);
49
- };
50
-
51
- /* Gap between a tick and its label. */
52
- const TICK_LABEL_GAP = 2;
53
- /* Gap between the axis label and tick labels. */
54
- const AXIS_LABEL_TICK_LABEL_GAP = 2;
55
- const YAxisRoot = (0, _styles.styled)(_AxisSharedComponents.AxisRoot, {
56
- name: 'MuiChartsYAxis',
57
- slot: 'Root'
58
- })({});
59
- const defaultProps = {
60
- disableLine: false,
61
- disableTicks: false,
62
- tickSize: 6
63
- };
64
-
65
17
  /**
66
18
  * Demos:
67
19
  *
@@ -70,167 +22,16 @@ const defaultProps = {
70
22
  * API:
71
23
  *
72
24
  * - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
73
- */
74
- function ChartsYAxis(inProps) {
25
+ */function ChartsYAxis(inProps) {
75
26
  const {
76
- yAxisIds,
77
- yAxis
78
- } = (0, _hooks.useYAxes)();
79
- const _yAxis = yAxis[inProps.axisId ?? yAxisIds[0]],
80
- {
81
- scale: yScale,
82
- tickNumber
83
- } = _yAxis,
84
- settings = (0, _objectWithoutPropertiesLoose2.default)(_yAxis, _excluded);
85
- const themedProps = (0, _styles.useThemeProps)({
86
- props: (0, _extends2.default)({}, settings, inProps),
87
- name: 'MuiChartsYAxis'
88
- });
89
- const defaultizedProps = (0, _extends2.default)({}, defaultProps, themedProps);
90
- const {
91
- position,
92
- disableLine,
93
- disableTicks,
94
- label,
95
- labelStyle,
96
- tickLabelStyle,
97
- tickSize: tickSizeProp,
98
- valueFormatter,
99
- slots,
100
- slotProps,
101
- tickPlacement,
102
- tickLabelPlacement,
103
- tickInterval,
104
- tickLabelInterval,
105
- sx,
106
- offset,
107
- width: axisWidth
108
- } = defaultizedProps;
109
- const theme = (0, _styles.useTheme)();
110
- const isRtl = (0, _RtlProvider.useRtl)();
111
- const isHydrated = (0, _useIsHydrated.useIsHydrated)();
112
- const classes = useUtilityClasses(defaultizedProps);
113
- const {
114
- instance
115
- } = (0, _ChartProvider.useChartContext)();
116
- const drawingArea = (0, _useDrawingArea.useDrawingArea)();
117
- const {
118
- left,
119
- top,
120
- width,
121
- height
122
- } = drawingArea;
123
- const tickSize = disableTicks ? 4 : tickSizeProp;
124
- const yTicks = (0, _useTicks.useTicks)({
125
- scale: yScale,
126
- tickNumber,
127
- valueFormatter,
128
- tickPlacement,
129
- tickLabelPlacement,
130
- tickInterval,
131
- direction: 'y'
132
- });
133
- const positionSign = position === 'right' ? 1 : -1;
134
- const tickFontSize = typeof tickLabelStyle?.fontSize === 'number' ? tickLabelStyle.fontSize : 12;
135
- const Line = slots?.axisLine ?? 'line';
136
- const Tick = slots?.axisTick ?? 'line';
137
- const TickLabel = slots?.axisTickLabel ?? _ChartsText.ChartsText;
138
- const Label = slots?.axisLabel ?? _ChartsText.ChartsText;
139
- const defaultTextAnchor = (0, _defaultTextPlacement.getDefaultTextAnchor)((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0));
140
- const defaultDominantBaseline = (0, _defaultTextPlacement.getDefaultBaseline)((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0));
141
- const axisTickLabelProps = (0, _useSlotProps.default)({
142
- elementType: TickLabel,
143
- externalSlotProps: slotProps?.axisTickLabel,
144
- additionalProps: {
145
- style: (0, _extends2.default)({}, theme.typography.caption, {
146
- fontSize: tickFontSize,
147
- textAnchor: isRtl ? (0, _invertTextAnchor.invertTextAnchor)(defaultTextAnchor) : defaultTextAnchor,
148
- dominantBaseline: defaultDominantBaseline
149
- }, tickLabelStyle)
150
- },
151
- className: classes.tickLabel,
152
- ownerState: {}
153
- });
154
- const axisLabelProps = (0, _useSlotProps.default)({
155
- elementType: Label,
156
- externalSlotProps: slotProps?.axisLabel,
157
- additionalProps: {
158
- style: (0, _extends2.default)({}, theme.typography.body1, {
159
- lineHeight: 1,
160
- fontSize: 14,
161
- angle: positionSign * 90,
162
- textAnchor: 'middle',
163
- dominantBaseline: 'text-before-edge'
164
- }, labelStyle)
165
- },
166
- ownerState: {}
167
- });
168
- const lineSlotProps = (0, _useSlotProps.default)({
169
- elementType: Line,
170
- externalSlotProps: slotProps?.axisLine,
171
- additionalProps: {
172
- strokeLinecap: 'square'
173
- },
174
- ownerState: {}
175
- });
176
- const domain = yScale.domain();
177
- const ordinalAxis = (0, _isBandScale.isBandScale)(yScale);
178
-
179
- // Skip axis rendering if no data is available
180
- // - The domain is an empty array for band/point scales.
181
- // - The domains contains Infinity for continuous scales.
182
- // - The position is 'none'.
183
- if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(_isInfinity.isInfinity) || position === 'none') {
184
- return null;
27
+ yAxis,
28
+ yAxisIds
29
+ } = (0, _useAxis.useYAxes)();
30
+ const axis = yAxis[inProps.axisId ?? yAxisIds[0]];
31
+ if ('groups' in axis && Array.isArray(axis.groups)) {
32
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsGroupedYAxis.ChartsGroupedYAxis, (0, _extends2.default)({}, inProps));
185
33
  }
186
- const labelRefPoint = {
187
- x: positionSign * axisWidth,
188
- y: top + height / 2
189
- };
190
- /* If there's an axis title, the tick labels have less space to render */
191
- const tickLabelsMaxWidth = Math.max(0, axisWidth - (label ? (0, _domUtils.getStringSize)(label, axisLabelProps.style).height + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
192
- const tickLabels = isHydrated ? (0, _shortenLabels.shortenLabels)(yTicks, drawingArea, tickLabelsMaxWidth, isRtl, axisTickLabelProps.style) : new Map(Array.from(yTicks).map(item => [item, item.formattedValue]));
193
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(YAxisRoot, {
194
- transform: `translate(${position === 'right' ? left + width + offset : left - offset}, 0)`,
195
- className: classes.root,
196
- sx: sx,
197
- children: [!disableLine && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _extends2.default)({
198
- y1: top,
199
- y2: top + height,
200
- className: classes.line
201
- }, lineSlotProps)), yTicks.map((item, index) => {
202
- const {
203
- offset: tickOffset,
204
- labelOffset,
205
- value
206
- } = item;
207
- const xTickLabel = positionSign * (tickSize + TICK_LABEL_GAP);
208
- const yTickLabel = labelOffset;
209
- const skipLabel = typeof tickLabelInterval === 'function' && !tickLabelInterval?.(value, index);
210
- const showLabel = instance.isYInside(tickOffset);
211
- const tickLabel = tickLabels.get(item);
212
- if (!showLabel) {
213
- return null;
214
- }
215
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
216
- transform: `translate(0, ${tickOffset})`,
217
- className: classes.tickContainer,
218
- children: [!disableTicks && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tick, (0, _extends2.default)({
219
- x2: positionSign * tickSize,
220
- className: classes.tick
221
- }, slotProps?.axisTick)), tickLabel !== undefined && !skipLabel && /*#__PURE__*/(0, _jsxRuntime.jsx)(TickLabel, (0, _extends2.default)({
222
- x: xTickLabel,
223
- y: yTickLabel,
224
- text: tickLabel
225
- }, axisTickLabelProps))]
226
- }, index);
227
- }), label && isHydrated && /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
228
- className: classes.label,
229
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, (0, _extends2.default)({}, labelRefPoint, axisLabelProps, {
230
- text: label
231
- }))
232
- })]
233
- });
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsSingleYAxis.ChartsSingleYAxis, (0, _extends2.default)({}, inProps));
234
35
  }
235
36
  process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
236
37
  // ----------------------------- Warning --------------------------------