@mui/x-charts 7.0.0-beta.6 → 7.0.0
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/CHANGELOG.md +311 -12
- package/ChartsLegend/ChartsLegend.d.ts +3 -0
- package/ChartsLegend/ChartsLegend.js +3 -0
- package/ChartsLegend/DefaultChartsLegend.js +3 -0
- package/ChartsTooltip/ChartsTooltip.d.ts +12 -0
- package/README.md +1 -1
- package/context/CartesianContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +6 -9
- package/esm/BarChart/BarElement.js +2 -3
- package/esm/BarChart/BarPlot.js +5 -8
- package/esm/BarChart/extremums.js +2 -3
- package/esm/BarChart/formatter.js +2 -6
- package/esm/ChartsAxis/ChartsAxis.js +3 -4
- package/esm/ChartsLegend/ChartsLegend.js +5 -3
- package/esm/ChartsLegend/DefaultChartsLegend.js +3 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -4
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/esm/ChartsText/ChartsText.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsTooltip.js +6 -7
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -4
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -2
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +13 -14
- package/esm/ChartsYAxis/ChartsYAxis.js +9 -10
- package/esm/Gauge/GaugeContainer.js +18 -21
- package/esm/Gauge/GaugeProvider.js +3 -3
- package/esm/LineChart/AreaElement.js +2 -3
- package/esm/LineChart/AreaPlot.js +2 -3
- package/esm/LineChart/LineChart.js +3 -6
- package/esm/LineChart/LineElement.js +2 -3
- package/esm/LineChart/LineHighlightPlot.js +3 -4
- package/esm/LineChart/LinePlot.js +2 -3
- package/esm/LineChart/MarkElement.js +1 -2
- package/esm/LineChart/MarkPlot.js +3 -4
- package/esm/LineChart/extremums.js +2 -3
- package/esm/LineChart/formatter.js +2 -6
- package/esm/PieChart/PieArcLabelPlot.js +3 -5
- package/esm/PieChart/PieArcPlot.js +2 -3
- package/esm/PieChart/PieChart.js +2 -2
- package/esm/PieChart/PiePlot.js +9 -9
- package/esm/PieChart/dataTransform/useTransformData.js +5 -6
- package/esm/PieChart/formatter.js +6 -13
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +15 -18
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
- package/esm/ScatterChart/ScatterPlot.js +5 -6
- package/esm/SparkLineChart/SparkLineChart.js +1 -1
- package/esm/context/CartesianContextProvider.js +18 -24
- package/esm/context/DrawingProvider.js +1 -1
- package/esm/context/SeriesContextProvider.js +2 -4
- package/esm/hooks/useAxisEvents.js +10 -2
- package/esm/hooks/useInteractionItemProps.js +2 -2
- package/esm/hooks/useScale.js +2 -2
- package/esm/hooks/useTicks.js +23 -32
- package/esm/internals/defaultizeValueFormatter.js +1 -2
- package/esm/internals/stackSeries.js +2 -3
- package/hooks/useAxisEvents.js +9 -1
- package/index.js +1 -1
- package/models/axis.d.ts +16 -0
- package/modern/ChartsLegend/ChartsLegend.js +3 -0
- package/modern/ChartsLegend/DefaultChartsLegend.js +3 -0
- package/modern/context/CartesianContextProvider.js +2 -2
- package/modern/hooks/useAxisEvents.js +9 -1
- package/modern/index.js +1 -1
- package/package.json +5 -5
package/esm/hooks/useTicks.js
CHANGED
|
@@ -10,7 +10,7 @@ export function getTickNumber(params) {
|
|
|
10
10
|
} = params;
|
|
11
11
|
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
12
12
|
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
13
|
-
const defaultizedTickNumber = tickNumber
|
|
13
|
+
const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
14
14
|
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
15
15
|
}
|
|
16
16
|
const offsetRatio = {
|
|
@@ -34,17 +34,14 @@ export function useTicks(options) {
|
|
|
34
34
|
const domain = scale.domain();
|
|
35
35
|
if (scale.bandwidth() > 0) {
|
|
36
36
|
// scale type = 'band'
|
|
37
|
-
return [...domain.map(value => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
labelOffset: tickLabelPlacement === 'tick' ? 0 : scale.step() * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement])
|
|
46
|
-
};
|
|
47
|
-
}), ...(tickPlacement === 'extremities' ? [{
|
|
37
|
+
return [...domain.map(value => ({
|
|
38
|
+
value,
|
|
39
|
+
formattedValue: valueFormatter?.(value, {
|
|
40
|
+
location: 'tick'
|
|
41
|
+
}) ?? `${value}`,
|
|
42
|
+
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step(),
|
|
43
|
+
labelOffset: tickLabelPlacement === 'tick' ? 0 : scale.step() * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement])
|
|
44
|
+
})), ...(tickPlacement === 'extremities' ? [{
|
|
48
45
|
formattedValue: undefined,
|
|
49
46
|
offset: scale.range()[1],
|
|
50
47
|
labelOffset: 0
|
|
@@ -53,29 +50,23 @@ export function useTicks(options) {
|
|
|
53
50
|
|
|
54
51
|
// scale type = 'point'
|
|
55
52
|
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
56
|
-
return filteredDomain.map(value => {
|
|
57
|
-
var _valueFormatter2;
|
|
58
|
-
return {
|
|
59
|
-
value,
|
|
60
|
-
formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value, {
|
|
61
|
-
location: 'tick'
|
|
62
|
-
})) != null ? _valueFormatter2 : `${value}`,
|
|
63
|
-
offset: scale(value),
|
|
64
|
-
labelOffset: 0
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
69
|
-
return ticks.map(value => {
|
|
70
|
-
var _valueFormatter3;
|
|
71
|
-
return {
|
|
53
|
+
return filteredDomain.map(value => ({
|
|
72
54
|
value,
|
|
73
|
-
formattedValue:
|
|
55
|
+
formattedValue: valueFormatter?.(value, {
|
|
74
56
|
location: 'tick'
|
|
75
|
-
})
|
|
57
|
+
}) ?? `${value}`,
|
|
76
58
|
offset: scale(value),
|
|
77
59
|
labelOffset: 0
|
|
78
|
-
};
|
|
79
|
-
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
63
|
+
return ticks.map(value => ({
|
|
64
|
+
value,
|
|
65
|
+
formattedValue: valueFormatter?.(value, {
|
|
66
|
+
location: 'tick'
|
|
67
|
+
}) ?? scale.tickFormat(tickNumber)(value),
|
|
68
|
+
offset: scale(value),
|
|
69
|
+
labelOffset: 0
|
|
70
|
+
}));
|
|
80
71
|
}, [scale, tickInterval, tickNumber, valueFormatter, tickPlacement, tickLabelPlacement]);
|
|
81
72
|
}
|
|
@@ -2,9 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
function defaultizeValueFormatter(series, defaultValueFormatter) {
|
|
3
3
|
const defaultizedSeries = {};
|
|
4
4
|
Object.keys(series).forEach(seriesId => {
|
|
5
|
-
var _series$seriesId$valu;
|
|
6
5
|
defaultizedSeries[seriesId] = _extends({}, series[seriesId], {
|
|
7
|
-
valueFormatter:
|
|
6
|
+
valueFormatter: series[seriesId].valueFormatter ?? defaultValueFormatter
|
|
8
7
|
});
|
|
9
8
|
});
|
|
10
9
|
return defaultizedSeries;
|
|
@@ -74,12 +74,11 @@ export const getStackingGroups = params => {
|
|
|
74
74
|
stackingOffset: StackOffset.none
|
|
75
75
|
});
|
|
76
76
|
} else if (stackIndex[stack] === undefined) {
|
|
77
|
-
var _ref, _ref2;
|
|
78
77
|
stackIndex[stack] = stackingGroups.length;
|
|
79
78
|
stackingGroups.push({
|
|
80
79
|
ids: [id],
|
|
81
|
-
stackingOrder: StackOrder[
|
|
82
|
-
stackingOffset: StackOffset[
|
|
80
|
+
stackingOrder: StackOrder[stackOrder ?? defaultStrategy?.stackOrder ?? 'none'],
|
|
81
|
+
stackingOffset: StackOffset[stackOffset ?? defaultStrategy?.stackOffset ?? 'diverging']
|
|
83
82
|
});
|
|
84
83
|
} else {
|
|
85
84
|
stackingGroups[stackIndex[stack]].ids.push(id);
|
package/hooks/useAxisEvents.js
CHANGED
|
@@ -51,7 +51,8 @@ const useAxisEvents = disableAxisListener => {
|
|
|
51
51
|
}
|
|
52
52
|
const {
|
|
53
53
|
scale,
|
|
54
|
-
data: axisData
|
|
54
|
+
data: axisData,
|
|
55
|
+
reverse
|
|
55
56
|
} = axisConfig;
|
|
56
57
|
if (!(0, _isBandScale.isBandScale)(scale)) {
|
|
57
58
|
const value = scale.invert(mouseValue);
|
|
@@ -84,6 +85,13 @@ const useAxisEvents = disableAxisListener => {
|
|
|
84
85
|
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
85
86
|
return null;
|
|
86
87
|
}
|
|
88
|
+
if (reverse) {
|
|
89
|
+
const reverseIndex = axisData.length - 1 - dataIndex;
|
|
90
|
+
return {
|
|
91
|
+
index: reverseIndex,
|
|
92
|
+
value: axisData[reverseIndex]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
87
95
|
return {
|
|
88
96
|
index: dataIndex,
|
|
89
97
|
value: axisData[dataIndex]
|
package/index.js
CHANGED
package/models/axis.d.ts
CHANGED
|
@@ -9,9 +9,25 @@ export type D3Scale<Domain extends {
|
|
|
9
9
|
} = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
|
|
10
10
|
export type D3ContinuouseScale<Range = number, Output = number> = ScaleLogarithmic<Range, Output> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
|
|
11
11
|
export interface ChartsAxisSlots {
|
|
12
|
+
/**
|
|
13
|
+
* Custom component for the axis main line.
|
|
14
|
+
* @default 'line'
|
|
15
|
+
*/
|
|
12
16
|
axisLine?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
17
|
+
/**
|
|
18
|
+
* Custom component for the axis tick.
|
|
19
|
+
* @default 'line'
|
|
20
|
+
*/
|
|
13
21
|
axisTick?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
22
|
+
/**
|
|
23
|
+
* Custom component for tick label.
|
|
24
|
+
* @default ChartsText
|
|
25
|
+
*/
|
|
14
26
|
axisTickLabel?: React.JSXElementConstructor<ChartsTextProps>;
|
|
27
|
+
/**
|
|
28
|
+
* Custom component for axis label.
|
|
29
|
+
* @default ChartsText
|
|
30
|
+
*/
|
|
15
31
|
axisLabel?: React.JSXElementConstructor<ChartsTextProps>;
|
|
16
32
|
}
|
|
17
33
|
export interface ChartsAxisSlotProps {
|
|
@@ -85,6 +85,9 @@ process.env.NODE_ENV !== "production" ? ChartsLegend.propTypes = {
|
|
|
85
85
|
* @default false
|
|
86
86
|
*/
|
|
87
87
|
hidden: PropTypes.bool,
|
|
88
|
+
/**
|
|
89
|
+
* The position of the legend.
|
|
90
|
+
*/
|
|
88
91
|
position: PropTypes.shape({
|
|
89
92
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
90
93
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
@@ -265,6 +265,9 @@ process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
|
265
265
|
right: PropTypes.number,
|
|
266
266
|
top: PropTypes.number
|
|
267
267
|
})]),
|
|
268
|
+
/**
|
|
269
|
+
* The position of the legend.
|
|
270
|
+
*/
|
|
268
271
|
position: PropTypes.shape({
|
|
269
272
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
270
273
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
@@ -90,7 +90,7 @@ function CartesianContextProvider(props) {
|
|
|
90
90
|
return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis), [null, null]);
|
|
91
91
|
};
|
|
92
92
|
const allXAxis = [...(xAxis?.map((axis, index) => _extends({
|
|
93
|
-
id: `
|
|
93
|
+
id: `defaultized-x-axis-${index}`
|
|
94
94
|
}, axis)) ?? []),
|
|
95
95
|
// Allows to specify an axis with id=DEFAULT_X_AXIS_KEY
|
|
96
96
|
...(xAxis === undefined || xAxis.findIndex(({
|
|
@@ -141,7 +141,7 @@ function CartesianContextProvider(props) {
|
|
|
141
141
|
});
|
|
142
142
|
});
|
|
143
143
|
const allYAxis = [...(yAxis?.map((axis, index) => _extends({
|
|
144
|
-
id: `
|
|
144
|
+
id: `defaultized-y-axis-${index}`
|
|
145
145
|
}, axis)) ?? []), ...(yAxis === undefined || yAxis.findIndex(({
|
|
146
146
|
id
|
|
147
147
|
}) => id === DEFAULT_Y_AXIS_KEY) === -1 ? [{
|
|
@@ -43,7 +43,8 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
43
43
|
}
|
|
44
44
|
const {
|
|
45
45
|
scale,
|
|
46
|
-
data: axisData
|
|
46
|
+
data: axisData,
|
|
47
|
+
reverse
|
|
47
48
|
} = axisConfig;
|
|
48
49
|
if (!isBandScale(scale)) {
|
|
49
50
|
const value = scale.invert(mouseValue);
|
|
@@ -76,6 +77,13 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
76
77
|
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
77
78
|
return null;
|
|
78
79
|
}
|
|
80
|
+
if (reverse) {
|
|
81
|
+
const reverseIndex = axisData.length - 1 - dataIndex;
|
|
82
|
+
return {
|
|
83
|
+
index: reverseIndex,
|
|
84
|
+
value: axisData[reverseIndex]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
79
87
|
return {
|
|
80
88
|
index: dataIndex,
|
|
81
89
|
value: axisData[dataIndex]
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "The community edition of the charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.24.0",
|
|
32
|
-
"@mui/base": "^5.0.0-beta.
|
|
33
|
-
"@mui/system": "^5.15.
|
|
34
|
-
"@mui/utils": "^5.15.
|
|
32
|
+
"@mui/base": "^5.0.0-beta.40",
|
|
33
|
+
"@mui/system": "^5.15.14",
|
|
34
|
+
"@mui/utils": "^5.15.14",
|
|
35
35
|
"@react-spring/rafz": "^9.7.3",
|
|
36
36
|
"@react-spring/web": "^9.7.3",
|
|
37
37
|
"clsx": "^2.1.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@emotion/react": "^11.9.0",
|
|
47
47
|
"@emotion/styled": "^11.8.1",
|
|
48
|
-
"@mui/material": "^5.15.
|
|
48
|
+
"@mui/material": "^5.15.14",
|
|
49
49
|
"react": "^17.0.0 || ^18.0.0",
|
|
50
50
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
51
51
|
},
|