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