@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,108 @@
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 { useYAxes } 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
+ yAxis,
19
+ yAxisIds
20
+ } = useYAxes();
21
+ const _yAxis = yAxis[inProps.axisId ?? yAxisIds[0]],
22
+ {
23
+ scale: yScale,
24
+ tickNumber,
25
+ reverse
26
+ } = _yAxis,
27
+ settings = _objectWithoutPropertiesLoose(_yAxis, _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: 'MuiChartsYAxis'
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 === 'right' ? 1 : -1;
46
+ const tickFontSize = typeof tickLabelStyle?.fontSize === 'number' ? tickLabelStyle.fontSize : 12;
47
+ const Line = slots?.axisLine ?? 'line';
48
+ const Tick = slots?.axisTick ?? 'line';
49
+ const TickLabel = slots?.axisTickLabel ?? ChartsText;
50
+ const Label = slots?.axisLabel ?? ChartsText;
51
+ const defaultTextAnchor = getDefaultTextAnchor((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0));
52
+ const defaultDominantBaseline = getDefaultBaseline((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0));
53
+ const axisTickLabelProps = useSlotProps({
54
+ elementType: TickLabel,
55
+ externalSlotProps: slotProps?.axisTickLabel,
56
+ additionalProps: {
57
+ style: _extends({}, theme.typography.caption, {
58
+ fontSize: tickFontSize,
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
+ angle: positionSign * 90,
74
+ textAnchor: 'middle',
75
+ dominantBaseline: 'text-before-edge'
76
+ }, labelStyle)
77
+ },
78
+ ownerState: {}
79
+ });
80
+ const lineProps = useSlotProps({
81
+ elementType: Line,
82
+ externalSlotProps: slotProps?.axisLine,
83
+ additionalProps: {
84
+ strokeLinecap: 'square'
85
+ },
86
+ ownerState: {}
87
+ });
88
+ const domain = yScale.domain();
89
+ const isScaleBand = isBandScale(yScale);
90
+ const skipAxisRendering = isScaleBand && domain.length === 0 || !isScaleBand && domain.some(isInfinity) || position === 'none';
91
+ return {
92
+ yScale,
93
+ defaultizedProps,
94
+ tickNumber,
95
+ positionSign,
96
+ skipAxisRendering,
97
+ classes,
98
+ Line,
99
+ Tick,
100
+ TickLabel,
101
+ Label,
102
+ axisTickLabelProps,
103
+ axisLabelProps,
104
+ lineProps,
105
+ reverse,
106
+ isRtl
107
+ };
108
+ };
@@ -0,0 +1,10 @@
1
+ import { AxisConfig, ChartsYAxisProps } from "../models/axis.js";
2
+ export declare const useUtilityClasses: (ownerState: AxisConfig<any, any, ChartsYAxisProps>) => Record<"line" | "root" | "label" | "tickContainer" | "tick" | "tickLabel", string>;
3
+ export declare const TICK_LABEL_GAP = 2;
4
+ export declare const AXIS_LABEL_TICK_LABEL_GAP = 2;
5
+ export declare const YAxisRoot: 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
+ disableLine: boolean;
8
+ disableTicks: boolean;
9
+ tickSize: number;
10
+ };
@@ -0,0 +1,34 @@
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', 'directionY', 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 = 2;
24
+ /* Gap between the axis label and tick labels. */
25
+ export const AXIS_LABEL_TICK_LABEL_GAP = 2;
26
+ export const YAxisRoot = styled(AxisRoot, {
27
+ name: 'MuiChartsYAxis',
28
+ slot: 'Root'
29
+ })({});
30
+ export const defaultProps = {
31
+ disableLine: false,
32
+ disableTicks: false,
33
+ tickSize: 6
34
+ };
@@ -270,6 +270,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
270
270
  disableTicks: PropTypes.bool,
271
271
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
272
272
  fill: PropTypes.string,
273
+ groups: PropTypes.arrayOf(PropTypes.shape({
274
+ getValue: PropTypes.func.isRequired,
275
+ tickLabelStyle: PropTypes.object,
276
+ tickSize: PropTypes.number
277
+ })),
273
278
  height: PropTypes.number,
274
279
  hideTooltip: PropTypes.bool,
275
280
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -321,6 +326,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
321
326
  disableTicks: PropTypes.bool,
322
327
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
323
328
  fill: PropTypes.string,
329
+ groups: PropTypes.arrayOf(PropTypes.shape({
330
+ getValue: PropTypes.func.isRequired,
331
+ tickLabelStyle: PropTypes.object,
332
+ tickSize: PropTypes.number
333
+ })),
324
334
  height: PropTypes.number,
325
335
  hideTooltip: PropTypes.bool,
326
336
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -703,6 +713,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
703
713
  disableTicks: PropTypes.bool,
704
714
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
705
715
  fill: PropTypes.string,
716
+ groups: PropTypes.arrayOf(PropTypes.shape({
717
+ getValue: PropTypes.func.isRequired,
718
+ tickLabelStyle: PropTypes.object,
719
+ tickSize: PropTypes.number
720
+ })),
706
721
  hideTooltip: PropTypes.bool,
707
722
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
708
723
  ignoreTooltip: PropTypes.bool,
@@ -753,6 +768,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
753
768
  disableTicks: PropTypes.bool,
754
769
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
755
770
  fill: PropTypes.string,
771
+ groups: PropTypes.arrayOf(PropTypes.shape({
772
+ getValue: PropTypes.func.isRequired,
773
+ tickLabelStyle: PropTypes.object,
774
+ tickSize: PropTypes.number
775
+ })),
756
776
  hideTooltip: PropTypes.bool,
757
777
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
758
778
  ignoreTooltip: PropTypes.bool,
@@ -1,7 +1,14 @@
1
- export { RadarChart as Unstable_RadarChart } from "./RadarChart.js";
1
+ import { RadarDataProvider } from "./RadarDataProvider/index.js";
2
2
  export { RadarChart } from "./RadarChart.js";
3
- export { RadarDataProvider as Unstable_RadarDataProvider } from "./RadarDataProvider/index.js";
3
+ /**
4
+ * @deprecated radar chart is now stable, import `RadarChart` instead
5
+ */
6
+ export declare const Unstable_RadarChart: import("react").ForwardRefExoticComponent<import("./RadarChart.js").RadarChartProps & import("react").RefAttributes<SVGSVGElement>>;
4
7
  export { RadarDataProvider } from "./RadarDataProvider/index.js";
8
+ /**
9
+ * @deprecated radar data provider is now stable, import `RadarDataProvider` instead
10
+ */
11
+ export declare const Unstable_RadarDataProvider: typeof RadarDataProvider;
5
12
  export type { RadarChartProps, RadarChartSlots, RadarChartSlotProps } from "./RadarChart.js";
6
13
  export type { RadarDataProviderProps, RadarSeries } from "./RadarDataProvider/index.js";
7
14
  export * from "./RadarGrid/index.js";
@@ -1,7 +1,17 @@
1
- export { RadarChart as Unstable_RadarChart } from "./RadarChart.js";
1
+ import { RadarChart } from "./RadarChart.js";
2
+ import { RadarDataProvider } from "./RadarDataProvider/index.js";
2
3
  export { RadarChart } from "./RadarChart.js";
3
- export { RadarDataProvider as Unstable_RadarDataProvider } from "./RadarDataProvider/index.js";
4
+ /**
5
+ * @deprecated radar chart is now stable, import `RadarChart` instead
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ export const Unstable_RadarChart = RadarChart;
4
9
  export { RadarDataProvider } from "./RadarDataProvider/index.js";
10
+ /**
11
+ * @deprecated radar data provider is now stable, import `RadarDataProvider` instead
12
+ */
13
+ // eslint-disable-next-line @typescript-eslint/naming-convention
14
+ export const Unstable_RadarDataProvider = RadarDataProvider;
5
15
  export * from "./RadarGrid/index.js";
6
16
  export * from "./RadarAxisHighlight/index.js";
7
17
  export * from "./RadarMetricLabels/index.js";
@@ -6,6 +6,7 @@ import { ScatterPlotProps, ScatterPlotSlotProps, ScatterPlotSlots } from "./Scat
6
6
  import { ChartContainerProps } from "../ChartContainer/index.js";
7
7
  import { ChartsAxisProps } from "../ChartsAxis/index.js";
8
8
  import { ScatterSeriesType } from "../models/seriesType/scatter.js";
9
+ import { ChartsTooltipProps } from "../ChartsTooltip/index.js";
9
10
  import { ChartsTooltipSlots, ChartsTooltipSlotProps } from "../ChartsTooltip/ChartTooltip.types.js";
10
11
  import { ChartsLegendSlotProps, ChartsLegendSlots } from "../ChartsLegend/index.js";
11
12
  import { ChartsOverlayProps, ChartsOverlaySlotProps, ChartsOverlaySlots } from "../ChartsOverlay/index.js";
@@ -15,7 +16,13 @@ import { ChartsGridProps } from "../ChartsGrid/index.js";
15
16
  import { UseChartVoronoiSignature } from "../internals/plugins/featurePlugins/useChartVoronoi/index.js";
16
17
  import { ScatterChartPluginsSignatures } from "./ScatterChart.plugins.js";
17
18
  export interface ScatterChartSlots extends ChartsAxisSlots, ScatterPlotSlots, ChartsLegendSlots, ChartsOverlaySlots, ChartsTooltipSlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
18
- export interface ScatterChartSlotProps extends ChartsAxisSlotProps, ScatterPlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, ChartsTooltipSlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {}
19
+ export interface ScatterChartSlotProps extends ChartsAxisSlotProps, ScatterPlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, Omit<ChartsTooltipSlotProps, 'tooltip'>, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {
20
+ /**
21
+ * Slot props for the tooltip component.
22
+ * @default {}
23
+ */
24
+ tooltip?: Partial<ChartsTooltipProps<'item' | 'none'>>;
25
+ }
19
26
  export type ScatterSeries = MakeOptional<ScatterSeriesType, 'type'>;
20
27
  export interface ScatterChartProps extends Omit<ChartContainerProps<'scatter', ScatterChartPluginsSignatures>, 'series' | 'plugins' | 'onItemClick' | 'experimentalFeatures' | 'highlightedAxis' | 'onHighlightedAxisChange'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'> {
21
28
  /**
@@ -239,6 +239,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
239
239
  disableTicks: PropTypes.bool,
240
240
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
241
241
  fill: PropTypes.string,
242
+ groups: PropTypes.arrayOf(PropTypes.shape({
243
+ getValue: PropTypes.func.isRequired,
244
+ tickLabelStyle: PropTypes.object,
245
+ tickSize: PropTypes.number
246
+ })),
242
247
  height: PropTypes.number,
243
248
  hideTooltip: PropTypes.bool,
244
249
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -290,6 +295,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
290
295
  disableTicks: PropTypes.bool,
291
296
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
292
297
  fill: PropTypes.string,
298
+ groups: PropTypes.arrayOf(PropTypes.shape({
299
+ getValue: PropTypes.func.isRequired,
300
+ tickLabelStyle: PropTypes.object,
301
+ tickSize: PropTypes.number
302
+ })),
293
303
  height: PropTypes.number,
294
304
  hideTooltip: PropTypes.bool,
295
305
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -672,6 +682,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
672
682
  disableTicks: PropTypes.bool,
673
683
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
674
684
  fill: PropTypes.string,
685
+ groups: PropTypes.arrayOf(PropTypes.shape({
686
+ getValue: PropTypes.func.isRequired,
687
+ tickLabelStyle: PropTypes.object,
688
+ tickSize: PropTypes.number
689
+ })),
675
690
  hideTooltip: PropTypes.bool,
676
691
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
677
692
  ignoreTooltip: PropTypes.bool,
@@ -722,6 +737,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
722
737
  disableTicks: PropTypes.bool,
723
738
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
724
739
  fill: PropTypes.string,
740
+ groups: PropTypes.arrayOf(PropTypes.shape({
741
+ getValue: PropTypes.func.isRequired,
742
+ tickLabelStyle: PropTypes.object,
743
+ tickSize: PropTypes.number
744
+ })),
725
745
  hideTooltip: PropTypes.bool,
726
746
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
727
747
  ignoreTooltip: PropTypes.bool,
@@ -13,7 +13,7 @@ import { BarPlotSlots, BarPlotSlotProps } from "../BarChart/BarPlot.js";
13
13
  import { ChartMargin } from "../internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.js";
14
14
  export interface SparkLineChartSlots extends AreaPlotSlots, LinePlotSlots, MarkPlotSlots, LineHighlightPlotSlots, Omit<BarPlotSlots, 'barLabel'>, ChartsTooltipSlots {}
15
15
  export interface SparkLineChartSlotProps extends AreaPlotSlotProps, LinePlotSlotProps, MarkPlotSlotProps, LineHighlightPlotSlotProps, BarPlotSlotProps, ChartsTooltipSlotProps {}
16
- export interface SparkLineChartProps extends Omit<ChartContainerProps, 'series' | 'xAxis' | 'yAxis' | 'zAxis' | 'radiusAxis' | 'rotationAxis' | 'margin' | 'plugins' | 'colors' | 'slots' | 'slotProps' | 'experimentalFeatures'> {
16
+ export interface SparkLineChartProps<PlotType extends 'line' | 'bar' = 'line' | 'bar'> extends Omit<ChartContainerProps, 'series' | 'xAxis' | 'yAxis' | 'zAxis' | 'radiusAxis' | 'rotationAxis' | 'margin' | 'plugins' | 'colors' | 'slots' | 'slotProps' | 'experimentalFeatures'> {
17
17
  /**
18
18
  * The xAxis configuration.
19
19
  * Notice it is a single [[AxisConfig]] object, not an array of configuration.
@@ -29,7 +29,7 @@ export interface SparkLineChartProps extends Omit<ChartContainerProps, 'series'
29
29
  * Type of plot used.
30
30
  * @default 'line'
31
31
  */
32
- plotType?: 'line' | 'bar';
32
+ plotType?: PlotType;
33
33
  /**
34
34
  * Data to plot.
35
35
  */
@@ -58,11 +58,21 @@ export interface SparkLineChartProps extends Omit<ChartContainerProps, 'series'
58
58
  * Has no effect if plotType='bar'.
59
59
  * @default false
60
60
  */
61
- area?: LineSeriesType['area'];
61
+ area?: PlotType extends 'line' ? LineSeriesType['area'] : never;
62
62
  /**
63
63
  * @default 'linear'
64
64
  */
65
- curve?: LineSeriesType['curve'];
65
+ curve?: PlotType extends 'line' ? LineSeriesType['curve'] : never;
66
+ /**
67
+ * The value of the line at the base of the series area.
68
+ *
69
+ * - `'min'` the area will fill the space **under** the line.
70
+ * - `'max'` the area will fill the space **above** the line.
71
+ * - `number` the area will fill the space between this value and the line
72
+ *
73
+ * @default 0
74
+ */
75
+ baseline?: PlotType extends 'line' ? LineSeriesType['baseline'] : never;
66
76
  /**
67
77
  * The margin between the SVG and the drawing area.
68
78
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
@@ -115,5 +125,5 @@ export interface SparkLineChartProps extends Omit<ChartContainerProps, 'series'
115
125
  *
116
126
  * - [SparkLineChart API](https://mui.com/x/api/charts/spark-line-chart/)
117
127
  */
118
- declare const SparkLineChart: React.ForwardRefExoticComponent<SparkLineChartProps & React.RefAttributes<SVGSVGElement>>;
128
+ declare const SparkLineChart: React.ForwardRefExoticComponent<SparkLineChartProps<"line" | "bar"> & React.RefAttributes<SVGSVGElement>>;
119
129
  export { SparkLineChart };
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["xAxis", "yAxis", "width", "height", "margin", "color", "sx", "showTooltip", "showHighlight", "axisHighlight", "children", "slots", "slotProps", "data", "plotType", "valueFormatter", "area", "curve", "className", "disableClipping", "clipAreaOffset"];
5
+ const _excluded = ["xAxis", "yAxis", "width", "height", "margin", "color", "baseline", "sx", "showTooltip", "showHighlight", "axisHighlight", "children", "slots", "slotProps", "data", "plotType", "valueFormatter", "area", "curve", "className", "disableClipping", "clipAreaOffset", "onHighlightChange", "onHighlightedAxisChange", "highlightedAxis", "highlightedItem"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import useId from '@mui/utils/useId';
@@ -28,12 +28,13 @@ const SPARK_LINE_DEFAULT_MARGIN = 5;
28
28
  */
29
29
  const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
30
30
  const {
31
- xAxis,
32
- yAxis,
31
+ xAxis: xAxisProps,
32
+ yAxis: yAxisProps,
33
33
  width,
34
34
  height,
35
35
  margin = SPARK_LINE_DEFAULT_MARGIN,
36
36
  color,
37
+ baseline,
37
38
  sx,
38
39
  showTooltip,
39
40
  showHighlight,
@@ -48,23 +49,27 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
48
49
  curve = 'linear',
49
50
  className,
50
51
  disableClipping,
51
- clipAreaOffset
52
+ clipAreaOffset,
53
+ onHighlightChange,
54
+ onHighlightedAxisChange,
55
+ highlightedAxis,
56
+ highlightedItem
52
57
  } = props,
53
58
  other = _objectWithoutPropertiesLoose(props, _excluded);
54
59
  const id = useId();
55
60
  const clipPathId = `${id}-clip-path`;
56
- const clipPathOffset = {
61
+ const clipPathOffset = React.useMemo(() => ({
57
62
  top: clipAreaOffset?.top ?? 1,
58
63
  right: clipAreaOffset?.right ?? 1,
59
64
  bottom: clipAreaOffset?.bottom ?? 1,
60
65
  left: clipAreaOffset?.left ?? 1
61
- };
62
- const defaultXHighlight = showHighlight && plotType === 'bar' ? {
66
+ }), [clipAreaOffset?.bottom, clipAreaOffset?.left, clipAreaOffset?.right, clipAreaOffset?.top]);
67
+ const defaultXHighlight = React.useMemo(() => showHighlight && plotType === 'bar' ? {
63
68
  x: 'band'
64
69
  } : {
65
70
  x: 'none'
66
- };
67
- const axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
71
+ }, [plotType, showHighlight]);
72
+ const axisHighlight = React.useMemo(() => _extends({}, defaultXHighlight, inAxisHighlight), [defaultXHighlight, inAxisHighlight]);
68
73
  const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
69
74
  const colors = React.useMemo(() => {
70
75
  if (color == null) {
@@ -72,36 +77,44 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
72
77
  }
73
78
  return typeof color === 'function' ? mode => [color(mode)] : [color];
74
79
  }, [color]);
80
+ const series = React.useMemo(() => [_extends({
81
+ type: plotType,
82
+ data,
83
+ valueFormatter
84
+ }, plotType === 'bar' ? {} : {
85
+ area,
86
+ curve,
87
+ baseline,
88
+ disableHighlight: !showHighlight
89
+ })], [area, baseline, curve, data, plotType, showHighlight, valueFormatter]);
90
+ const xAxis = React.useMemo(() => [_extends({
91
+ id: DEFAULT_X_AXIS_KEY,
92
+ scaleType: plotType === 'bar' ? 'band' : 'point',
93
+ hideTooltip: xAxisProps === undefined
94
+ }, xAxisProps, {
95
+ data: xAxisProps?.data ?? Array.from({
96
+ length: data.length
97
+ }, (_, index) => index),
98
+ position: 'none'
99
+ })], [data.length, plotType, xAxisProps]);
100
+ const yAxis = React.useMemo(() => [_extends({
101
+ id: DEFAULT_Y_AXIS_KEY
102
+ }, yAxisProps, {
103
+ position: 'none'
104
+ })], [yAxisProps]);
75
105
  return /*#__PURE__*/_jsxs(ChartDataProvider, {
76
- series: [_extends({
77
- type: plotType,
78
- data,
79
- valueFormatter
80
- }, plotType === 'bar' ? {} : {
81
- area,
82
- curve,
83
- disableHighlight: !showHighlight
84
- })],
106
+ series: series,
85
107
  width: width,
86
108
  height: height,
87
109
  margin: margin,
88
- xAxis: [_extends({
89
- id: DEFAULT_X_AXIS_KEY,
90
- scaleType: plotType === 'bar' ? 'band' : 'point',
91
- data: Array.from({
92
- length: data.length
93
- }, (_, index) => index),
94
- hideTooltip: xAxis === undefined
95
- }, xAxis, {
96
- position: 'none'
97
- })],
98
- yAxis: [_extends({
99
- id: DEFAULT_Y_AXIS_KEY
100
- }, yAxis, {
101
- position: 'none'
102
- })],
110
+ xAxis: xAxis,
111
+ yAxis: yAxis,
103
112
  colors: colors,
104
- disableAxisListener: (!showTooltip || slotProps?.tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
113
+ disableAxisListener: onHighlightedAxisChange === undefined && (!showTooltip || slotProps?.tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
114
+ onHighlightChange: onHighlightChange,
115
+ onHighlightedAxisChange: onHighlightedAxisChange,
116
+ highlightedAxis: highlightedAxis,
117
+ highlightedItem: highlightedItem,
105
118
  children: [/*#__PURE__*/_jsxs(ChartsSurface, _extends({
106
119
  className: className,
107
120
  ref: ref,
@@ -153,6 +166,16 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
153
166
  x: PropTypes.oneOf(['band', 'line', 'none']),
154
167
  y: PropTypes.oneOf(['band', 'line', 'none'])
155
168
  }),
169
+ /**
170
+ * The value of the line at the base of the series area.
171
+ *
172
+ * - `'min'` the area will fill the space **under** the line.
173
+ * - `'max'` the area will fill the space **above** the line.
174
+ * - `number` the area will fill the space between this value and the line
175
+ *
176
+ * @default 0
177
+ */
178
+ baseline: PropTypes.oneOfType([PropTypes.oneOf(['max', 'min']), PropTypes.number]),
156
179
  children: PropTypes.node,
157
180
  className: PropTypes.string,
158
181
  /**
@@ -353,6 +376,11 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
353
376
  disableTicks: PropTypes.bool,
354
377
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
355
378
  fill: PropTypes.string,
379
+ groups: PropTypes.arrayOf(PropTypes.shape({
380
+ getValue: PropTypes.func.isRequired,
381
+ tickLabelStyle: PropTypes.object,
382
+ tickSize: PropTypes.number
383
+ })),
356
384
  height: PropTypes.number,
357
385
  hideTooltip: PropTypes.bool,
358
386
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -404,6 +432,11 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
404
432
  disableTicks: PropTypes.bool,
405
433
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
406
434
  fill: PropTypes.string,
435
+ groups: PropTypes.arrayOf(PropTypes.shape({
436
+ getValue: PropTypes.func.isRequired,
437
+ tickLabelStyle: PropTypes.object,
438
+ tickSize: PropTypes.number
439
+ })),
407
440
  height: PropTypes.number,
408
441
  hideTooltip: PropTypes.bool,
409
442
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -785,6 +818,11 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
785
818
  disableTicks: PropTypes.bool,
786
819
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
787
820
  fill: PropTypes.string,
821
+ groups: PropTypes.arrayOf(PropTypes.shape({
822
+ getValue: PropTypes.func.isRequired,
823
+ tickLabelStyle: PropTypes.object,
824
+ tickSize: PropTypes.number
825
+ })),
788
826
  hideTooltip: PropTypes.bool,
789
827
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
790
828
  ignoreTooltip: PropTypes.bool,
@@ -835,6 +873,11 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
835
873
  disableTicks: PropTypes.bool,
836
874
  domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
837
875
  fill: PropTypes.string,
876
+ groups: PropTypes.arrayOf(PropTypes.shape({
877
+ getValue: PropTypes.func.isRequired,
878
+ tickLabelStyle: PropTypes.object,
879
+ tickSize: PropTypes.number
880
+ })),
838
881
  hideTooltip: PropTypes.bool,
839
882
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
840
883
  ignoreTooltip: PropTypes.bool,
@@ -0,0 +1,28 @@
1
+ import type { ScaleBand, ScalePoint } from '@mui/x-charts-vendor/d3-scale';
2
+ import { AxisConfig, type AxisGroup } from "../models/axis.js";
3
+ import type { TickParams } from "./useTicks.js";
4
+ export type GroupedTickItemType = {
5
+ /**
6
+ * This property is undefined only if it's the tick closing the last band
7
+ */
8
+ value?: any;
9
+ formattedValue?: string;
10
+ offset: number;
11
+ labelOffset: number;
12
+ /**
13
+ * In band scales, we remove some redundant ticks.
14
+ */
15
+ ignoreTick?: boolean;
16
+ dataIndex?: number;
17
+ /**
18
+ * The index of the group this tick belongs to. If `getGrouping` returns `[[0, 1], [2, 3]]`
19
+ * both ticks with value `0` and `2` will have `groupIndex: 0`, and both ticks with value `1` and `3` will have `groupIndex: 1`.
20
+ */
21
+ groupIndex?: number;
22
+ };
23
+ export declare function useTicksGrouped(options: {
24
+ scale: ScaleBand<any> | ScalePoint<any>;
25
+ valueFormatter?: AxisConfig['valueFormatter'];
26
+ direction: 'x' | 'y';
27
+ groups: AxisGroup[];
28
+ } & Pick<TickParams, 'tickNumber' | 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'>): GroupedTickItemType[];