@mui/x-charts 8.9.2 → 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 (68) hide show
  1. package/BarChart/BarChart.js +16 -0
  2. package/CHANGELOG.md +121 -6
  3. package/ChartContainer/ChartContainer.js +24 -0
  4. package/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
  5. package/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
  6. package/ChartsTooltip/ChartsTooltip.d.ts +2 -1
  7. package/ChartsTooltip/ChartsTooltip.js +3 -3
  8. package/ChartsTooltip/ChartsTooltipContainer.d.ts +5 -5
  9. package/ChartsTooltip/ChartsTooltipContainer.js +3 -3
  10. package/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
  11. package/ChartsXAxis/ChartsGroupedXAxis.js +142 -0
  12. package/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
  13. package/ChartsXAxis/ChartsSingleXAxis.js +144 -0
  14. package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  15. package/ChartsXAxis/ChartsXAxis.js +8 -210
  16. package/ChartsXAxis/getVisibleLabels.d.ts +2 -2
  17. package/ChartsXAxis/useAxisProps.d.ts +4526 -0
  18. package/ChartsXAxis/useAxisProps.js +105 -0
  19. package/ChartsXAxis/utilities.d.ts +11 -0
  20. package/ChartsXAxis/utilities.js +43 -0
  21. package/LineChart/LineChart.js +16 -0
  22. package/RadarChart/index.d.ts +9 -2
  23. package/RadarChart/index.js +13 -14
  24. package/ScatterChart/ScatterChart.d.ts +8 -1
  25. package/ScatterChart/ScatterChart.js +16 -0
  26. package/SparkLineChart/SparkLineChart.js +16 -0
  27. package/esm/BarChart/BarChart.js +16 -0
  28. package/esm/ChartContainer/ChartContainer.js +24 -0
  29. package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
  30. package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
  31. package/esm/ChartsTooltip/ChartsTooltip.d.ts +2 -1
  32. package/esm/ChartsTooltip/ChartsTooltip.js +3 -3
  33. package/esm/ChartsTooltip/ChartsTooltipContainer.d.ts +5 -5
  34. package/esm/ChartsTooltip/ChartsTooltipContainer.js +3 -3
  35. package/esm/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
  36. package/esm/ChartsXAxis/ChartsGroupedXAxis.js +136 -0
  37. package/esm/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
  38. package/esm/ChartsXAxis/ChartsSingleXAxis.js +140 -0
  39. package/esm/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  40. package/esm/ChartsXAxis/ChartsXAxis.js +7 -207
  41. package/esm/ChartsXAxis/getVisibleLabels.d.ts +2 -2
  42. package/esm/ChartsXAxis/useAxisProps.d.ts +4526 -0
  43. package/esm/ChartsXAxis/useAxisProps.js +98 -0
  44. package/esm/ChartsXAxis/utilities.d.ts +11 -0
  45. package/esm/ChartsXAxis/utilities.js +35 -0
  46. package/esm/LineChart/LineChart.js +16 -0
  47. package/esm/RadarChart/index.d.ts +9 -2
  48. package/esm/RadarChart/index.js +12 -2
  49. package/esm/ScatterChart/ScatterChart.d.ts +8 -1
  50. package/esm/ScatterChart/ScatterChart.js +16 -0
  51. package/esm/SparkLineChart/SparkLineChart.js +16 -0
  52. package/esm/hooks/useTicksGrouped.d.ts +28 -0
  53. package/esm/hooks/useTicksGrouped.js +98 -0
  54. package/esm/index.js +1 -1
  55. package/esm/internals/getScale.d.ts +1 -1
  56. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
  57. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +32 -23
  58. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
  59. package/esm/models/axis.d.ts +61 -0
  60. package/hooks/useTicksGrouped.d.ts +28 -0
  61. package/hooks/useTicksGrouped.js +104 -0
  62. package/index.js +1 -1
  63. package/internals/getScale.d.ts +1 -1
  64. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
  65. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +34 -23
  66. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
  67. package/models/axis.d.ts +61 -0
  68. package/package.json +3 -4
@@ -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>;