@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.d.ts +2 -1
- package/BarChart/BarChart.js +33 -12
- package/BarChart/BarElement.d.ts +20 -13
- package/BarChart/BarElement.js +7 -3
- package/BarChart/BarPlot.d.ts +11 -6
- package/BarChart/BarPlot.js +28 -15
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +406 -1
- package/ChartContainer/ChartContainer.js +6 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +5 -54
- package/ChartsLegend/ChartsLegend.js +2 -307
- package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
- package/ChartsLegend/DefaultChartsLegend.js +294 -0
- package/ChartsLegend/index.d.ts +1 -0
- package/ChartsLegend/index.js +11 -0
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
- package/ChartsOnAxisClickHandler/index.d.ts +1 -0
- package/ChartsOnAxisClickHandler/index.js +16 -0
- package/ChartsOnAxisClickHandler/package.json +6 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +2 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/ChartsTooltip/utils.d.ts +4 -1
- package/ChartsTooltip/utils.js +15 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/ChartsXAxis/ChartsXAxis.js +13 -9
- package/ChartsYAxis/ChartsYAxis.js +1 -1
- package/LineChart/AnimatedArea.d.ts +1361 -0
- package/LineChart/AnimatedArea.js +111 -0
- package/LineChart/AnimatedLine.d.ts +1361 -0
- package/LineChart/AnimatedLine.js +113 -0
- package/LineChart/AreaElement.d.ts +19 -18
- package/LineChart/AreaElement.js +17 -34
- package/LineChart/AreaPlot.d.ts +12 -7
- package/LineChart/AreaPlot.js +91 -58
- package/LineChart/LineChart.d.ts +13 -4
- package/LineChart/LineChart.js +45 -14
- package/LineChart/LineElement.d.ts +19 -18
- package/LineChart/LineElement.js +16 -36
- package/LineChart/LineHighlightElement.d.ts +3 -2
- package/LineChart/LineHighlightElement.js +5 -3
- package/LineChart/LinePlot.d.ts +12 -7
- package/LineChart/LinePlot.js +89 -56
- package/LineChart/MarkElement.d.ts +8 -4
- package/LineChart/MarkElement.js +27 -13
- package/LineChart/MarkPlot.d.ts +8 -1
- package/LineChart/MarkPlot.js +80 -51
- package/LineChart/formatter.js +1 -1
- package/LineChart/index.d.ts +2 -0
- package/LineChart/index.js +22 -0
- package/PieChart/PieArc.d.ts +3 -2
- package/PieChart/PieArc.js +1 -0
- package/PieChart/PieArcLabel.d.ts +3 -2
- package/PieChart/PieArcLabel.js +1 -0
- package/PieChart/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +2 -2
- package/PieChart/PieArcPlot.d.ts +2 -2
- package/PieChart/PieArcPlot.js +7 -7
- package/PieChart/PieChart.d.ts +1 -1
- package/PieChart/PieChart.js +14 -12
- package/PieChart/PiePlot.d.ts +1 -1
- package/PieChart/PiePlot.js +4 -4
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/ScatterChart/Scatter.d.ts +7 -1
- package/ScatterChart/Scatter.js +17 -3
- package/ScatterChart/ScatterChart.d.ts +8 -2
- package/ScatterChart/ScatterChart.js +21 -10
- package/ScatterChart/ScatterPlot.d.ts +1 -1
- package/ScatterChart/ScatterPlot.js +10 -2
- package/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.js +7 -4
- package/context/CartesianContextProvider.js +8 -6
- package/context/DrawingProvider.d.ts +6 -1
- package/context/DrawingProvider.js +9 -2
- package/context/InteractionProvider.d.ts +3 -3
- package/esm/BarChart/BarChart.js +33 -12
- package/esm/BarChart/BarElement.js +7 -3
- package/esm/BarChart/BarPlot.js +27 -15
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/ChartContainer.js +6 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -307
- package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/esm/ChartsLegend/index.js +1 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
- package/esm/ChartsOnAxisClickHandler/index.js +1 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/esm/ChartsTooltip/utils.js +12 -0
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/esm/ChartsXAxis/ChartsXAxis.js +13 -9
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
- package/esm/LineChart/AnimatedArea.js +103 -0
- package/esm/LineChart/AnimatedLine.js +105 -0
- package/esm/LineChart/AreaElement.js +16 -33
- package/esm/LineChart/AreaPlot.js +92 -59
- package/esm/LineChart/LineChart.js +45 -14
- package/esm/LineChart/LineElement.js +16 -35
- package/esm/LineChart/LineHighlightElement.js +5 -3
- package/esm/LineChart/LinePlot.js +90 -57
- package/esm/LineChart/MarkElement.js +27 -13
- package/esm/LineChart/MarkPlot.js +80 -51
- package/esm/LineChart/formatter.js +1 -1
- package/esm/LineChart/index.js +2 -0
- package/esm/PieChart/PieArc.js +1 -0
- package/esm/PieChart/PieArcLabel.js +1 -0
- package/esm/PieChart/PieArcLabelPlot.js +2 -2
- package/esm/PieChart/PieArcPlot.js +7 -7
- package/esm/PieChart/PieChart.js +14 -12
- package/esm/PieChart/PiePlot.js +4 -4
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/esm/ScatterChart/Scatter.js +17 -3
- package/esm/ScatterChart/ScatterChart.js +21 -10
- package/esm/ScatterChart/ScatterPlot.js +10 -2
- package/esm/SparkLineChart/SparkLineChart.js +7 -4
- package/esm/context/CartesianContextProvider.js +8 -6
- package/esm/context/DrawingProvider.js +9 -2
- package/esm/hooks/useDrawingArea.js +7 -3
- package/esm/index.js +1 -0
- package/esm/internals/geometry.js +1 -1
- package/esm/internals/useAnimatedPath.js +29 -0
- package/esm/internals/utils.js +7 -0
- package/hooks/useDrawingArea.d.ts +2 -0
- package/hooks/useDrawingArea.js +7 -3
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +16 -16
- package/internals/defaultizeValueFormatter.d.ts +4 -7
- package/internals/geometry.js +1 -1
- package/internals/stackSeries.d.ts +4 -7
- package/internals/useAnimatedPath.d.ts +1 -0
- package/internals/useAnimatedPath.js +38 -0
- package/internals/utils.d.ts +4 -0
- package/internals/utils.js +8 -0
- package/legacy/BarChart/BarChart.js +33 -12
- package/legacy/BarChart/BarElement.js +6 -2
- package/legacy/BarChart/BarPlot.js +28 -14
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/ChartContainer.js +6 -4
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +2 -323
- package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
- package/legacy/ChartsLegend/index.js +1 -0
- package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/legacy/ChartsTooltip/utils.js +12 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
- package/legacy/ChartsXAxis/ChartsXAxis.js +12 -8
- package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
- package/legacy/LineChart/AnimatedArea.js +102 -0
- package/legacy/LineChart/AnimatedLine.js +104 -0
- package/legacy/LineChart/AreaElement.js +15 -35
- package/legacy/LineChart/AreaPlot.js +102 -66
- package/legacy/LineChart/LineChart.js +45 -14
- package/legacy/LineChart/LineElement.js +15 -37
- package/legacy/LineChart/LineHighlightElement.js +5 -3
- package/legacy/LineChart/LinePlot.js +97 -63
- package/legacy/LineChart/MarkElement.js +30 -12
- package/legacy/LineChart/MarkPlot.js +83 -53
- package/legacy/LineChart/formatter.js +1 -1
- package/legacy/LineChart/index.js +2 -0
- package/legacy/PieChart/PieArc.js +1 -0
- package/legacy/PieChart/PieArcLabel.js +1 -0
- package/legacy/PieChart/PieArcLabelPlot.js +2 -2
- package/legacy/PieChart/PieArcPlot.js +7 -7
- package/legacy/PieChart/PieChart.js +14 -12
- package/legacy/PieChart/PiePlot.js +4 -4
- package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/legacy/ScatterChart/Scatter.js +19 -3
- package/legacy/ScatterChart/ScatterChart.js +21 -10
- package/legacy/ScatterChart/ScatterPlot.js +10 -2
- package/legacy/SparkLineChart/SparkLineChart.js +8 -5
- package/legacy/context/CartesianContextProvider.js +8 -6
- package/legacy/context/DrawingProvider.js +11 -2
- package/legacy/hooks/useDrawingArea.js +7 -3
- package/legacy/index.js +2 -1
- package/legacy/internals/geometry.js +1 -1
- package/legacy/internals/useAnimatedPath.js +32 -0
- package/legacy/internals/utils.js +7 -0
- package/models/axis.d.ts +7 -2
- package/models/seriesType/common.d.ts +2 -1
- package/models/seriesType/config.d.ts +7 -12
- package/models/seriesType/line.d.ts +2 -2
- package/models/seriesType/pie.d.ts +7 -3
- package/models/seriesType/scatter.d.ts +5 -2
- package/modern/BarChart/BarChart.js +33 -12
- package/modern/BarChart/BarElement.js +7 -3
- package/modern/BarChart/BarPlot.js +27 -15
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/ChartContainer.js +6 -4
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +2 -307
- package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/modern/ChartsLegend/index.js +1 -0
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/modern/ChartsOnAxisClickHandler/index.js +1 -0
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/modern/ChartsTooltip/utils.js +12 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/modern/ChartsXAxis/ChartsXAxis.js +13 -9
- package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
- package/modern/LineChart/AnimatedArea.js +103 -0
- package/modern/LineChart/AnimatedLine.js +105 -0
- package/modern/LineChart/AreaElement.js +16 -33
- package/modern/LineChart/AreaPlot.js +91 -58
- package/modern/LineChart/LineChart.js +45 -14
- package/modern/LineChart/LineElement.js +16 -35
- package/modern/LineChart/LineHighlightElement.js +5 -3
- package/modern/LineChart/LinePlot.js +89 -56
- package/modern/LineChart/MarkElement.js +27 -13
- package/modern/LineChart/MarkPlot.js +80 -51
- package/modern/LineChart/formatter.js +1 -1
- package/modern/LineChart/index.js +2 -0
- package/modern/PieChart/PieArc.js +1 -0
- package/modern/PieChart/PieArcLabel.js +1 -0
- package/modern/PieChart/PieArcLabelPlot.js +2 -2
- package/modern/PieChart/PieArcPlot.js +7 -7
- package/modern/PieChart/PieChart.js +14 -12
- package/modern/PieChart/PiePlot.js +4 -4
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/modern/ScatterChart/Scatter.js +17 -3
- package/modern/ScatterChart/ScatterChart.js +21 -10
- package/modern/ScatterChart/ScatterPlot.js +10 -2
- package/modern/SparkLineChart/SparkLineChart.js +7 -4
- package/modern/context/CartesianContextProvider.js +8 -6
- package/modern/context/DrawingProvider.js +9 -2
- package/modern/hooks/useDrawingArea.js +7 -3
- package/modern/index.js +2 -1
- package/modern/internals/geometry.js +1 -1
- package/modern/internals/useAnimatedPath.js +29 -0
- package/modern/internals/utils.js +7 -0
- package/package.json +6 -5
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { SVGContext } from '../context/DrawingProvider';
|
|
4
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
5
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
6
|
+
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
function ChartsOnAxisClickHandler(props) {
|
|
9
|
+
var onAxisClick = props.onAxisClick;
|
|
10
|
+
var svgRef = React.useContext(SVGContext);
|
|
11
|
+
var series = React.useContext(SeriesContext);
|
|
12
|
+
var _React$useContext = React.useContext(InteractionContext),
|
|
13
|
+
axis = _React$useContext.axis;
|
|
14
|
+
var _React$useContext2 = React.useContext(CartesianContext),
|
|
15
|
+
xAxisIds = _React$useContext2.xAxisIds,
|
|
16
|
+
xAxis = _React$useContext2.xAxis,
|
|
17
|
+
yAxisIds = _React$useContext2.yAxisIds,
|
|
18
|
+
yAxis = _React$useContext2.yAxis;
|
|
19
|
+
React.useEffect(function () {
|
|
20
|
+
var element = svgRef.current;
|
|
21
|
+
if (element === null || !onAxisClick) {
|
|
22
|
+
return function () {};
|
|
23
|
+
}
|
|
24
|
+
var handleMouseClick = function handleMouseClick(event) {
|
|
25
|
+
var _USED_AXIS_ID$data;
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
var isXaxis = (axis.x && axis.x.index) !== undefined;
|
|
28
|
+
var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
29
|
+
var dataIndex = isXaxis ? axis.x && axis.x.index : axis.y && axis.y.index;
|
|
30
|
+
if (dataIndex == null) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var seriesValues = {};
|
|
34
|
+
Object.keys(series).filter(function (seriesType) {
|
|
35
|
+
return ['bar', 'line'].includes(seriesType);
|
|
36
|
+
}).forEach(function (seriesType) {
|
|
37
|
+
var _series$seriesType;
|
|
38
|
+
(_series$seriesType = series[seriesType]) == null || _series$seriesType.seriesOrder.forEach(function (seriesId) {
|
|
39
|
+
var seriesItem = series[seriesType].series[seriesId];
|
|
40
|
+
var axisKey = isXaxis ? seriesItem.xAxisKey : seriesItem.yAxisKey;
|
|
41
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
42
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
var axisValue = (_USED_AXIS_ID$data = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data) == null ? void 0 : _USED_AXIS_ID$data[dataIndex];
|
|
47
|
+
onAxisClick(event, {
|
|
48
|
+
dataIndex: dataIndex,
|
|
49
|
+
axisValue: axisValue,
|
|
50
|
+
seriesValues: seriesValues
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
element.addEventListener('click', handleMouseClick);
|
|
54
|
+
return function () {
|
|
55
|
+
element.removeEventListener('click', handleMouseClick);
|
|
56
|
+
};
|
|
57
|
+
}, [axis.x, axis.y, onAxisClick, series, svgRef, xAxis, xAxisIds, yAxis, yAxisIds]);
|
|
58
|
+
|
|
59
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
60
|
+
return /*#__PURE__*/_jsx(React.Fragment, {});
|
|
61
|
+
}
|
|
62
|
+
process.env.NODE_ENV !== "production" ? ChartsOnAxisClickHandler.propTypes = {
|
|
63
|
+
// ----------------------------- Warning --------------------------------
|
|
64
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
65
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
66
|
+
// ----------------------------------------------------------------------
|
|
67
|
+
/**
|
|
68
|
+
* The function called for onClick events.
|
|
69
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
70
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
71
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
72
|
+
*/
|
|
73
|
+
onAxisClick: PropTypes.func
|
|
74
|
+
} : void 0;
|
|
75
|
+
export { ChartsOnAxisClickHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChartsOnAxisClickHandler';
|
|
@@ -8,7 +8,7 @@ function ChartsReferenceLine(props) {
|
|
|
8
8
|
var x = props.x,
|
|
9
9
|
y = props.y;
|
|
10
10
|
if (x !== undefined && y !== undefined) {
|
|
11
|
-
throw new Error('MUI X Charts: The ChartsReferenceLine
|
|
11
|
+
throw new Error('MUI X Charts: The ChartsReferenceLine cannot have both `x` and `y` props set.');
|
|
12
12
|
}
|
|
13
13
|
if (x === undefined && y === undefined) {
|
|
14
14
|
throw new Error('MUI X Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
@@ -27,7 +27,7 @@ process.env.NODE_ENV !== "production" ? ChartsReferenceLine.propTypes = {
|
|
|
27
27
|
* The id of the axis used for the reference value.
|
|
28
28
|
* @default The `id` of the first defined axis.
|
|
29
29
|
*/
|
|
30
|
-
axisId: PropTypes.string,
|
|
30
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
31
31
|
/**
|
|
32
32
|
* Override or extend the styles applied to the component.
|
|
33
33
|
*/
|
|
@@ -70,7 +70,7 @@ function ChartsXReferenceLine(props) {
|
|
|
70
70
|
if (process.env.NODE_ENV !== 'production') {
|
|
71
71
|
if (!warnedOnce) {
|
|
72
72
|
warnedOnce = true;
|
|
73
|
-
console.error("MUI X: the value ".concat(x, " does not exist in the data of x axis with id ").concat(axisId, "."));
|
|
73
|
+
console.error("MUI X Charts: the value ".concat(x, " does not exist in the data of x axis with id ").concat(axisId, "."));
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return null;
|
|
@@ -70,7 +70,7 @@ function ChartsYReferenceLine(props) {
|
|
|
70
70
|
if (process.env.NODE_ENV !== 'production') {
|
|
71
71
|
if (!warnedOnce) {
|
|
72
72
|
warnedOnce = true;
|
|
73
|
-
console.error("MUI X: the value ".concat(y, " does not exist in the data of y axis with id ").concat(axisId, "."));
|
|
73
|
+
console.error("MUI X Charts: the value ".concat(y, " does not exist in the data of y axis with id ").concat(axisId, "."));
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return null;
|
|
@@ -5,6 +5,7 @@ import { useSlotProps } from '@mui/base/utils';
|
|
|
5
5
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
6
6
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
7
7
|
import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
|
|
8
|
+
import { isCartesianSeriesType } from './utils';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
function ChartsAxisTooltipContent(props) {
|
|
10
11
|
var content = props.content,
|
|
@@ -24,9 +25,7 @@ function ChartsAxisTooltipContent(props) {
|
|
|
24
25
|
var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
25
26
|
var relevantSeries = React.useMemo(function () {
|
|
26
27
|
var rep = [];
|
|
27
|
-
Object.keys(series).filter(function (seriesType) {
|
|
28
|
-
return ['bar', 'line', 'scatter'].includes(seriesType);
|
|
29
|
-
}).forEach(function (seriesType) {
|
|
28
|
+
Object.keys(series).filter(isCartesianSeriesType).forEach(function (seriesType) {
|
|
30
29
|
series[seriesType].seriesOrder.forEach(function (seriesId) {
|
|
31
30
|
var item = series[seriesType].series[seriesId];
|
|
32
31
|
var axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
|
|
@@ -65,11 +64,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
|
|
|
65
64
|
axisData: PropTypes.shape({
|
|
66
65
|
x: PropTypes.shape({
|
|
67
66
|
index: PropTypes.number,
|
|
68
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
67
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
69
68
|
}),
|
|
70
69
|
y: PropTypes.shape({
|
|
71
70
|
index: PropTypes.number,
|
|
72
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
71
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
73
72
|
})
|
|
74
73
|
}).isRequired,
|
|
75
74
|
classes: PropTypes.object.isRequired,
|
|
@@ -79,11 +78,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
|
|
|
79
78
|
axisData: PropTypes.shape({
|
|
80
79
|
x: PropTypes.shape({
|
|
81
80
|
index: PropTypes.number,
|
|
82
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
81
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
83
82
|
}),
|
|
84
83
|
y: PropTypes.shape({
|
|
85
84
|
index: PropTypes.number,
|
|
86
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
85
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
87
86
|
})
|
|
88
87
|
}),
|
|
89
88
|
axisValue: PropTypes.any,
|
|
@@ -37,7 +37,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
|
|
|
37
37
|
classes: PropTypes.object,
|
|
38
38
|
itemData: PropTypes.shape({
|
|
39
39
|
dataIndex: PropTypes.number,
|
|
40
|
-
seriesId: PropTypes.string.isRequired,
|
|
40
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
41
41
|
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
|
|
42
42
|
}),
|
|
43
43
|
series: PropTypes.object,
|
|
@@ -45,7 +45,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
|
|
|
45
45
|
}),
|
|
46
46
|
itemData: PropTypes.shape({
|
|
47
47
|
dataIndex: PropTypes.number,
|
|
48
|
-
seriesId: PropTypes.string.isRequired,
|
|
48
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
49
49
|
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
|
|
50
50
|
}).isRequired,
|
|
51
51
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import Typography from '@mui/material/Typography';
|
|
5
5
|
import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
|
|
6
|
+
import { isCartesianSeries, utcFormatter } from './utils';
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
9
|
function DefaultChartsAxisTooltipContent(props) {
|
|
@@ -17,7 +18,7 @@ function DefaultChartsAxisTooltipContent(props) {
|
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
19
20
|
var axisFormatter = (_axis$valueFormatter = axis.valueFormatter) != null ? _axis$valueFormatter : function (v) {
|
|
20
|
-
return v.toLocaleString();
|
|
21
|
+
return axis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString();
|
|
21
22
|
};
|
|
22
23
|
return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
|
|
23
24
|
sx: sx,
|
|
@@ -34,13 +35,15 @@ function DefaultChartsAxisTooltipContent(props) {
|
|
|
34
35
|
})
|
|
35
36
|
})
|
|
36
37
|
}), /*#__PURE__*/_jsx("tbody", {
|
|
37
|
-
children: series.map(function (_ref) {
|
|
38
|
+
children: series.filter(isCartesianSeries).map(function (_ref) {
|
|
39
|
+
var _data$dataIndex;
|
|
38
40
|
var color = _ref.color,
|
|
39
41
|
id = _ref.id,
|
|
40
42
|
label = _ref.label,
|
|
41
43
|
valueFormatter = _ref.valueFormatter,
|
|
42
44
|
data = _ref.data;
|
|
43
|
-
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
var formattedValue = valueFormatter((_data$dataIndex = data[dataIndex]) != null ? _data$dataIndex : null);
|
|
44
47
|
if (formattedValue == null) {
|
|
45
48
|
return null;
|
|
46
49
|
}
|
|
@@ -87,11 +90,11 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
|
|
|
87
90
|
axisData: PropTypes.shape({
|
|
88
91
|
x: PropTypes.shape({
|
|
89
92
|
index: PropTypes.number,
|
|
90
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
93
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
91
94
|
}),
|
|
92
95
|
y: PropTypes.shape({
|
|
93
96
|
index: PropTypes.number,
|
|
94
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
97
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
95
98
|
})
|
|
96
99
|
}).isRequired,
|
|
97
100
|
/**
|
|
@@ -66,7 +66,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
|
|
|
66
66
|
*/
|
|
67
67
|
itemData: PropTypes.shape({
|
|
68
68
|
dataIndex: PropTypes.number,
|
|
69
|
-
seriesId: PropTypes.string.isRequired,
|
|
69
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
70
70
|
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
|
|
71
71
|
}).isRequired,
|
|
72
72
|
/**
|
|
@@ -88,4 +88,16 @@ export function getTooltipHasData(trigger, displayedData) {
|
|
|
88
88
|
var hasAxisXData = displayedData.x !== null;
|
|
89
89
|
var hasAxisYData = displayedData.y !== null;
|
|
90
90
|
return hasAxisXData || hasAxisYData;
|
|
91
|
+
}
|
|
92
|
+
export function isCartesianSeriesType(seriesType) {
|
|
93
|
+
return ['bar', 'line', 'scatter'].includes(seriesType);
|
|
94
|
+
}
|
|
95
|
+
export function isCartesianSeries(series) {
|
|
96
|
+
return isCartesianSeriesType(series.type);
|
|
97
|
+
}
|
|
98
|
+
export function utcFormatter(v) {
|
|
99
|
+
if (v instanceof Date) {
|
|
100
|
+
return v.toUTCString();
|
|
101
|
+
}
|
|
102
|
+
return v.toLocaleString();
|
|
91
103
|
}
|
|
@@ -11,7 +11,8 @@ import { getSVGPoint } from '../internals/utils';
|
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
function ChartsVoronoiHandler(props) {
|
|
13
13
|
var _React$useContext$sca;
|
|
14
|
-
var voronoiMaxRadius = props.voronoiMaxRadius
|
|
14
|
+
var voronoiMaxRadius = props.voronoiMaxRadius,
|
|
15
|
+
onItemClick = props.onItemClick;
|
|
15
16
|
var svgRef = React.useContext(SVGContext);
|
|
16
17
|
var _React$useContext = React.useContext(DrawingContext),
|
|
17
18
|
width = _React$useContext.width,
|
|
@@ -44,6 +45,8 @@ function ChartsVoronoiHandler(props) {
|
|
|
44
45
|
};
|
|
45
46
|
}, [dispatch]);
|
|
46
47
|
useEnhancedEffect(function () {
|
|
48
|
+
// This effect generate and store the Delaunay object that's used to map coordinate to closest point.
|
|
49
|
+
|
|
47
50
|
if (seriesOrder === undefined || series === undefined) {
|
|
48
51
|
// If there is no scatter chart series
|
|
49
52
|
return;
|
|
@@ -77,81 +80,122 @@ function ChartsVoronoiHandler(props) {
|
|
|
77
80
|
if (element === null) {
|
|
78
81
|
return undefined;
|
|
79
82
|
}
|
|
80
|
-
var handleMouseOut = function handleMouseOut() {
|
|
81
|
-
dispatch({
|
|
82
|
-
type: 'exitChart'
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
83
|
|
|
86
84
|
// TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
|
|
87
|
-
|
|
85
|
+
function getClosestPoint(event) {
|
|
88
86
|
var _voronoiRef$current$d;
|
|
89
87
|
// Get mouse coordinate in global SVG space
|
|
90
88
|
var svgPoint = getSVGPoint(svgRef.current, event);
|
|
91
89
|
var outsideX = svgPoint.x < left || svgPoint.x > left + width;
|
|
92
90
|
var outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
93
91
|
if (outsideX || outsideY) {
|
|
94
|
-
|
|
95
|
-
type: 'exitChart'
|
|
96
|
-
});
|
|
97
|
-
return;
|
|
92
|
+
return 'outside-chart';
|
|
98
93
|
}
|
|
99
94
|
if (!voronoiRef.current.delauney) {
|
|
100
|
-
return;
|
|
95
|
+
return 'no-point-found';
|
|
101
96
|
}
|
|
102
97
|
var closestPointIndex = (_voronoiRef$current$d = voronoiRef.current.delauney) == null ? void 0 : _voronoiRef$current$d.find(svgPoint.x, svgPoint.y);
|
|
103
|
-
if (closestPointIndex
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return
|
|
109
|
-
});
|
|
110
|
-
if (seriesId === undefined) {
|
|
111
|
-
return;
|
|
98
|
+
if (closestPointIndex === undefined) {
|
|
99
|
+
return 'no-point-found';
|
|
100
|
+
}
|
|
101
|
+
var seriesId = Object.keys(voronoiRef.current).find(function (id) {
|
|
102
|
+
if (id === 'delauney') {
|
|
103
|
+
return false;
|
|
112
104
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
105
|
+
return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
|
|
106
|
+
});
|
|
107
|
+
if (seriesId === undefined) {
|
|
108
|
+
return 'no-point-found';
|
|
109
|
+
}
|
|
110
|
+
var dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
|
|
111
|
+
if (voronoiMaxRadius !== undefined) {
|
|
112
|
+
var pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
|
|
113
|
+
var pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
|
|
114
|
+
var dist2 = Math.pow(pointX - svgPoint.x, 2) + Math.pow(pointY - svgPoint.y, 2);
|
|
115
|
+
if (dist2 > Math.pow(voronoiMaxRadius, 2)) {
|
|
116
|
+
// The closest point is too far to be considered.
|
|
117
|
+
return 'outside-voronoi-max-radius';
|
|
130
118
|
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
seriesId: seriesId,
|
|
122
|
+
dataIndex: dataIndex
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
var handleMouseOut = function handleMouseOut() {
|
|
126
|
+
dispatch({
|
|
127
|
+
type: 'exitChart'
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
var handleMouseMove = function handleMouseMove(event) {
|
|
131
|
+
var closestPoint = getClosestPoint(event);
|
|
132
|
+
if (closestPoint === 'outside-chart') {
|
|
131
133
|
dispatch({
|
|
132
|
-
type: '
|
|
134
|
+
type: 'exitChart'
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (closestPoint === 'outside-voronoi-max-radius' || closestPoint === 'no-point-found') {
|
|
139
|
+
dispatch({
|
|
140
|
+
type: 'leaveItem',
|
|
133
141
|
data: {
|
|
134
|
-
type: 'scatter'
|
|
135
|
-
seriesId: seriesId,
|
|
136
|
-
dataIndex: dataIndex
|
|
142
|
+
type: 'scatter'
|
|
137
143
|
}
|
|
138
144
|
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
var seriesId = closestPoint.seriesId,
|
|
148
|
+
dataIndex = closestPoint.dataIndex;
|
|
149
|
+
dispatch({
|
|
150
|
+
type: 'enterItem',
|
|
151
|
+
data: {
|
|
152
|
+
type: 'scatter',
|
|
153
|
+
seriesId: seriesId,
|
|
154
|
+
dataIndex: dataIndex
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
var handleMouseClick = function handleMouseClick(event) {
|
|
159
|
+
if (!onItemClick) {
|
|
160
|
+
return;
|
|
139
161
|
}
|
|
162
|
+
var closestPoint = getClosestPoint(event);
|
|
163
|
+
if (typeof closestPoint === 'string') {
|
|
164
|
+
// No point fond for any reason
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
var seriesId = closestPoint.seriesId,
|
|
168
|
+
dataIndex = closestPoint.dataIndex;
|
|
169
|
+
onItemClick(event, {
|
|
170
|
+
type: 'scatter',
|
|
171
|
+
seriesId: seriesId,
|
|
172
|
+
dataIndex: dataIndex
|
|
173
|
+
});
|
|
140
174
|
};
|
|
141
175
|
element.addEventListener('mouseout', handleMouseOut);
|
|
142
176
|
element.addEventListener('mousemove', handleMouseMove);
|
|
177
|
+
element.addEventListener('click', handleMouseClick);
|
|
143
178
|
return function () {
|
|
144
179
|
element.removeEventListener('mouseout', handleMouseOut);
|
|
145
180
|
element.removeEventListener('mousemove', handleMouseMove);
|
|
181
|
+
element.removeEventListener('click', handleMouseClick);
|
|
146
182
|
};
|
|
147
|
-
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
|
|
148
|
-
|
|
183
|
+
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick]);
|
|
184
|
+
|
|
185
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
186
|
+
return /*#__PURE__*/_jsx(React.Fragment, {});
|
|
149
187
|
}
|
|
150
188
|
process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
|
|
151
189
|
// ----------------------------- Warning --------------------------------
|
|
152
190
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
153
191
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
154
192
|
// ----------------------------------------------------------------------
|
|
193
|
+
/**
|
|
194
|
+
* Callback fired when clicking on a scatter item.
|
|
195
|
+
* @param {MouseEvent} event Mouse event catched at the svg level
|
|
196
|
+
* @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
|
|
197
|
+
*/
|
|
198
|
+
onItemClick: PropTypes.func,
|
|
155
199
|
/**
|
|
156
200
|
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
157
201
|
* If `undefined`, the radius is assumed to be infinite.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
var _excluded = ["scale", "tickNumber"];
|
|
4
|
+
var _excluded = ["scale", "tickNumber", "reverse"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { useSlotProps } from '@mui/base/utils';
|
|
@@ -34,6 +34,7 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
34
34
|
function addLabelDimension(xTicks, _ref) {
|
|
35
35
|
var style = _ref.tickLabelStyle,
|
|
36
36
|
tickLabelInterval = _ref.tickLabelInterval,
|
|
37
|
+
reverse = _ref.reverse,
|
|
37
38
|
isMounted = _ref.isMounted;
|
|
38
39
|
var withDimension = xTicks.map(function (tick) {
|
|
39
40
|
if (!isMounted || tick.formattedValue === undefined) {
|
|
@@ -63,8 +64,9 @@ function addLabelDimension(xTicks, _ref) {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
// Filter label to avoid overlap
|
|
66
|
-
var
|
|
67
|
-
var
|
|
67
|
+
var currentTextLimit = 0;
|
|
68
|
+
var previouseTextLimit = 0;
|
|
69
|
+
var direction = reverse ? -1 : 1;
|
|
68
70
|
return withDimension.map(function (item, labelIndex) {
|
|
69
71
|
var width = item.width,
|
|
70
72
|
offset = item.offset,
|
|
@@ -74,15 +76,15 @@ function addLabelDimension(xTicks, _ref) {
|
|
|
74
76
|
var textPosition = offset + labelOffset;
|
|
75
77
|
var gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
if (labelIndex > 0 &&
|
|
79
|
+
currentTextLimit = textPosition - direction * (gapRatio * distance) / 2;
|
|
80
|
+
if (labelIndex > 0 && direction * currentTextLimit < direction * previouseTextLimit) {
|
|
79
81
|
// Except for the first label, we skip all label that overlap with the last accepted.
|
|
80
|
-
// Notice that the early return prevents `
|
|
82
|
+
// Notice that the early return prevents `previouseTextLimit` from being updated.
|
|
81
83
|
return _extends({}, item, {
|
|
82
84
|
skipLabel: true
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
previouseTextLimit = textPosition + direction * (gapRatio * distance) / 2;
|
|
86
88
|
return item;
|
|
87
89
|
});
|
|
88
90
|
}
|
|
@@ -114,6 +116,7 @@ function ChartsXAxis(inProps) {
|
|
|
114
116
|
_React$useContext2$xA = _React$useContext2.xAxis[(_props$axisId = props.axisId) != null ? _props$axisId : xAxisIds[0]],
|
|
115
117
|
xScale = _React$useContext2$xA.scale,
|
|
116
118
|
tickNumber = _React$useContext2$xA.tickNumber,
|
|
119
|
+
reverse = _React$useContext2$xA.reverse,
|
|
117
120
|
settings = _objectWithoutProperties(_React$useContext2$xA, _excluded);
|
|
118
121
|
var isMounted = useMounted();
|
|
119
122
|
var defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
@@ -169,6 +172,7 @@ function ChartsXAxis(inProps) {
|
|
|
169
172
|
var xTicksWithDimension = addLabelDimension(xTicks, {
|
|
170
173
|
tickLabelStyle: axisTickLabelProps.style,
|
|
171
174
|
tickLabelInterval: tickLabelInterval,
|
|
175
|
+
reverse: reverse,
|
|
172
176
|
isMounted: isMounted
|
|
173
177
|
});
|
|
174
178
|
var labelRefPoint = {
|
|
@@ -231,7 +235,7 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
231
235
|
* The id of the axis to render.
|
|
232
236
|
* If undefined, it will be the first defined axis.
|
|
233
237
|
*/
|
|
234
|
-
axisId: PropTypes.string,
|
|
238
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
235
239
|
/**
|
|
236
240
|
* Override or extend the styles applied to the component.
|
|
237
241
|
*/
|
|
@@ -163,7 +163,7 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
163
163
|
* The id of the axis to render.
|
|
164
164
|
* If undefined, it will be the first defined axis.
|
|
165
165
|
*/
|
|
166
|
-
axisId: PropTypes.string,
|
|
166
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
167
167
|
/**
|
|
168
168
|
* Override or extend the styles applied to the component.
|
|
169
169
|
*/
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["d", "skipAnimation", "ownerState"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { styled } from '@mui/material/styles';
|
|
7
|
+
import { color as d3Color } from 'd3-color';
|
|
8
|
+
import { animated, useSpring } from '@react-spring/web';
|
|
9
|
+
import { useAnimatedPath } from '../internals/useAnimatedPath';
|
|
10
|
+
import { DrawingContext } from '../context/DrawingProvider';
|
|
11
|
+
import { cleanId } from '../internals/utils';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
export var AreaElementPath = styled(animated.path, {
|
|
15
|
+
name: 'MuiAreaElement',
|
|
16
|
+
slot: 'Root',
|
|
17
|
+
overridesResolver: function overridesResolver(_, styles) {
|
|
18
|
+
return styles.root;
|
|
19
|
+
}
|
|
20
|
+
})(function (_ref) {
|
|
21
|
+
var ownerState = _ref.ownerState;
|
|
22
|
+
return {
|
|
23
|
+
stroke: 'none',
|
|
24
|
+
fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
|
|
25
|
+
transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
|
|
26
|
+
opacity: ownerState.isFaded ? 0.3 : 1
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Demos:
|
|
31
|
+
*
|
|
32
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
33
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
34
|
+
*
|
|
35
|
+
* API:
|
|
36
|
+
*
|
|
37
|
+
* - [AreaElement API](https://mui.com/x/api/charts/animated-area/)
|
|
38
|
+
*/
|
|
39
|
+
function AnimatedArea(props) {
|
|
40
|
+
var d = props.d,
|
|
41
|
+
skipAnimation = props.skipAnimation,
|
|
42
|
+
ownerState = props.ownerState,
|
|
43
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
44
|
+
var _React$useContext = React.useContext(DrawingContext),
|
|
45
|
+
left = _React$useContext.left,
|
|
46
|
+
top = _React$useContext.top,
|
|
47
|
+
right = _React$useContext.right,
|
|
48
|
+
bottom = _React$useContext.bottom,
|
|
49
|
+
width = _React$useContext.width,
|
|
50
|
+
height = _React$useContext.height,
|
|
51
|
+
chartId = _React$useContext.chartId;
|
|
52
|
+
var path = useAnimatedPath(d, skipAnimation);
|
|
53
|
+
var _useSpring = useSpring({
|
|
54
|
+
from: {
|
|
55
|
+
animatedWidth: left
|
|
56
|
+
},
|
|
57
|
+
to: {
|
|
58
|
+
animatedWidth: width + left + right
|
|
59
|
+
},
|
|
60
|
+
reset: false,
|
|
61
|
+
immediate: skipAnimation
|
|
62
|
+
}),
|
|
63
|
+
animatedWidth = _useSpring.animatedWidth;
|
|
64
|
+
var clipId = cleanId("".concat(chartId, "-").concat(ownerState.id, "-area-clip"));
|
|
65
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
66
|
+
children: [/*#__PURE__*/_jsx("clipPath", {
|
|
67
|
+
id: clipId,
|
|
68
|
+
children: /*#__PURE__*/_jsx(animated.rect, {
|
|
69
|
+
x: 0,
|
|
70
|
+
y: 0,
|
|
71
|
+
width: animatedWidth,
|
|
72
|
+
height: top + height + bottom
|
|
73
|
+
})
|
|
74
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
75
|
+
clipPath: "url(#".concat(clipId, ")"),
|
|
76
|
+
children: /*#__PURE__*/_jsx(AreaElementPath, _extends({}, other, {
|
|
77
|
+
ownerState: ownerState,
|
|
78
|
+
d: path
|
|
79
|
+
}))
|
|
80
|
+
})]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
|
|
84
|
+
// ----------------------------- Warning --------------------------------
|
|
85
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
86
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
87
|
+
// ----------------------------------------------------------------------
|
|
88
|
+
d: PropTypes.string.isRequired,
|
|
89
|
+
ownerState: PropTypes.shape({
|
|
90
|
+
classes: PropTypes.object,
|
|
91
|
+
color: PropTypes.string.isRequired,
|
|
92
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
93
|
+
isFaded: PropTypes.bool.isRequired,
|
|
94
|
+
isHighlighted: PropTypes.bool.isRequired
|
|
95
|
+
}).isRequired,
|
|
96
|
+
/**
|
|
97
|
+
* If `true`, animations are skipped.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
skipAnimation: PropTypes.bool
|
|
101
|
+
} : void 0;
|
|
102
|
+
export { AnimatedArea };
|