@mui/x-charts 6.0.0-alpha.15 → 6.0.0-alpha.17
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.d.ts +13 -2
- package/BarChart/BarChart.js +45 -3
- package/BarChart/BarElement.d.ts +1318 -3
- package/BarChart/BarElement.js +10 -8
- package/BarChart/BarPlot.d.ts +17 -1
- package/BarChart/BarPlot.js +152 -66
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +131 -0
- package/ChartContainer/index.js +5 -2
- package/ChartsAxis/ChartsAxis.js +18 -2
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/ChartsClipPath/ChartsClipPath.js +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +2 -1
- package/ChartsLegend/ChartsLegend.js +12 -8
- package/ChartsSurface.js +2 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +29 -23
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsTooltip.js +2 -2
- package/ChartsTooltip/utils.js +2 -2
- package/ChartsXAxis/ChartsXAxis.js +123 -35
- package/ChartsYAxis/ChartsYAxis.js +38 -16
- package/LineChart/AreaElement.d.ts +10 -0
- package/LineChart/AreaElement.js +12 -2
- package/LineChart/AreaPlot.d.ts +11 -0
- package/LineChart/AreaPlot.js +24 -7
- package/LineChart/LineChart.d.ts +10 -0
- package/LineChart/LineChart.js +36 -2
- package/LineChart/LineElement.d.ts +10 -0
- package/LineChart/LineElement.js +12 -2
- package/LineChart/LineHighlightElement.d.ts +10 -0
- package/LineChart/LineHighlightElement.js +12 -2
- package/LineChart/LineHighlightPlot.d.ts +10 -0
- package/LineChart/LineHighlightPlot.js +14 -3
- package/LineChart/LinePlot.d.ts +10 -0
- package/LineChart/LinePlot.js +22 -11
- package/LineChart/MarkElement.d.ts +10 -0
- package/LineChart/MarkElement.js +12 -2
- package/LineChart/MarkPlot.d.ts +10 -0
- package/LineChart/MarkPlot.js +40 -9
- package/LineChart/formatter.js +4 -3
- package/PieChart/PieArc.js +2 -2
- package/PieChart/PieArcLabel.js +2 -2
- package/PieChart/PieChart.d.ts +10 -0
- package/PieChart/PieChart.js +37 -2
- package/PieChart/PiePlot.d.ts +10 -0
- package/PieChart/PiePlot.js +12 -2
- package/ResponsiveChartContainer/index.js +4 -4
- package/ScatterChart/Scatter.d.ts +10 -0
- package/ScatterChart/Scatter.js +12 -2
- package/ScatterChart/ScatterChart.d.ts +10 -0
- package/ScatterChart/ScatterChart.js +36 -2
- package/ScatterChart/ScatterPlot.d.ts +10 -0
- package/ScatterChart/ScatterPlot.js +12 -2
- package/SparkLineChart/SparkLineChart.d.ts +9 -0
- package/SparkLineChart/SparkLineChart.js +16 -2
- package/context/CartesianContextProvider.js +10 -2
- package/context/DrawingProvider.js +2 -2
- package/context/HighlightProvider.js +2 -2
- package/context/InteractionProvider.js +2 -2
- package/context/SeriesContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +43 -1
- package/esm/BarChart/BarElement.js +7 -4
- package/esm/BarChart/BarPlot.js +152 -67
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +16 -0
- package/esm/ChartsLegend/ChartsLegend.js +10 -6
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +27 -21
- package/esm/ChartsXAxis/ChartsXAxis.js +122 -34
- package/esm/ChartsYAxis/ChartsYAxis.js +36 -14
- package/esm/LineChart/AreaElement.js +10 -0
- package/esm/LineChart/AreaPlot.js +24 -6
- package/esm/LineChart/LineChart.js +34 -0
- package/esm/LineChart/LineElement.js +10 -0
- package/esm/LineChart/LineHighlightElement.js +10 -0
- package/esm/LineChart/LineHighlightPlot.js +12 -1
- package/esm/LineChart/LinePlot.js +23 -14
- package/esm/LineChart/MarkElement.js +10 -0
- package/esm/LineChart/MarkPlot.js +38 -7
- package/esm/LineChart/formatter.js +7 -3
- package/esm/PieChart/PieChart.js +35 -0
- package/esm/PieChart/PiePlot.js +10 -0
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +10 -0
- package/esm/ScatterChart/ScatterChart.js +34 -0
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +14 -0
- package/esm/context/CartesianContextProvider.js +8 -0
- package/esm/hooks/useMounted.js +16 -0
- package/esm/hooks/useReducedMotion.js +27 -0
- package/esm/hooks/useTicks.js +12 -6
- package/esm/internals/components/ChartsText.js +19 -13
- package/esm/internals/geometry.js +36 -0
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useChartDimensions.js +2 -2
- package/hooks/useDrawingArea.js +2 -2
- package/hooks/useInteractionItemProps.js +2 -2
- package/hooks/useMounted.d.ts +1 -0
- package/hooks/useMounted.js +25 -0
- package/hooks/useReducedMotion.d.ts +8 -0
- package/hooks/useReducedMotion.js +33 -0
- package/hooks/useScale.d.ts +2 -2
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.d.ts +18 -9
- package/hooks/useTicks.js +14 -8
- package/index.js +1 -1
- package/internals/components/ChartsText.d.ts +11 -8
- package/internals/components/ChartsText.js +21 -15
- package/internals/defaultizeColor.d.ts +2 -2
- package/internals/domUtils.d.ts +0 -1
- package/internals/geometry.d.ts +9 -0
- package/internals/geometry.js +42 -0
- package/legacy/BarChart/BarChart.js +43 -1
- package/legacy/BarChart/BarElement.js +6 -3
- package/legacy/BarChart/BarPlot.js +151 -63
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +16 -0
- package/legacy/ChartsLegend/ChartsLegend.js +14 -7
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +5 -1
- package/legacy/ChartsXAxis/ChartsXAxis.js +126 -36
- package/legacy/ChartsYAxis/ChartsYAxis.js +36 -14
- package/legacy/LineChart/AreaElement.js +10 -0
- package/legacy/LineChart/AreaPlot.js +27 -7
- package/legacy/LineChart/LineChart.js +34 -0
- package/legacy/LineChart/LineElement.js +10 -0
- package/legacy/LineChart/LineHighlightElement.js +10 -0
- package/legacy/LineChart/LineHighlightPlot.js +12 -1
- package/legacy/LineChart/LinePlot.js +25 -12
- package/legacy/LineChart/MarkElement.js +10 -0
- package/legacy/LineChart/MarkPlot.js +37 -7
- package/legacy/LineChart/formatter.js +7 -3
- package/legacy/PieChart/PieChart.js +35 -0
- package/legacy/PieChart/PiePlot.js +10 -0
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +10 -0
- package/legacy/ScatterChart/ScatterChart.js +34 -0
- package/legacy/ScatterChart/ScatterPlot.js +10 -0
- package/legacy/SparkLineChart/SparkLineChart.js +14 -0
- package/legacy/context/CartesianContextProvider.js +8 -0
- package/legacy/hooks/useMounted.js +21 -0
- package/legacy/hooks/useReducedMotion.js +27 -0
- package/legacy/hooks/useTicks.js +13 -6
- package/legacy/index.js +1 -1
- package/legacy/internals/components/ChartsText.js +17 -15
- package/legacy/internals/geometry.js +37 -0
- package/models/axis.d.ts +19 -2
- package/models/seriesType/line.d.ts +3 -3
- package/modern/BarChart/BarChart.js +43 -1
- package/modern/BarChart/BarElement.js +7 -4
- package/modern/BarChart/BarPlot.js +149 -65
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +16 -0
- package/modern/ChartsLegend/ChartsLegend.js +10 -6
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +27 -21
- package/modern/ChartsXAxis/ChartsXAxis.js +122 -34
- package/modern/ChartsYAxis/ChartsYAxis.js +36 -14
- package/modern/LineChart/AreaElement.js +10 -0
- package/modern/LineChart/AreaPlot.js +22 -5
- package/modern/LineChart/LineChart.js +34 -0
- package/modern/LineChart/LineElement.js +10 -0
- package/modern/LineChart/LineHighlightElement.js +10 -0
- package/modern/LineChart/LineHighlightPlot.js +12 -1
- package/modern/LineChart/LinePlot.js +20 -9
- package/modern/LineChart/MarkElement.js +10 -0
- package/modern/LineChart/MarkPlot.js +38 -7
- package/modern/LineChart/formatter.js +4 -3
- package/modern/PieChart/PieChart.js +35 -0
- package/modern/PieChart/PiePlot.js +10 -0
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +10 -0
- package/modern/ScatterChart/ScatterChart.js +34 -0
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +14 -0
- package/modern/context/CartesianContextProvider.js +8 -0
- package/modern/hooks/useMounted.js +16 -0
- package/modern/hooks/useReducedMotion.js +27 -0
- package/modern/hooks/useTicks.js +12 -6
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsText.js +19 -13
- package/modern/internals/geometry.js +36 -0
- package/package.json +5 -3
|
@@ -11,7 +11,9 @@ import { DrawingContext } from '../context/DrawingProvider';
|
|
|
11
11
|
import useTicks from '../hooks/useTicks';
|
|
12
12
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
13
13
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
14
|
-
import { ChartsText } from '../internals/components/ChartsText';
|
|
14
|
+
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
15
|
+
import { getMinXTranslation } from '../internals/geometry';
|
|
16
|
+
import { useMounted } from '../hooks/useMounted';
|
|
15
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
19
|
const useUtilityClasses = ownerState => {
|
|
@@ -29,12 +31,64 @@ const useUtilityClasses = ownerState => {
|
|
|
29
31
|
};
|
|
30
32
|
return composeClasses(slots, getAxisUtilityClass, classes);
|
|
31
33
|
};
|
|
34
|
+
function addLabelDimension(xTicks, {
|
|
35
|
+
tickLabelStyle: style,
|
|
36
|
+
tickLabelInterval,
|
|
37
|
+
isMounted
|
|
38
|
+
}) {
|
|
39
|
+
const withDimension = xTicks.map(tick => {
|
|
40
|
+
if (!isMounted || tick.formattedValue === undefined) {
|
|
41
|
+
return _extends({}, tick, {
|
|
42
|
+
width: 0,
|
|
43
|
+
height: 0
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const tickSizes = getWordsByLines({
|
|
47
|
+
style,
|
|
48
|
+
needsComputation: true,
|
|
49
|
+
text: tick.formattedValue
|
|
50
|
+
});
|
|
51
|
+
return _extends({}, tick, {
|
|
52
|
+
width: Math.max(...tickSizes.map(size => size.width)),
|
|
53
|
+
height: Math.max(tickSizes.length * tickSizes[0].height)
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
if (typeof tickLabelInterval === 'function') {
|
|
57
|
+
return withDimension.map((item, index) => _extends({}, item, {
|
|
58
|
+
skipLabel: !tickLabelInterval(item.value, index)
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Filter label to avoid overlap
|
|
63
|
+
let textStart = 0;
|
|
64
|
+
let textEnd = 0;
|
|
65
|
+
return withDimension.map((item, labelIndex) => {
|
|
66
|
+
const {
|
|
67
|
+
width,
|
|
68
|
+
offset,
|
|
69
|
+
labelOffset,
|
|
70
|
+
height
|
|
71
|
+
} = item;
|
|
72
|
+
const distance = getMinXTranslation(width, height, style?.angle);
|
|
73
|
+
const textPosition = offset + labelOffset;
|
|
74
|
+
const gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
|
|
75
|
+
|
|
76
|
+
textStart = textPosition - gapRatio * distance / 2;
|
|
77
|
+
if (labelIndex > 0 && textStart < textEnd) {
|
|
78
|
+
// Except for the first label, we skip all label that overlap with the last accepted.
|
|
79
|
+
// Notice that the early return prevents `textEnd` from being updated.
|
|
80
|
+
return _extends({}, item, {
|
|
81
|
+
skipLabel: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
textEnd = textPosition + gapRatio * distance / 2;
|
|
85
|
+
return item;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
32
88
|
const defaultProps = {
|
|
33
89
|
position: 'bottom',
|
|
34
90
|
disableLine: false,
|
|
35
91
|
disableTicks: false,
|
|
36
|
-
tickFontSize: 12,
|
|
37
|
-
labelFontSize: 14,
|
|
38
92
|
tickSize: 6
|
|
39
93
|
};
|
|
40
94
|
function ChartsXAxis(inProps) {
|
|
@@ -53,18 +107,23 @@ function ChartsXAxis(inProps) {
|
|
|
53
107
|
}
|
|
54
108
|
} = _React$useContext,
|
|
55
109
|
settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_props$axisId], _excluded);
|
|
110
|
+
const isMounted = useMounted();
|
|
56
111
|
const defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
57
112
|
const {
|
|
58
113
|
position,
|
|
59
114
|
disableLine,
|
|
60
115
|
disableTicks,
|
|
61
|
-
|
|
116
|
+
tickLabelStyle,
|
|
62
117
|
label,
|
|
118
|
+
labelStyle,
|
|
119
|
+
tickFontSize,
|
|
63
120
|
labelFontSize,
|
|
64
121
|
tickSize: tickSizeProp,
|
|
65
122
|
valueFormatter,
|
|
66
123
|
slots,
|
|
67
|
-
slotProps
|
|
124
|
+
slotProps,
|
|
125
|
+
tickInterval,
|
|
126
|
+
tickLabelInterval
|
|
68
127
|
} = defaultizedProps;
|
|
69
128
|
const theme = useTheme();
|
|
70
129
|
const classes = useUtilityClasses(_extends({}, defaultizedProps, {
|
|
@@ -77,16 +136,7 @@ function ChartsXAxis(inProps) {
|
|
|
77
136
|
height
|
|
78
137
|
} = React.useContext(DrawingContext);
|
|
79
138
|
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
80
|
-
const
|
|
81
|
-
scale: xScale,
|
|
82
|
-
tickNumber,
|
|
83
|
-
valueFormatter
|
|
84
|
-
});
|
|
85
|
-
const positionSigne = position === 'bottom' ? 1 : -1;
|
|
86
|
-
const labelRefPoint = {
|
|
87
|
-
x: left + width / 2,
|
|
88
|
-
y: positionSigne * (tickFontSize + tickSize + 10)
|
|
89
|
-
};
|
|
139
|
+
const positionSign = position === 'bottom' ? 1 : -1;
|
|
90
140
|
const Line = slots?.axisLine ?? 'line';
|
|
91
141
|
const Tick = slots?.axisTick ?? 'line';
|
|
92
142
|
const TickLabel = slots?.axisTickLabel ?? ChartsText;
|
|
@@ -95,27 +145,40 @@ function ChartsXAxis(inProps) {
|
|
|
95
145
|
elementType: TickLabel,
|
|
96
146
|
externalSlotProps: slotProps?.axisTickLabel,
|
|
97
147
|
additionalProps: {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
fontSize: tickFontSize
|
|
102
|
-
},
|
|
148
|
+
style: _extends({
|
|
149
|
+
textAnchor: 'middle',
|
|
150
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
|
|
151
|
+
fontSize: tickFontSize ?? 12
|
|
152
|
+
}, tickLabelStyle),
|
|
103
153
|
className: classes.tickLabel
|
|
104
154
|
},
|
|
105
155
|
className: classes.tickLabel,
|
|
106
156
|
ownerState: {}
|
|
107
157
|
});
|
|
158
|
+
const xTicks = useTicks({
|
|
159
|
+
scale: xScale,
|
|
160
|
+
tickNumber,
|
|
161
|
+
valueFormatter,
|
|
162
|
+
tickInterval
|
|
163
|
+
});
|
|
164
|
+
const xTicksWithDimension = addLabelDimension(xTicks, {
|
|
165
|
+
tickLabelStyle: axisTickLabelProps.style,
|
|
166
|
+
tickLabelInterval,
|
|
167
|
+
isMounted
|
|
168
|
+
});
|
|
169
|
+
const labelRefPoint = {
|
|
170
|
+
x: left + width / 2,
|
|
171
|
+
y: positionSign * (tickSize + 22)
|
|
172
|
+
};
|
|
108
173
|
const axisLabelProps = useSlotProps({
|
|
109
174
|
elementType: Label,
|
|
110
175
|
externalSlotProps: slotProps?.axisLabel,
|
|
111
176
|
additionalProps: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
},
|
|
118
|
-
className: classes.label
|
|
177
|
+
style: _extends({
|
|
178
|
+
fontSize: labelFontSize ?? 14,
|
|
179
|
+
textAnchor: 'middle',
|
|
180
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
|
|
181
|
+
}, labelStyle)
|
|
119
182
|
},
|
|
120
183
|
ownerState: {}
|
|
121
184
|
});
|
|
@@ -126,23 +189,23 @@ function ChartsXAxis(inProps) {
|
|
|
126
189
|
x1: xScale.range()[0],
|
|
127
190
|
x2: xScale.range()[1],
|
|
128
191
|
className: classes.line
|
|
129
|
-
}, slotProps?.axisLine)),
|
|
192
|
+
}, slotProps?.axisLine)), xTicksWithDimension.map(({
|
|
130
193
|
formattedValue,
|
|
131
194
|
offset,
|
|
132
|
-
labelOffset
|
|
195
|
+
labelOffset,
|
|
196
|
+
skipLabel
|
|
133
197
|
}, index) => {
|
|
134
198
|
const xTickLabel = labelOffset ?? 0;
|
|
135
|
-
const yTickLabel =
|
|
199
|
+
const yTickLabel = positionSign * (tickSize + 3);
|
|
136
200
|
return /*#__PURE__*/_jsxs("g", {
|
|
137
201
|
transform: `translate(${offset}, 0)`,
|
|
138
202
|
className: classes.tickContainer,
|
|
139
203
|
children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
|
|
140
|
-
y2:
|
|
204
|
+
y2: positionSign * tickSize,
|
|
141
205
|
className: classes.tick
|
|
142
|
-
}, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
206
|
+
}, slotProps?.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
143
207
|
x: xTickLabel,
|
|
144
|
-
y: yTickLabel
|
|
145
|
-
"transform-origin": `${xTickLabel}px ${yTickLabel}px`
|
|
208
|
+
y: yTickLabel
|
|
146
209
|
}, axisTickLabelProps, {
|
|
147
210
|
text: formattedValue.toString()
|
|
148
211
|
}))]
|
|
@@ -190,8 +253,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
190
253
|
/**
|
|
191
254
|
* The font size of the axis label.
|
|
192
255
|
* @default 14
|
|
256
|
+
* @deprecated Consider using `labelStyle.fontSize` instead.
|
|
193
257
|
*/
|
|
194
258
|
labelFontSize: PropTypes.number,
|
|
259
|
+
/**
|
|
260
|
+
* The style applied to the axis label.
|
|
261
|
+
*/
|
|
262
|
+
labelStyle: PropTypes.object,
|
|
195
263
|
/**
|
|
196
264
|
* Position of the axis.
|
|
197
265
|
*/
|
|
@@ -214,8 +282,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
214
282
|
/**
|
|
215
283
|
* The font size of the axis ticks text.
|
|
216
284
|
* @default 12
|
|
285
|
+
* @deprecated Consider using `tickLabelStyle.fontSize` instead.
|
|
217
286
|
*/
|
|
218
287
|
tickFontSize: PropTypes.number,
|
|
288
|
+
/**
|
|
289
|
+
* Defines which ticks are displayed. Its value can be:
|
|
290
|
+
* - 'auto' In such case the ticks are computed based on axis scale and other parameters.
|
|
291
|
+
* - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
|
|
292
|
+
* - an array containing the values where ticks should be displayed.
|
|
293
|
+
* @default 'auto'
|
|
294
|
+
*/
|
|
295
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
296
|
+
/**
|
|
297
|
+
* Defines which ticks get its label displayed. Its value can be:
|
|
298
|
+
* - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
|
|
299
|
+
* - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
|
|
300
|
+
* @default 'auto'
|
|
301
|
+
*/
|
|
302
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
303
|
+
/**
|
|
304
|
+
* The style applied to ticks text.
|
|
305
|
+
*/
|
|
306
|
+
tickLabelStyle: PropTypes.object,
|
|
219
307
|
/**
|
|
220
308
|
* Maximal step between two ticks.
|
|
221
309
|
* When using time data, the value is assumed to be in ms.
|
|
@@ -82,9 +82,9 @@ function ChartsYAxis(inProps) {
|
|
|
82
82
|
tickNumber,
|
|
83
83
|
valueFormatter
|
|
84
84
|
});
|
|
85
|
-
const
|
|
85
|
+
const positionSign = position === 'right' ? 1 : -1;
|
|
86
86
|
const labelRefPoint = {
|
|
87
|
-
x:
|
|
87
|
+
x: positionSign * (tickFontSize + tickSize + 10),
|
|
88
88
|
y: top + height / 2
|
|
89
89
|
};
|
|
90
90
|
const Line = slots?.axisLine ?? 'line';
|
|
@@ -95,10 +95,10 @@ function ChartsYAxis(inProps) {
|
|
|
95
95
|
elementType: TickLabel,
|
|
96
96
|
externalSlotProps: slotProps?.axisTickLabel,
|
|
97
97
|
additionalProps: {
|
|
98
|
-
textAnchor: position === 'right' ? 'start' : 'end',
|
|
99
|
-
dominantBaseline: 'central',
|
|
100
98
|
style: {
|
|
101
|
-
fontSize: tickFontSize
|
|
99
|
+
fontSize: tickFontSize,
|
|
100
|
+
textAnchor: position === 'right' ? 'start' : 'end',
|
|
101
|
+
dominantBaseline: 'central'
|
|
102
102
|
},
|
|
103
103
|
className: classes.tickLabel
|
|
104
104
|
},
|
|
@@ -108,14 +108,12 @@ function ChartsYAxis(inProps) {
|
|
|
108
108
|
elementType: Label,
|
|
109
109
|
externalSlotProps: slotProps?.axisLabel,
|
|
110
110
|
additionalProps: {
|
|
111
|
-
textAnchor: 'middle',
|
|
112
|
-
dominantBaseline: 'auto',
|
|
113
111
|
style: {
|
|
114
112
|
fontSize: labelFontSize,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
angle: positionSign * 90,
|
|
114
|
+
textAnchor: 'middle',
|
|
115
|
+
dominantBaseline: 'auto'
|
|
116
|
+
}
|
|
119
117
|
},
|
|
120
118
|
ownerState: {}
|
|
121
119
|
});
|
|
@@ -131,18 +129,17 @@ function ChartsYAxis(inProps) {
|
|
|
131
129
|
offset,
|
|
132
130
|
labelOffset
|
|
133
131
|
}, index) => {
|
|
134
|
-
const xTickLabel =
|
|
132
|
+
const xTickLabel = positionSign * (tickSize + 2);
|
|
135
133
|
const yTickLabel = labelOffset;
|
|
136
134
|
return /*#__PURE__*/_jsxs("g", {
|
|
137
135
|
transform: `translate(0, ${offset})`,
|
|
138
136
|
className: classes.tickContainer,
|
|
139
137
|
children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
|
|
140
|
-
x2:
|
|
138
|
+
x2: positionSign * tickSize,
|
|
141
139
|
className: classes.tick
|
|
142
140
|
}, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
143
141
|
x: xTickLabel,
|
|
144
142
|
y: yTickLabel,
|
|
145
|
-
"transform-origin": `${xTickLabel}px ${yTickLabel}px`,
|
|
146
143
|
text: formattedValue.toString()
|
|
147
144
|
}, axisTickLabelProps))]
|
|
148
145
|
}, index);
|
|
@@ -189,8 +186,13 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
189
186
|
/**
|
|
190
187
|
* The font size of the axis label.
|
|
191
188
|
* @default 14
|
|
189
|
+
* @deprecated Consider using `labelStyle.fontSize` instead.
|
|
192
190
|
*/
|
|
193
191
|
labelFontSize: PropTypes.number,
|
|
192
|
+
/**
|
|
193
|
+
* The style applied to the axis label.
|
|
194
|
+
*/
|
|
195
|
+
labelStyle: PropTypes.object,
|
|
194
196
|
/**
|
|
195
197
|
* Position of the axis.
|
|
196
198
|
*/
|
|
@@ -213,8 +215,28 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
213
215
|
/**
|
|
214
216
|
* The font size of the axis ticks text.
|
|
215
217
|
* @default 12
|
|
218
|
+
* @deprecated Consider using `tickLabelStyle.fontSize` instead.
|
|
216
219
|
*/
|
|
217
220
|
tickFontSize: PropTypes.number,
|
|
221
|
+
/**
|
|
222
|
+
* Defines which ticks are displayed. Its value can be:
|
|
223
|
+
* - 'auto' In such case the ticks are computed based on axis scale and other parameters.
|
|
224
|
+
* - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
|
|
225
|
+
* - an array containing the values where ticks should be displayed.
|
|
226
|
+
* @default 'auto'
|
|
227
|
+
*/
|
|
228
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
229
|
+
/**
|
|
230
|
+
* Defines which ticks get its label displayed. Its value can be:
|
|
231
|
+
* - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
|
|
232
|
+
* - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
|
|
233
|
+
* @default 'auto'
|
|
234
|
+
*/
|
|
235
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
236
|
+
/**
|
|
237
|
+
* The style applied to ticks text.
|
|
238
|
+
*/
|
|
239
|
+
tickLabelStyle: PropTypes.object,
|
|
218
240
|
/**
|
|
219
241
|
* Maximal step between two ticks.
|
|
220
242
|
* When using time data, the value is assumed to be in ms.
|
|
@@ -55,6 +55,16 @@ AreaElementPath.propTypes = {
|
|
|
55
55
|
}).isRequired,
|
|
56
56
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
57
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Demos:
|
|
60
|
+
*
|
|
61
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
62
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
63
|
+
*
|
|
64
|
+
* API:
|
|
65
|
+
*
|
|
66
|
+
* - [AreaElement API](https://mui.com/x/api/charts/area-element/)
|
|
67
|
+
*/
|
|
58
68
|
function AreaElement(props) {
|
|
59
69
|
const {
|
|
60
70
|
id,
|
|
@@ -10,6 +10,17 @@ import { AreaElement } from './AreaElement';
|
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* Demos:
|
|
15
|
+
*
|
|
16
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
17
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
18
|
+
* - [Stacking](https://mui.com/x/react-charts/stacking/)
|
|
19
|
+
*
|
|
20
|
+
* API:
|
|
21
|
+
*
|
|
22
|
+
* - [AreaPlot API](https://mui.com/x/api/charts/area-plot/)
|
|
23
|
+
*/
|
|
13
24
|
function AreaPlot(props) {
|
|
14
25
|
const {
|
|
15
26
|
slots,
|
|
@@ -41,20 +52,26 @@ function AreaPlot(props) {
|
|
|
41
52
|
const {
|
|
42
53
|
xAxisKey = defaultXAxisId,
|
|
43
54
|
yAxisKey = defaultYAxisId,
|
|
44
|
-
stackedData
|
|
55
|
+
stackedData,
|
|
56
|
+
data
|
|
45
57
|
} = series[seriesId];
|
|
46
58
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
47
59
|
const yScale = yAxis[yAxisKey].scale;
|
|
48
60
|
const xData = xAxis[xAxisKey].data;
|
|
49
|
-
if (
|
|
50
|
-
|
|
61
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
62
|
+
if (xData === undefined) {
|
|
63
|
+
throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
|
|
64
|
+
}
|
|
65
|
+
if (xData.length < stackedData.length) {
|
|
66
|
+
throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
|
|
67
|
+
}
|
|
51
68
|
}
|
|
52
|
-
const areaPath = d3Area().x(d => xScale(d.x)).y0(d => yScale(d.y[0])).y1(d => yScale(d.y[1]));
|
|
69
|
+
const areaPath = d3Area().x(d => xScale(d.x)).defined((_, i) => data[i] != null).y0(d => d.y && yScale(d.y[0])).y1(d => d.y && yScale(d.y[1]));
|
|
53
70
|
const curve = getCurveFactory(series[seriesId].curve);
|
|
54
71
|
const d3Data = xData?.map((x, index) => ({
|
|
55
72
|
x,
|
|
56
73
|
y: stackedData[index]
|
|
57
|
-
}));
|
|
74
|
+
})) ?? [];
|
|
58
75
|
return !!series[seriesId].area && /*#__PURE__*/_jsx(AreaElement, {
|
|
59
76
|
id: seriesId,
|
|
60
77
|
d: areaPath.curve(curve)(d3Data) || undefined,
|
|
@@ -15,6 +15,16 @@ import { ChartsClipPath } from '../ChartsClipPath';
|
|
|
15
15
|
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
/**
|
|
19
|
+
* Demos:
|
|
20
|
+
*
|
|
21
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
22
|
+
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
|
|
23
|
+
*
|
|
24
|
+
* API:
|
|
25
|
+
*
|
|
26
|
+
* - [LineChart API](https://mui.com/x/api/charts/line-chart/)
|
|
27
|
+
*/
|
|
18
28
|
const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
19
29
|
const {
|
|
20
30
|
xAxis,
|
|
@@ -118,11 +128,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
118
128
|
fill: PropTypes.string,
|
|
119
129
|
label: PropTypes.string,
|
|
120
130
|
labelFontSize: PropTypes.number,
|
|
131
|
+
labelStyle: PropTypes.object,
|
|
121
132
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
122
133
|
slotProps: PropTypes.object,
|
|
123
134
|
slots: PropTypes.object,
|
|
124
135
|
stroke: PropTypes.string,
|
|
125
136
|
tickFontSize: PropTypes.number,
|
|
137
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
138
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
139
|
+
tickLabelStyle: PropTypes.object,
|
|
126
140
|
tickMaxStep: PropTypes.number,
|
|
127
141
|
tickMinStep: PropTypes.number,
|
|
128
142
|
tickNumber: PropTypes.number,
|
|
@@ -155,11 +169,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
155
169
|
fill: PropTypes.string,
|
|
156
170
|
label: PropTypes.string,
|
|
157
171
|
labelFontSize: PropTypes.number,
|
|
172
|
+
labelStyle: PropTypes.object,
|
|
158
173
|
position: PropTypes.oneOf(['left', 'right']),
|
|
159
174
|
slotProps: PropTypes.object,
|
|
160
175
|
slots: PropTypes.object,
|
|
161
176
|
stroke: PropTypes.string,
|
|
162
177
|
tickFontSize: PropTypes.number,
|
|
178
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
179
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
180
|
+
tickLabelStyle: PropTypes.object,
|
|
163
181
|
tickMaxStep: PropTypes.number,
|
|
164
182
|
tickMinStep: PropTypes.number,
|
|
165
183
|
tickNumber: PropTypes.number,
|
|
@@ -198,11 +216,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
198
216
|
fill: PropTypes.string,
|
|
199
217
|
label: PropTypes.string,
|
|
200
218
|
labelFontSize: PropTypes.number,
|
|
219
|
+
labelStyle: PropTypes.object,
|
|
201
220
|
position: PropTypes.oneOf(['left', 'right']),
|
|
202
221
|
slotProps: PropTypes.object,
|
|
203
222
|
slots: PropTypes.object,
|
|
204
223
|
stroke: PropTypes.string,
|
|
205
224
|
tickFontSize: PropTypes.number,
|
|
225
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
226
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
227
|
+
tickLabelStyle: PropTypes.object,
|
|
206
228
|
tickMaxStep: PropTypes.number,
|
|
207
229
|
tickMinStep: PropTypes.number,
|
|
208
230
|
tickNumber: PropTypes.number,
|
|
@@ -263,11 +285,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
263
285
|
fill: PropTypes.string,
|
|
264
286
|
label: PropTypes.string,
|
|
265
287
|
labelFontSize: PropTypes.number,
|
|
288
|
+
labelStyle: PropTypes.object,
|
|
266
289
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
267
290
|
slotProps: PropTypes.object,
|
|
268
291
|
slots: PropTypes.object,
|
|
269
292
|
stroke: PropTypes.string,
|
|
270
293
|
tickFontSize: PropTypes.number,
|
|
294
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
295
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
296
|
+
tickLabelStyle: PropTypes.object,
|
|
271
297
|
tickMaxStep: PropTypes.number,
|
|
272
298
|
tickMinStep: PropTypes.number,
|
|
273
299
|
tickNumber: PropTypes.number,
|
|
@@ -292,6 +318,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
292
318
|
id: PropTypes.string,
|
|
293
319
|
label: PropTypes.string,
|
|
294
320
|
labelFontSize: PropTypes.number,
|
|
321
|
+
labelStyle: PropTypes.object,
|
|
295
322
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
296
323
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
297
324
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -300,6 +327,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
300
327
|
slots: PropTypes.object,
|
|
301
328
|
stroke: PropTypes.string,
|
|
302
329
|
tickFontSize: PropTypes.number,
|
|
330
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
331
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
332
|
+
tickLabelStyle: PropTypes.object,
|
|
303
333
|
tickMaxStep: PropTypes.number,
|
|
304
334
|
tickMinStep: PropTypes.number,
|
|
305
335
|
tickNumber: PropTypes.number,
|
|
@@ -318,6 +348,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
318
348
|
id: PropTypes.string,
|
|
319
349
|
label: PropTypes.string,
|
|
320
350
|
labelFontSize: PropTypes.number,
|
|
351
|
+
labelStyle: PropTypes.object,
|
|
321
352
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
322
353
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
323
354
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -326,6 +357,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
326
357
|
slots: PropTypes.object,
|
|
327
358
|
stroke: PropTypes.string,
|
|
328
359
|
tickFontSize: PropTypes.number,
|
|
360
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
361
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
362
|
+
tickLabelStyle: PropTypes.object,
|
|
329
363
|
tickMaxStep: PropTypes.number,
|
|
330
364
|
tickMinStep: PropTypes.number,
|
|
331
365
|
tickNumber: PropTypes.number,
|
|
@@ -57,6 +57,16 @@ LineElementPath.propTypes = {
|
|
|
57
57
|
}).isRequired,
|
|
58
58
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Demos:
|
|
62
|
+
*
|
|
63
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
64
|
+
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
|
|
65
|
+
*
|
|
66
|
+
* API:
|
|
67
|
+
*
|
|
68
|
+
* - [LineElement API](https://mui.com/x/api/charts/line-element/)
|
|
69
|
+
*/
|
|
60
70
|
function LineElement(props) {
|
|
61
71
|
const {
|
|
62
72
|
id,
|
|
@@ -33,6 +33,16 @@ const HighlightElement = styled('circle', {
|
|
|
33
33
|
transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
|
|
34
34
|
fill: ownerState.color
|
|
35
35
|
}));
|
|
36
|
+
/**
|
|
37
|
+
* Demos:
|
|
38
|
+
*
|
|
39
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
40
|
+
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
|
|
41
|
+
*
|
|
42
|
+
* API:
|
|
43
|
+
*
|
|
44
|
+
* - [LineHighlightElement API](https://mui.com/x/api/charts/line-highlight-element/)
|
|
45
|
+
*/
|
|
36
46
|
function LineHighlightElement(props) {
|
|
37
47
|
const {
|
|
38
48
|
x,
|
|
@@ -9,6 +9,16 @@ import { LineHighlightElement } from './LineHighlightElement';
|
|
|
9
9
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
10
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
/**
|
|
13
|
+
* Demos:
|
|
14
|
+
*
|
|
15
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
16
|
+
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
|
|
17
|
+
*
|
|
18
|
+
* API:
|
|
19
|
+
*
|
|
20
|
+
* - [LineHighlightPlot API](https://mui.com/x/api/charts/line-highlight-plot/)
|
|
21
|
+
*/
|
|
12
22
|
function LineHighlightPlot(props) {
|
|
13
23
|
const {
|
|
14
24
|
slots,
|
|
@@ -49,9 +59,10 @@ function LineHighlightPlot(props) {
|
|
|
49
59
|
xAxisKey = defaultXAxisId,
|
|
50
60
|
yAxisKey = defaultYAxisId,
|
|
51
61
|
stackedData,
|
|
62
|
+
data,
|
|
52
63
|
disableHighlight
|
|
53
64
|
} = series[seriesId];
|
|
54
|
-
if (disableHighlight) {
|
|
65
|
+
if (disableHighlight || data[highlightedIndex] == null) {
|
|
55
66
|
return null;
|
|
56
67
|
}
|
|
57
68
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
@@ -10,6 +10,16 @@ import { LineElement } from './LineElement';
|
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* Demos:
|
|
15
|
+
*
|
|
16
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
17
|
+
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
|
|
18
|
+
*
|
|
19
|
+
* API:
|
|
20
|
+
*
|
|
21
|
+
* - [LinePlot API](https://mui.com/x/api/charts/line-plot/)
|
|
22
|
+
*/
|
|
13
23
|
function LinePlot(props) {
|
|
14
24
|
const {
|
|
15
25
|
slots,
|
|
@@ -41,25 +51,26 @@ function LinePlot(props) {
|
|
|
41
51
|
const {
|
|
42
52
|
xAxisKey = defaultXAxisId,
|
|
43
53
|
yAxisKey = defaultYAxisId,
|
|
44
|
-
stackedData
|
|
54
|
+
stackedData,
|
|
55
|
+
data
|
|
45
56
|
} = series[seriesId];
|
|
46
57
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
47
58
|
const yScale = yAxis[yAxisKey].scale;
|
|
48
59
|
const xData = xAxis[xAxisKey].data;
|
|
49
|
-
if (xData === undefined) {
|
|
50
|
-
throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
|
|
51
|
-
}
|
|
52
|
-
const linePath = d3Line().x(d => xScale(d.x)).y(d => yScale(d.y[1]));
|
|
53
60
|
if (process.env.NODE_ENV !== 'production') {
|
|
54
|
-
if (xData
|
|
55
|
-
throw new Error(`
|
|
61
|
+
if (xData === undefined) {
|
|
62
|
+
throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
|
|
63
|
+
}
|
|
64
|
+
if (xData.length < stackedData.length) {
|
|
65
|
+
throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
|
|
56
66
|
}
|
|
57
67
|
}
|
|
68
|
+
const linePath = d3Line().x(d => xScale(d.x)).defined((_, i) => data[i] != null).y(d => yScale(d.y[1]));
|
|
58
69
|
const curve = getCurveFactory(series[seriesId].curve);
|
|
59
70
|
const d3Data = xData?.map((x, index) => ({
|
|
60
71
|
x,
|
|
61
|
-
y: stackedData[index]
|
|
62
|
-
}));
|
|
72
|
+
y: stackedData[index]
|
|
73
|
+
})) ?? [];
|
|
63
74
|
return /*#__PURE__*/_jsx(LineElement, {
|
|
64
75
|
id: seriesId,
|
|
65
76
|
d: linePath.curve(curve)(d3Data) || undefined,
|
|
@@ -59,6 +59,16 @@ MarkElementPath.propTypes = {
|
|
|
59
59
|
}).isRequired,
|
|
60
60
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Demos:
|
|
64
|
+
*
|
|
65
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
66
|
+
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
|
|
67
|
+
*
|
|
68
|
+
* API:
|
|
69
|
+
*
|
|
70
|
+
* - [MarkElement API](https://mui.com/x/api/charts/mark-element/)
|
|
71
|
+
*/
|
|
62
72
|
function MarkElement(props) {
|
|
63
73
|
const {
|
|
64
74
|
x,
|