@mui/x-charts 8.10.0 → 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.
- package/BarChart/BarChart.js +4 -0
- package/CHANGELOG.md +96 -0
- package/ChartContainer/ChartContainer.js +6 -0
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/ChartsLabel/labelGradientClasses.d.ts +1 -1
- package/ChartsLabel/labelMarkClasses.d.ts +1 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
- package/ChartsTooltip/ChartsTooltipContainer.js +8 -2
- package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
- package/ChartsTooltip/ChartsTooltipTable.js +1 -0
- package/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
- package/ChartsXAxis/ChartsGroupedXAxis.js +1 -0
- package/ChartsXAxis/useAxisProps.d.ts +9 -9
- package/ChartsXAxis/utilities.d.ts +1 -1
- package/ChartsYAxis/ChartsGroupedYAxis.d.ts +7 -0
- package/ChartsYAxis/ChartsGroupedYAxis.js +144 -0
- package/ChartsYAxis/ChartsSingleYAxis.d.ts +7 -0
- package/ChartsYAxis/ChartsSingleYAxis.js +133 -0
- package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
- package/ChartsYAxis/ChartsYAxis.js +12 -211
- package/ChartsYAxis/useAxisProps.d.ts +4452 -0
- package/ChartsYAxis/useAxisProps.js +115 -0
- package/ChartsYAxis/utilities.d.ts +10 -0
- package/ChartsYAxis/utilities.js +42 -0
- package/LineChart/LineChart.js +4 -0
- package/ScatterChart/ScatterChart.js +4 -0
- package/SparkLineChart/SparkLineChart.d.ts +15 -5
- package/SparkLineChart/SparkLineChart.js +61 -34
- package/esm/BarChart/BarChart.js +4 -0
- package/esm/ChartContainer/ChartContainer.js +6 -0
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/esm/ChartsLabel/labelGradientClasses.d.ts +1 -1
- package/esm/ChartsLabel/labelMarkClasses.d.ts +1 -1
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +8 -2
- package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
- package/esm/ChartsTooltip/ChartsTooltipTable.js +1 -0
- package/esm/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
- package/esm/ChartsXAxis/ChartsGroupedXAxis.js +1 -0
- package/esm/ChartsXAxis/useAxisProps.d.ts +9 -9
- package/esm/ChartsXAxis/utilities.d.ts +1 -1
- package/esm/ChartsYAxis/ChartsGroupedYAxis.d.ts +7 -0
- package/esm/ChartsYAxis/ChartsGroupedYAxis.js +138 -0
- package/esm/ChartsYAxis/ChartsSingleYAxis.d.ts +7 -0
- package/esm/ChartsYAxis/ChartsSingleYAxis.js +129 -0
- package/esm/ChartsYAxis/ChartsYAxis.d.ts +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +10 -207
- package/esm/ChartsYAxis/useAxisProps.d.ts +4452 -0
- package/esm/ChartsYAxis/useAxisProps.js +108 -0
- package/esm/ChartsYAxis/utilities.d.ts +10 -0
- package/esm/ChartsYAxis/utilities.js +34 -0
- package/esm/LineChart/LineChart.js +4 -0
- package/esm/ScatterChart/ScatterChart.js +4 -0
- package/esm/SparkLineChart/SparkLineChart.d.ts +15 -5
- package/esm/SparkLineChart/SparkLineChart.js +61 -34
- package/esm/index.js +1 -1
- package/esm/internals/animation/Transition.js +2 -5
- package/esm/internals/configInit.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -4
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +2 -2
- package/esm/internals/plugins/utils/ChartStore.js +16 -18
- package/esm/models/axis.d.ts +31 -48
- package/esm/tests/web-components.js +2 -4
- package/index.js +1 -1
- package/internals/animation/Transition.js +2 -5
- package/internals/configInit.js +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -4
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +2 -2
- package/internals/plugins/utils/ChartStore.js +16 -18
- package/models/axis.d.ts +31 -48
- package/package.json +16 -17
- 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
|
+
};
|
|
@@ -272,6 +272,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
272
272
|
fill: PropTypes.string,
|
|
273
273
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
274
274
|
getValue: PropTypes.func.isRequired,
|
|
275
|
+
tickLabelStyle: PropTypes.object,
|
|
275
276
|
tickSize: PropTypes.number
|
|
276
277
|
})),
|
|
277
278
|
height: PropTypes.number,
|
|
@@ -327,6 +328,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
327
328
|
fill: PropTypes.string,
|
|
328
329
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
329
330
|
getValue: PropTypes.func.isRequired,
|
|
331
|
+
tickLabelStyle: PropTypes.object,
|
|
330
332
|
tickSize: PropTypes.number
|
|
331
333
|
})),
|
|
332
334
|
height: PropTypes.number,
|
|
@@ -713,6 +715,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
713
715
|
fill: PropTypes.string,
|
|
714
716
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
715
717
|
getValue: PropTypes.func.isRequired,
|
|
718
|
+
tickLabelStyle: PropTypes.object,
|
|
716
719
|
tickSize: PropTypes.number
|
|
717
720
|
})),
|
|
718
721
|
hideTooltip: PropTypes.bool,
|
|
@@ -767,6 +770,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
767
770
|
fill: PropTypes.string,
|
|
768
771
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
769
772
|
getValue: PropTypes.func.isRequired,
|
|
773
|
+
tickLabelStyle: PropTypes.object,
|
|
770
774
|
tickSize: PropTypes.number
|
|
771
775
|
})),
|
|
772
776
|
hideTooltip: PropTypes.bool,
|
|
@@ -241,6 +241,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
241
241
|
fill: PropTypes.string,
|
|
242
242
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
243
243
|
getValue: PropTypes.func.isRequired,
|
|
244
|
+
tickLabelStyle: PropTypes.object,
|
|
244
245
|
tickSize: PropTypes.number
|
|
245
246
|
})),
|
|
246
247
|
height: PropTypes.number,
|
|
@@ -296,6 +297,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
296
297
|
fill: PropTypes.string,
|
|
297
298
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
298
299
|
getValue: PropTypes.func.isRequired,
|
|
300
|
+
tickLabelStyle: PropTypes.object,
|
|
299
301
|
tickSize: PropTypes.number
|
|
300
302
|
})),
|
|
301
303
|
height: PropTypes.number,
|
|
@@ -682,6 +684,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
682
684
|
fill: PropTypes.string,
|
|
683
685
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
684
686
|
getValue: PropTypes.func.isRequired,
|
|
687
|
+
tickLabelStyle: PropTypes.object,
|
|
685
688
|
tickSize: PropTypes.number
|
|
686
689
|
})),
|
|
687
690
|
hideTooltip: PropTypes.bool,
|
|
@@ -736,6 +739,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
736
739
|
fill: PropTypes.string,
|
|
737
740
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
738
741
|
getValue: PropTypes.func.isRequired,
|
|
742
|
+
tickLabelStyle: PropTypes.object,
|
|
739
743
|
tickSize: PropTypes.number
|
|
740
744
|
})),
|
|
741
745
|
hideTooltip: 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?:
|
|
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:
|
|
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:
|
|
89
|
-
|
|
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
|
/**
|
|
@@ -355,6 +378,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
355
378
|
fill: PropTypes.string,
|
|
356
379
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
357
380
|
getValue: PropTypes.func.isRequired,
|
|
381
|
+
tickLabelStyle: PropTypes.object,
|
|
358
382
|
tickSize: PropTypes.number
|
|
359
383
|
})),
|
|
360
384
|
height: PropTypes.number,
|
|
@@ -410,6 +434,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
410
434
|
fill: PropTypes.string,
|
|
411
435
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
412
436
|
getValue: PropTypes.func.isRequired,
|
|
437
|
+
tickLabelStyle: PropTypes.object,
|
|
413
438
|
tickSize: PropTypes.number
|
|
414
439
|
})),
|
|
415
440
|
height: PropTypes.number,
|
|
@@ -795,6 +820,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
795
820
|
fill: PropTypes.string,
|
|
796
821
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
797
822
|
getValue: PropTypes.func.isRequired,
|
|
823
|
+
tickLabelStyle: PropTypes.object,
|
|
798
824
|
tickSize: PropTypes.number
|
|
799
825
|
})),
|
|
800
826
|
hideTooltip: PropTypes.bool,
|
|
@@ -849,6 +875,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
849
875
|
fill: PropTypes.string,
|
|
850
876
|
groups: PropTypes.arrayOf(PropTypes.shape({
|
|
851
877
|
getValue: PropTypes.func.isRequired,
|
|
878
|
+
tickLabelStyle: PropTypes.object,
|
|
852
879
|
tickSize: PropTypes.number
|
|
853
880
|
})),
|
|
854
881
|
hideTooltip: PropTypes.bool,
|
package/esm/index.js
CHANGED
|
@@ -10,6 +10,8 @@ import { timer, now, timeout, timerFlush } from '@mui/x-charts-vendor/d3-timer';
|
|
|
10
10
|
* stopped.
|
|
11
11
|
*/
|
|
12
12
|
export class Transition {
|
|
13
|
+
elapsed = 0;
|
|
14
|
+
timer = null;
|
|
13
15
|
/**
|
|
14
16
|
* Create a new ResumableTransition.
|
|
15
17
|
* @param duration Duration in milliseconds
|
|
@@ -17,11 +19,6 @@ export class Transition {
|
|
|
17
19
|
* @param onTick Callback function called on each animation frame with the eased time in range [0, 1].
|
|
18
20
|
*/
|
|
19
21
|
constructor(duration, easingFn, onTick) {
|
|
20
|
-
this.duration = void 0;
|
|
21
|
-
this.elapsed = 0;
|
|
22
|
-
this.easingFn = void 0;
|
|
23
|
-
this.timer = null;
|
|
24
|
-
this.onTickCallback = void 0;
|
|
25
22
|
this.duration = duration;
|
|
26
23
|
this.easingFn = easingFn;
|
|
27
24
|
this.onTickCallback = onTick;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
let cartesianInstance;
|
|
2
2
|
let polarInstance;
|
|
3
3
|
class CartesianSeriesTypes {
|
|
4
|
+
types = (() => new Set())();
|
|
4
5
|
constructor() {
|
|
5
|
-
this.types = new Set();
|
|
6
6
|
if (cartesianInstance) {
|
|
7
7
|
throw new Error('You can only create one instance!');
|
|
8
8
|
}
|
|
@@ -16,8 +16,8 @@ class CartesianSeriesTypes {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
class PolarSeriesTypes {
|
|
19
|
+
types = (() => new Set())();
|
|
19
20
|
constructor() {
|
|
20
|
-
this.types = new Set();
|
|
21
21
|
if (polarInstance) {
|
|
22
22
|
throw new Error('You can only create one instance!');
|
|
23
23
|
}
|
|
@@ -8,4 +8,4 @@ export declare function getAxisIndex(axisConfig: ComputedAxis, pointerValue: num
|
|
|
8
8
|
* For a pointer coordinate, this function returns the value associated.
|
|
9
9
|
* Returns `null` if the coordinate has no value associated.
|
|
10
10
|
*/
|
|
11
|
-
export declare function getAxisValue(axisConfig: ComputedAxis, pointerValue: number, dataIndex: number): number | Date | null;
|
|
11
|
+
export declare function getAxisValue(axisConfig: ComputedAxis, pointerValue: number, dataIndex: number | null): number | Date | null;
|
|
@@ -52,13 +52,12 @@ export function getAxisValue(axisConfig, pointerValue, dataIndex) {
|
|
|
52
52
|
data: axisData
|
|
53
53
|
} = axisConfig;
|
|
54
54
|
if (!isBandScale(scale)) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return value;
|
|
55
|
+
if (dataIndex === null) {
|
|
56
|
+
return scale.invert(pointerValue);
|
|
58
57
|
}
|
|
59
58
|
return axisData[dataIndex];
|
|
60
59
|
}
|
|
61
|
-
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
60
|
+
if (dataIndex === null || dataIndex < 0 || dataIndex >= axisData.length) {
|
|
62
61
|
return null;
|
|
63
62
|
}
|
|
64
63
|
return axisData[dataIndex];
|
|
@@ -37,13 +37,13 @@ function valueGetter(value, axes, indexes, ids = axes.axisIds[0]) {
|
|
|
37
37
|
return Array.isArray(ids) ? ids.map((id, axisIndex) => getAxisValue(axes.axis[id], value, indexes[axisIndex])) : getAxisValue(axes.axis[ids], value, indexes);
|
|
38
38
|
}
|
|
39
39
|
export const selectorChartsInteractionXAxisValue = createSelector([selectorChartsInteractionPointerX, selectorChartXAxis, selectorChartsInteractionXAxisIndex, optionalGetAxisId], (x, xAxes, xIndex, id) => {
|
|
40
|
-
if (x === null ||
|
|
40
|
+
if (x === null || xAxes.axisIds.length === 0) {
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
return valueGetter(x, xAxes, xIndex, id);
|
|
44
44
|
});
|
|
45
45
|
export const selectorChartsInteractionYAxisValue = createSelector([selectorChartsInteractionPointerY, selectorChartYAxis, selectorChartsInteractionYAxisIndex, optionalGetAxisId], (y, yAxes, yIndex, id) => {
|
|
46
|
-
if (y === null ||
|
|
46
|
+
if (y === null || yAxes.axisIds.length === 0) {
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
49
|
return valueGetter(y, yAxes, yIndex, id);
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
export class ChartStore {
|
|
2
2
|
constructor(value) {
|
|
3
|
-
this.value = void 0;
|
|
4
|
-
this.listeners = void 0;
|
|
5
|
-
this.subscribe = fn => {
|
|
6
|
-
this.listeners.add(fn);
|
|
7
|
-
return () => {
|
|
8
|
-
this.listeners.delete(fn);
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
this.getSnapshot = () => {
|
|
12
|
-
return this.value;
|
|
13
|
-
};
|
|
14
|
-
this.update = updater => {
|
|
15
|
-
const newState = updater(this.value);
|
|
16
|
-
if (newState !== this.value) {
|
|
17
|
-
this.value = newState;
|
|
18
|
-
this.listeners.forEach(l => l(newState));
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
3
|
this.value = value;
|
|
22
4
|
this.listeners = new Set();
|
|
23
5
|
}
|
|
6
|
+
subscribe = fn => {
|
|
7
|
+
this.listeners.add(fn);
|
|
8
|
+
return () => {
|
|
9
|
+
this.listeners.delete(fn);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
getSnapshot = () => {
|
|
13
|
+
return this.value;
|
|
14
|
+
};
|
|
15
|
+
update = updater => {
|
|
16
|
+
const newState = updater(this.value);
|
|
17
|
+
if (newState !== this.value) {
|
|
18
|
+
this.value = newState;
|
|
19
|
+
this.listeners.forEach(l => l(newState));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
24
22
|
}
|
package/esm/models/axis.d.ts
CHANGED
|
@@ -194,6 +194,35 @@ export type AxisGroup = {
|
|
|
194
194
|
* @default 6
|
|
195
195
|
*/
|
|
196
196
|
tickSize?: number;
|
|
197
|
+
/**
|
|
198
|
+
* The style applied to ticks text.
|
|
199
|
+
*/
|
|
200
|
+
tickLabelStyle?: ChartsTextProps['style'];
|
|
201
|
+
};
|
|
202
|
+
export type AxisGroups = {
|
|
203
|
+
/**
|
|
204
|
+
* Each group will have a label that is the stringified value of the group.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* If the axis is grouped by day, month and year.
|
|
208
|
+
*
|
|
209
|
+
* ```tsx
|
|
210
|
+
* [
|
|
211
|
+
* { getValue: getDate },
|
|
212
|
+
* { getValue: getMonth },
|
|
213
|
+
* { getValue: getFullYear }
|
|
214
|
+
* ]
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* Then the axis will have three rows, one for each group.
|
|
218
|
+
*
|
|
219
|
+
* ```bash
|
|
220
|
+
* | 31 | 1 | 2 |
|
|
221
|
+
* | Jan | Feb |
|
|
222
|
+
* | 2021 |
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
groups?: AxisGroup[];
|
|
197
226
|
};
|
|
198
227
|
export interface AxisScaleConfig {
|
|
199
228
|
band: {
|
|
@@ -212,58 +241,12 @@ export interface AxisScaleConfig {
|
|
|
212
241
|
*/
|
|
213
242
|
barGapRatio: number;
|
|
214
243
|
colorMap?: OrdinalColorConfig | ContinuousColorConfig | PiecewiseColorConfig;
|
|
215
|
-
|
|
216
|
-
* Each group will have a label that is the stringified value of the group.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* If the axis is grouped by day, month and year.
|
|
220
|
-
*
|
|
221
|
-
* ```tsx
|
|
222
|
-
* [
|
|
223
|
-
* { getValue: getDate },
|
|
224
|
-
* { getValue: getMonth },
|
|
225
|
-
* { getValue: getFullYear }
|
|
226
|
-
* ]
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* Then the axis will have three rows, one for each group.
|
|
230
|
-
*
|
|
231
|
-
* ```bash
|
|
232
|
-
* | 31 | 1 | 2 |
|
|
233
|
-
* | Jan | Feb |
|
|
234
|
-
* | 2021 |
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
groups?: AxisGroup[];
|
|
238
|
-
} & Pick<TickParams, 'tickPlacement' | 'tickLabelPlacement'>;
|
|
244
|
+
} & AxisGroups & Pick<TickParams, 'tickPlacement' | 'tickLabelPlacement'>;
|
|
239
245
|
point: {
|
|
240
246
|
scaleType: 'point';
|
|
241
247
|
scale: ScalePoint<number | Date | string>;
|
|
242
248
|
colorMap?: OrdinalColorConfig | ContinuousColorConfig | PiecewiseColorConfig;
|
|
243
|
-
|
|
244
|
-
* Each group will have a label that is the stringified value of the group.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* If the axis is grouped by day, month and year.
|
|
248
|
-
*
|
|
249
|
-
* ```tsx
|
|
250
|
-
* [
|
|
251
|
-
* { getValue: getDate },
|
|
252
|
-
* { getValue: getMonth },
|
|
253
|
-
* { getValue: getFullYear }
|
|
254
|
-
* ]
|
|
255
|
-
* ```
|
|
256
|
-
*
|
|
257
|
-
* Then the axis will have three rows, one for each group.
|
|
258
|
-
*
|
|
259
|
-
* ```bash
|
|
260
|
-
* | 31 | 1 | 2 |
|
|
261
|
-
* | Jan | Feb |
|
|
262
|
-
* | 2021 |
|
|
263
|
-
* ```
|
|
264
|
-
*/
|
|
265
|
-
groups?: AxisGroup[];
|
|
266
|
-
};
|
|
249
|
+
} & AxisGroups;
|
|
267
250
|
log: {
|
|
268
251
|
scaleType: 'log';
|
|
269
252
|
scale: ScaleLogarithmic<number, number>;
|