@mui/x-charts 8.10.0 → 8.10.2

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 (76) hide show
  1. package/BarChart/BarChart.js +4 -0
  2. package/CHANGELOG.md +182 -0
  3. package/ChartContainer/ChartContainer.js +6 -0
  4. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  5. package/ChartsLabel/labelGradientClasses.d.ts +1 -1
  6. package/ChartsLabel/labelMarkClasses.d.ts +1 -1
  7. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
  8. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
  9. package/ChartsTooltip/ChartsTooltipContainer.js +8 -2
  10. package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  11. package/ChartsTooltip/ChartsTooltipTable.js +1 -0
  12. package/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
  13. package/ChartsXAxis/ChartsGroupedXAxis.js +1 -0
  14. package/ChartsXAxis/useAxisProps.d.ts +9 -9
  15. package/ChartsXAxis/utilities.d.ts +1 -1
  16. package/ChartsYAxis/ChartsGroupedYAxis.d.ts +7 -0
  17. package/ChartsYAxis/ChartsGroupedYAxis.js +144 -0
  18. package/ChartsYAxis/ChartsSingleYAxis.d.ts +7 -0
  19. package/ChartsYAxis/ChartsSingleYAxis.js +133 -0
  20. package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
  21. package/ChartsYAxis/ChartsYAxis.js +12 -211
  22. package/ChartsYAxis/useAxisProps.d.ts +4452 -0
  23. package/ChartsYAxis/useAxisProps.js +115 -0
  24. package/ChartsYAxis/utilities.d.ts +10 -0
  25. package/ChartsYAxis/utilities.js +42 -0
  26. package/LineChart/LineChart.js +4 -0
  27. package/ScatterChart/ScatterChart.js +4 -0
  28. package/SparkLineChart/SparkLineChart.d.ts +15 -5
  29. package/SparkLineChart/SparkLineChart.js +61 -34
  30. package/esm/BarChart/BarChart.js +4 -0
  31. package/esm/ChartContainer/ChartContainer.js +6 -0
  32. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  33. package/esm/ChartsLabel/labelGradientClasses.d.ts +1 -1
  34. package/esm/ChartsLabel/labelMarkClasses.d.ts +1 -1
  35. package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
  36. package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
  37. package/esm/ChartsTooltip/ChartsTooltipContainer.js +8 -2
  38. package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  39. package/esm/ChartsTooltip/ChartsTooltipTable.js +1 -0
  40. package/esm/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
  41. package/esm/ChartsXAxis/ChartsGroupedXAxis.js +1 -0
  42. package/esm/ChartsXAxis/useAxisProps.d.ts +9 -9
  43. package/esm/ChartsXAxis/utilities.d.ts +1 -1
  44. package/esm/ChartsYAxis/ChartsGroupedYAxis.d.ts +7 -0
  45. package/esm/ChartsYAxis/ChartsGroupedYAxis.js +138 -0
  46. package/esm/ChartsYAxis/ChartsSingleYAxis.d.ts +7 -0
  47. package/esm/ChartsYAxis/ChartsSingleYAxis.js +129 -0
  48. package/esm/ChartsYAxis/ChartsYAxis.d.ts +1 -1
  49. package/esm/ChartsYAxis/ChartsYAxis.js +10 -207
  50. package/esm/ChartsYAxis/useAxisProps.d.ts +4452 -0
  51. package/esm/ChartsYAxis/useAxisProps.js +108 -0
  52. package/esm/ChartsYAxis/utilities.d.ts +10 -0
  53. package/esm/ChartsYAxis/utilities.js +34 -0
  54. package/esm/LineChart/LineChart.js +4 -0
  55. package/esm/ScatterChart/ScatterChart.js +4 -0
  56. package/esm/SparkLineChart/SparkLineChart.d.ts +15 -5
  57. package/esm/SparkLineChart/SparkLineChart.js +61 -34
  58. package/esm/index.js +1 -1
  59. package/esm/internals/animation/Transition.js +2 -5
  60. package/esm/internals/configInit.js +2 -2
  61. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +1 -1
  62. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -4
  63. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +2 -2
  64. package/esm/internals/plugins/utils/ChartStore.js +16 -18
  65. package/esm/models/axis.d.ts +31 -48
  66. package/esm/tests/web-components.js +2 -4
  67. package/index.js +1 -1
  68. package/internals/animation/Transition.js +2 -5
  69. package/internals/configInit.js +2 -2
  70. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +1 -1
  71. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -4
  72. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +2 -2
  73. package/internals/plugins/utils/ChartStore.js +16 -18
  74. package/models/axis.d.ts +31 -48
  75. package/package.json +16 -17
  76. package/tests/web-components.js +2 -4
@@ -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 --------------------------------