@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.d.ts +2 -1
- package/BarChart/BarChart.js +23 -4
- package/BarChart/BarElement.d.ts +1 -1
- package/BarChart/BarElement.js +6 -3
- package/BarChart/BarPlot.d.ts +8 -1
- package/BarChart/BarPlot.js +19 -5
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +247 -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/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
- package/ChartsTooltip/utils.d.ts +3 -1
- package/ChartsTooltip/utils.js +8 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- 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 +17 -17
- 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 +35 -6
- package/LineChart/LineElement.d.ts +17 -17
- package/LineChart/LineElement.js +16 -36
- package/LineChart/LineHighlightElement.js +3 -2
- package/LineChart/LinePlot.d.ts +12 -7
- package/LineChart/LinePlot.js +89 -56
- package/LineChart/MarkElement.d.ts +5 -2
- package/LineChart/MarkElement.js +26 -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/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +1 -1
- package/PieChart/PieArcPlot.d.ts +2 -2
- package/PieChart/PieArcPlot.js +6 -6
- package/PieChart/PieChart.d.ts +1 -1
- package/PieChart/PieChart.js +4 -4
- package/PieChart/PiePlot.d.ts +1 -1
- package/PieChart/PiePlot.js +4 -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 +11 -2
- package/ScatterChart/ScatterPlot.d.ts +1 -1
- package/ScatterChart/ScatterPlot.js +10 -2
- package/SparkLineChart/SparkLineChart.js +2 -0
- 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 +23 -4
- package/esm/BarChart/BarElement.js +6 -3
- package/esm/BarChart/BarPlot.js +19 -5
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
- package/esm/ChartsOnAxisClickHandler/index.js +1 -0
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
- package/esm/ChartsTooltip/utils.js +6 -0
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- 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 +35 -6
- package/esm/LineChart/LineElement.js +16 -35
- package/esm/LineChart/LineHighlightElement.js +3 -2
- package/esm/LineChart/LinePlot.js +90 -57
- package/esm/LineChart/MarkElement.js +26 -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/PieArcLabelPlot.js +1 -1
- package/esm/PieChart/PieArcPlot.js +6 -6
- package/esm/PieChart/PieChart.js +4 -4
- package/esm/PieChart/PiePlot.js +4 -4
- package/esm/ScatterChart/Scatter.js +17 -3
- package/esm/ScatterChart/ScatterChart.js +11 -2
- package/esm/ScatterChart/ScatterPlot.js +10 -2
- package/esm/SparkLineChart/SparkLineChart.js +2 -0
- 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/geometry.js +1 -1
- 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 +23 -4
- package/legacy/BarChart/BarElement.js +5 -2
- package/legacy/BarChart/BarPlot.js +18 -4
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
- package/legacy/ChartsTooltip/utils.js +6 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
- 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 +35 -6
- package/legacy/LineChart/LineElement.js +15 -37
- package/legacy/LineChart/LineHighlightElement.js +3 -2
- package/legacy/LineChart/LinePlot.js +97 -63
- package/legacy/LineChart/MarkElement.js +29 -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/PieArcLabelPlot.js +1 -1
- package/legacy/PieChart/PieArcPlot.js +6 -6
- package/legacy/PieChart/PieChart.js +4 -4
- package/legacy/PieChart/PiePlot.js +4 -4
- package/legacy/ScatterChart/Scatter.js +19 -3
- package/legacy/ScatterChart/ScatterChart.js +11 -2
- package/legacy/ScatterChart/ScatterPlot.js +10 -2
- package/legacy/SparkLineChart/SparkLineChart.js +2 -0
- 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/modern/BarChart/BarChart.js +23 -4
- package/modern/BarChart/BarElement.js +6 -3
- package/modern/BarChart/BarPlot.js +19 -5
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/modern/ChartsOnAxisClickHandler/index.js +1 -0
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
- package/modern/ChartsTooltip/utils.js +6 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- 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 +35 -6
- package/modern/LineChart/LineElement.js +16 -35
- package/modern/LineChart/LineHighlightElement.js +3 -2
- package/modern/LineChart/LinePlot.js +89 -56
- package/modern/LineChart/MarkElement.js +26 -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/PieArcLabelPlot.js +1 -1
- package/modern/PieChart/PieArcPlot.js +6 -6
- package/modern/PieChart/PieChart.js +4 -4
- package/modern/PieChart/PiePlot.js +4 -4
- package/modern/ScatterChart/Scatter.js +17 -3
- package/modern/ScatterChart/ScatterChart.js +11 -2
- package/modern/ScatterChart/ScatterPlot.js +10 -2
- package/modern/SparkLineChart/SparkLineChart.js +2 -0
- 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,103 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _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 const AreaElementPath = styled(animated.path, {
|
|
15
|
+
name: 'MuiAreaElement',
|
|
16
|
+
slot: 'Root',
|
|
17
|
+
overridesResolver: (_, styles) => styles.root
|
|
18
|
+
})(({
|
|
19
|
+
ownerState
|
|
20
|
+
}) => ({
|
|
21
|
+
stroke: 'none',
|
|
22
|
+
fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
|
|
23
|
+
transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
|
|
24
|
+
opacity: ownerState.isFaded ? 0.3 : 1
|
|
25
|
+
}));
|
|
26
|
+
/**
|
|
27
|
+
* Demos:
|
|
28
|
+
*
|
|
29
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
30
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
31
|
+
*
|
|
32
|
+
* API:
|
|
33
|
+
*
|
|
34
|
+
* - [AreaElement API](https://mui.com/x/api/charts/animated-area/)
|
|
35
|
+
*/
|
|
36
|
+
function AnimatedArea(props) {
|
|
37
|
+
const {
|
|
38
|
+
d,
|
|
39
|
+
skipAnimation,
|
|
40
|
+
ownerState
|
|
41
|
+
} = props,
|
|
42
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
43
|
+
const {
|
|
44
|
+
left,
|
|
45
|
+
top,
|
|
46
|
+
right,
|
|
47
|
+
bottom,
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
chartId
|
|
51
|
+
} = React.useContext(DrawingContext);
|
|
52
|
+
const path = useAnimatedPath(d, skipAnimation);
|
|
53
|
+
const {
|
|
54
|
+
animatedWidth
|
|
55
|
+
} = useSpring({
|
|
56
|
+
from: {
|
|
57
|
+
animatedWidth: left
|
|
58
|
+
},
|
|
59
|
+
to: {
|
|
60
|
+
animatedWidth: width + left + right
|
|
61
|
+
},
|
|
62
|
+
reset: false,
|
|
63
|
+
immediate: skipAnimation
|
|
64
|
+
});
|
|
65
|
+
const clipId = cleanId(`${chartId}-${ownerState.id}-area-clip`);
|
|
66
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
67
|
+
children: [/*#__PURE__*/_jsx("clipPath", {
|
|
68
|
+
id: clipId,
|
|
69
|
+
children: /*#__PURE__*/_jsx(animated.rect, {
|
|
70
|
+
x: 0,
|
|
71
|
+
y: 0,
|
|
72
|
+
width: animatedWidth,
|
|
73
|
+
height: top + height + bottom
|
|
74
|
+
})
|
|
75
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
76
|
+
clipPath: `url(#${clipId})`,
|
|
77
|
+
children: /*#__PURE__*/_jsx(AreaElementPath, _extends({}, other, {
|
|
78
|
+
ownerState: ownerState,
|
|
79
|
+
d: path
|
|
80
|
+
}))
|
|
81
|
+
})]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
|
|
85
|
+
// ----------------------------- Warning --------------------------------
|
|
86
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
87
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
88
|
+
// ----------------------------------------------------------------------
|
|
89
|
+
d: PropTypes.string.isRequired,
|
|
90
|
+
ownerState: PropTypes.shape({
|
|
91
|
+
classes: PropTypes.object,
|
|
92
|
+
color: PropTypes.string.isRequired,
|
|
93
|
+
id: PropTypes.string.isRequired,
|
|
94
|
+
isFaded: PropTypes.bool.isRequired,
|
|
95
|
+
isHighlighted: PropTypes.bool.isRequired
|
|
96
|
+
}).isRequired,
|
|
97
|
+
/**
|
|
98
|
+
* If `true`, animations are skipped.
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
skipAnimation: PropTypes.bool
|
|
102
|
+
} : void 0;
|
|
103
|
+
export { AnimatedArea };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["d", "skipAnimation", "ownerState"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { animated, useSpring } from '@react-spring/web';
|
|
7
|
+
import { color as d3Color } from 'd3-color';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
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 const LineElementPath = styled(animated.path, {
|
|
15
|
+
name: 'MuiLineElement',
|
|
16
|
+
slot: 'Root',
|
|
17
|
+
overridesResolver: (_, styles) => styles.root
|
|
18
|
+
})(({
|
|
19
|
+
ownerState
|
|
20
|
+
}) => ({
|
|
21
|
+
strokeWidth: 2,
|
|
22
|
+
strokeLinejoin: 'round',
|
|
23
|
+
fill: 'none',
|
|
24
|
+
stroke: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
|
|
25
|
+
transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
|
|
26
|
+
opacity: ownerState.isFaded ? 0.3 : 1
|
|
27
|
+
}));
|
|
28
|
+
/**
|
|
29
|
+
* Demos:
|
|
30
|
+
*
|
|
31
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
32
|
+
* - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
|
|
33
|
+
*
|
|
34
|
+
* API:
|
|
35
|
+
*
|
|
36
|
+
* - [AnimatedLine API](https://mui.com/x/api/charts/animated-line/)
|
|
37
|
+
*/
|
|
38
|
+
function AnimatedLine(props) {
|
|
39
|
+
const {
|
|
40
|
+
d,
|
|
41
|
+
skipAnimation,
|
|
42
|
+
ownerState
|
|
43
|
+
} = props,
|
|
44
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
45
|
+
const {
|
|
46
|
+
left,
|
|
47
|
+
top,
|
|
48
|
+
bottom,
|
|
49
|
+
width,
|
|
50
|
+
height,
|
|
51
|
+
right,
|
|
52
|
+
chartId
|
|
53
|
+
} = React.useContext(DrawingContext);
|
|
54
|
+
const path = useAnimatedPath(d, skipAnimation);
|
|
55
|
+
const {
|
|
56
|
+
animatedWidth
|
|
57
|
+
} = useSpring({
|
|
58
|
+
from: {
|
|
59
|
+
animatedWidth: left
|
|
60
|
+
},
|
|
61
|
+
to: {
|
|
62
|
+
animatedWidth: width + left + right
|
|
63
|
+
},
|
|
64
|
+
reset: false,
|
|
65
|
+
immediate: skipAnimation
|
|
66
|
+
});
|
|
67
|
+
const clipId = cleanId(`${chartId}-${ownerState.id}-line-clip`);
|
|
68
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
69
|
+
children: [/*#__PURE__*/_jsx("clipPath", {
|
|
70
|
+
id: clipId,
|
|
71
|
+
children: /*#__PURE__*/_jsx(animated.rect, {
|
|
72
|
+
x: 0,
|
|
73
|
+
y: 0,
|
|
74
|
+
width: animatedWidth,
|
|
75
|
+
height: top + height + bottom
|
|
76
|
+
})
|
|
77
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
78
|
+
clipPath: `url(#${clipId})`,
|
|
79
|
+
children: /*#__PURE__*/_jsx(LineElementPath, _extends({}, other, {
|
|
80
|
+
ownerState: ownerState,
|
|
81
|
+
d: path
|
|
82
|
+
}))
|
|
83
|
+
})]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
process.env.NODE_ENV !== "production" ? AnimatedLine.propTypes = {
|
|
87
|
+
// ----------------------------- Warning --------------------------------
|
|
88
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
89
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
90
|
+
// ----------------------------------------------------------------------
|
|
91
|
+
d: PropTypes.string.isRequired,
|
|
92
|
+
ownerState: PropTypes.shape({
|
|
93
|
+
classes: PropTypes.object,
|
|
94
|
+
color: PropTypes.string.isRequired,
|
|
95
|
+
id: PropTypes.string.isRequired,
|
|
96
|
+
isFaded: PropTypes.bool.isRequired,
|
|
97
|
+
isHighlighted: PropTypes.bool.isRequired
|
|
98
|
+
}).isRequired,
|
|
99
|
+
/**
|
|
100
|
+
* If `true`, animations are skipped.
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
skipAnimation: PropTypes.bool
|
|
104
|
+
} : void 0;
|
|
105
|
+
export { AnimatedLine };
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps"];
|
|
3
|
+
const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
7
7
|
import { useSlotProps } from '@mui/base/utils';
|
|
8
8
|
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
9
|
-
import { styled } from '@mui/material/styles';
|
|
10
9
|
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
11
|
-
import { color as d3Color } from 'd3-color';
|
|
12
10
|
import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
13
11
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
12
|
+
import { AnimatedArea } from './AnimatedArea';
|
|
14
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
14
|
export function getAreaElementUtilityClass(slot) {
|
|
16
15
|
return generateUtilityClass('MuiAreaElement', slot);
|
|
@@ -28,33 +27,6 @@ const useUtilityClasses = ownerState => {
|
|
|
28
27
|
};
|
|
29
28
|
return composeClasses(slots, getAreaElementUtilityClass, classes);
|
|
30
29
|
};
|
|
31
|
-
export const AreaElementPath = styled('path', {
|
|
32
|
-
name: 'MuiAreaElement',
|
|
33
|
-
slot: 'Root',
|
|
34
|
-
overridesResolver: (_, styles) => styles.root
|
|
35
|
-
})(({
|
|
36
|
-
ownerState
|
|
37
|
-
}) => ({
|
|
38
|
-
stroke: 'none',
|
|
39
|
-
fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
|
|
40
|
-
transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
|
|
41
|
-
opacity: ownerState.isFaded ? 0.3 : 1
|
|
42
|
-
}));
|
|
43
|
-
AreaElementPath.propTypes = {
|
|
44
|
-
// ----------------------------- Warning --------------------------------
|
|
45
|
-
// | These PropTypes are generated from the TypeScript type definitions |
|
|
46
|
-
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
47
|
-
// ----------------------------------------------------------------------
|
|
48
|
-
as: PropTypes.elementType,
|
|
49
|
-
ownerState: PropTypes.shape({
|
|
50
|
-
classes: PropTypes.object,
|
|
51
|
-
color: PropTypes.string.isRequired,
|
|
52
|
-
id: PropTypes.string.isRequired,
|
|
53
|
-
isFaded: PropTypes.bool.isRequired,
|
|
54
|
-
isHighlighted: PropTypes.bool.isRequired
|
|
55
|
-
}).isRequired,
|
|
56
|
-
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
57
|
-
};
|
|
58
30
|
/**
|
|
59
31
|
* Demos:
|
|
60
32
|
*
|
|
@@ -73,7 +45,8 @@ function AreaElement(props) {
|
|
|
73
45
|
color,
|
|
74
46
|
highlightScope,
|
|
75
47
|
slots,
|
|
76
|
-
slotProps
|
|
48
|
+
slotProps,
|
|
49
|
+
onClick
|
|
77
50
|
} = props,
|
|
78
51
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
79
52
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -96,7 +69,7 @@ function AreaElement(props) {
|
|
|
96
69
|
isHighlighted
|
|
97
70
|
};
|
|
98
71
|
const classes = useUtilityClasses(ownerState);
|
|
99
|
-
const Area = (_slots$area = slots == null ? void 0 : slots.area) != null ? _slots$area :
|
|
72
|
+
const Area = (_slots$area = slots == null ? void 0 : slots.area) != null ? _slots$area : AnimatedArea;
|
|
100
73
|
const areaProps = useSlotProps({
|
|
101
74
|
elementType: Area,
|
|
102
75
|
externalSlotProps: slotProps == null ? void 0 : slotProps.area,
|
|
@@ -104,7 +77,9 @@ function AreaElement(props) {
|
|
|
104
77
|
type: 'line',
|
|
105
78
|
seriesId: id
|
|
106
79
|
}), {
|
|
107
|
-
className: classes.root
|
|
80
|
+
className: classes.root,
|
|
81
|
+
onClick,
|
|
82
|
+
cursor: onClick ? 'pointer' : 'unset'
|
|
108
83
|
}),
|
|
109
84
|
ownerState
|
|
110
85
|
});
|
|
@@ -116,10 +91,18 @@ process.env.NODE_ENV !== "production" ? AreaElement.propTypes = {
|
|
|
116
91
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
117
92
|
// ----------------------------------------------------------------------
|
|
118
93
|
classes: PropTypes.object,
|
|
94
|
+
color: PropTypes.string.isRequired,
|
|
95
|
+
d: PropTypes.string.isRequired,
|
|
119
96
|
highlightScope: PropTypes.shape({
|
|
120
97
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
121
98
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
122
99
|
}),
|
|
100
|
+
id: PropTypes.string.isRequired,
|
|
101
|
+
/**
|
|
102
|
+
* If `true`, animations are skipped.
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
skipAnimation: PropTypes.bool,
|
|
123
106
|
/**
|
|
124
107
|
* The props used for each component slot.
|
|
125
108
|
* @default {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["slots", "slotProps", "onItemClick", "skipAnimation"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { area as d3Area } from 'd3-shape';
|
|
@@ -11,27 +11,11 @@ import { getValueToPositionMapper } from '../hooks/useScale';
|
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
12
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
|
|
15
|
-
* Demos:
|
|
16
|
-
*
|
|
17
|
-
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
18
|
-
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
19
|
-
* - [Stacking](https://mui.com/x/react-charts/stacking/)
|
|
20
|
-
*
|
|
21
|
-
* API:
|
|
22
|
-
*
|
|
23
|
-
* - [AreaPlot API](https://mui.com/x/api/charts/area-plot/)
|
|
24
|
-
*/
|
|
25
|
-
function AreaPlot(props) {
|
|
26
|
-
const {
|
|
27
|
-
slots,
|
|
28
|
-
slotProps
|
|
29
|
-
} = props,
|
|
30
|
-
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
14
|
+
const useAggregatedData = () => {
|
|
31
15
|
const seriesData = React.useContext(SeriesContext).line;
|
|
32
16
|
const axisData = React.useContext(CartesianContext);
|
|
33
17
|
if (seriesData === undefined) {
|
|
34
|
-
return
|
|
18
|
+
return [];
|
|
35
19
|
}
|
|
36
20
|
const {
|
|
37
21
|
series,
|
|
@@ -45,47 +29,85 @@ function AreaPlot(props) {
|
|
|
45
29
|
} = axisData;
|
|
46
30
|
const defaultXAxisId = xAxisIds[0];
|
|
47
31
|
const defaultYAxisId = yAxisIds[0];
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
|
|
67
|
-
}
|
|
68
|
-
if (xData.length < stackedData.length) {
|
|
69
|
-
throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
|
|
70
|
-
}
|
|
32
|
+
return stackingGroups.flatMap(({
|
|
33
|
+
ids: groupIds
|
|
34
|
+
}) => {
|
|
35
|
+
return groupIds.flatMap(seriesId => {
|
|
36
|
+
var _xData$map;
|
|
37
|
+
const {
|
|
38
|
+
xAxisKey = defaultXAxisId,
|
|
39
|
+
yAxisKey = defaultYAxisId,
|
|
40
|
+
stackedData,
|
|
41
|
+
data,
|
|
42
|
+
connectNulls
|
|
43
|
+
} = series[seriesId];
|
|
44
|
+
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
45
|
+
const yScale = yAxis[yAxisKey].scale;
|
|
46
|
+
const xData = xAxis[xAxisKey].data;
|
|
47
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
48
|
+
if (xData === undefined) {
|
|
49
|
+
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
|
|
71
50
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
51
|
+
if (xData.length < stackedData.length) {
|
|
52
|
+
throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const areaPath = d3Area().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y0(d => d.y && yScale(d.y[0])).y1(d => d.y && yScale(d.y[1]));
|
|
56
|
+
const curve = getCurveFactory(series[seriesId].curve);
|
|
57
|
+
const formattedData = (_xData$map = xData == null ? void 0 : xData.map((x, index) => ({
|
|
58
|
+
x,
|
|
59
|
+
y: stackedData[index]
|
|
60
|
+
}))) != null ? _xData$map : [];
|
|
61
|
+
const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
|
|
62
|
+
const d = areaPath.curve(curve)(d3Data) || '';
|
|
63
|
+
return _extends({}, series[seriesId], {
|
|
64
|
+
d,
|
|
65
|
+
seriesId
|
|
87
66
|
});
|
|
88
|
-
})
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Demos:
|
|
73
|
+
*
|
|
74
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
75
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
76
|
+
* - [Stacking](https://mui.com/x/react-charts/stacking/)
|
|
77
|
+
*
|
|
78
|
+
* API:
|
|
79
|
+
*
|
|
80
|
+
* - [AreaPlot API](https://mui.com/x/api/charts/area-plot/)
|
|
81
|
+
*/
|
|
82
|
+
function AreaPlot(props) {
|
|
83
|
+
const {
|
|
84
|
+
slots,
|
|
85
|
+
slotProps,
|
|
86
|
+
onItemClick,
|
|
87
|
+
skipAnimation
|
|
88
|
+
} = props,
|
|
89
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
90
|
+
const completedData = useAggregatedData();
|
|
91
|
+
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
92
|
+
children: completedData.reverse().map(({
|
|
93
|
+
d,
|
|
94
|
+
seriesId,
|
|
95
|
+
color,
|
|
96
|
+
highlightScope,
|
|
97
|
+
area
|
|
98
|
+
}) => !!area && /*#__PURE__*/_jsx(AreaElement, {
|
|
99
|
+
id: seriesId,
|
|
100
|
+
d: d,
|
|
101
|
+
color: color,
|
|
102
|
+
highlightScope: highlightScope,
|
|
103
|
+
slots: slots,
|
|
104
|
+
slotProps: slotProps,
|
|
105
|
+
onClick: onItemClick && (event => onItemClick(event, {
|
|
106
|
+
type: 'line',
|
|
107
|
+
seriesId
|
|
108
|
+
})),
|
|
109
|
+
skipAnimation: skipAnimation
|
|
110
|
+
}, seriesId))
|
|
89
111
|
}));
|
|
90
112
|
}
|
|
91
113
|
process.env.NODE_ENV !== "production" ? AreaPlot.propTypes = {
|
|
@@ -93,6 +115,17 @@ process.env.NODE_ENV !== "production" ? AreaPlot.propTypes = {
|
|
|
93
115
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
94
116
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
95
117
|
// ----------------------------------------------------------------------
|
|
118
|
+
/**
|
|
119
|
+
* Callback fired when a line area item is clicked.
|
|
120
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
121
|
+
* @param {LineItemIdentifier} lineItemIdentifier The line item identifier.
|
|
122
|
+
*/
|
|
123
|
+
onItemClick: PropTypes.func,
|
|
124
|
+
/**
|
|
125
|
+
* If `true`, animations are skipped.
|
|
126
|
+
* @default false
|
|
127
|
+
*/
|
|
128
|
+
skipAnimation: PropTypes.bool,
|
|
96
129
|
/**
|
|
97
130
|
* The props used for each component slot.
|
|
98
131
|
* @default {}
|
|
@@ -13,6 +13,7 @@ import { ChartsLegend } from '../ChartsLegend';
|
|
|
13
13
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
14
14
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
15
15
|
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
16
|
+
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
/**
|
|
@@ -37,6 +38,10 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
37
38
|
dataset,
|
|
38
39
|
sx,
|
|
39
40
|
tooltip,
|
|
41
|
+
onAxisClick,
|
|
42
|
+
onAreaClick,
|
|
43
|
+
onLineClick,
|
|
44
|
+
onMarkClick,
|
|
40
45
|
axisHighlight = {
|
|
41
46
|
x: 'line'
|
|
42
47
|
},
|
|
@@ -48,7 +53,8 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
48
53
|
bottomAxis,
|
|
49
54
|
children,
|
|
50
55
|
slots,
|
|
51
|
-
slotProps
|
|
56
|
+
slotProps,
|
|
57
|
+
skipAnimation
|
|
52
58
|
} = props;
|
|
53
59
|
const id = useId();
|
|
54
60
|
const clipPathId = `${id}-clip-path`;
|
|
@@ -75,15 +81,21 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
75
81
|
colors: colors,
|
|
76
82
|
dataset: dataset,
|
|
77
83
|
sx: sx,
|
|
78
|
-
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
79
|
-
children: [/*#__PURE__*/
|
|
84
|
+
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none' && !onAxisClick,
|
|
85
|
+
children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
|
|
86
|
+
onAxisClick: onAxisClick
|
|
87
|
+
}), /*#__PURE__*/_jsxs("g", {
|
|
80
88
|
clipPath: `url(#${clipPathId})`,
|
|
81
89
|
children: [/*#__PURE__*/_jsx(AreaPlot, {
|
|
82
90
|
slots: slots,
|
|
83
|
-
slotProps: slotProps
|
|
91
|
+
slotProps: slotProps,
|
|
92
|
+
onItemClick: onAreaClick,
|
|
93
|
+
skipAnimation: skipAnimation
|
|
84
94
|
}), /*#__PURE__*/_jsx(LinePlot, {
|
|
85
95
|
slots: slots,
|
|
86
|
-
slotProps: slotProps
|
|
96
|
+
slotProps: slotProps,
|
|
97
|
+
onItemClick: onLineClick,
|
|
98
|
+
skipAnimation: skipAnimation
|
|
87
99
|
})]
|
|
88
100
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
89
101
|
topAxis: topAxis,
|
|
@@ -94,7 +106,9 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
94
106
|
slotProps: slotProps
|
|
95
107
|
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(MarkPlot, {
|
|
96
108
|
slots: slots,
|
|
97
|
-
slotProps: slotProps
|
|
109
|
+
slotProps: slotProps,
|
|
110
|
+
onItemClick: onMarkClick,
|
|
111
|
+
skipAnimation: skipAnimation
|
|
98
112
|
}), /*#__PURE__*/_jsx(LineHighlightPlot, {
|
|
99
113
|
slots: slots,
|
|
100
114
|
slotProps: slotProps
|
|
@@ -233,6 +247,16 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
233
247
|
right: PropTypes.number,
|
|
234
248
|
top: PropTypes.number
|
|
235
249
|
}),
|
|
250
|
+
onAreaClick: PropTypes.func,
|
|
251
|
+
/**
|
|
252
|
+
* The function called for onClick events.
|
|
253
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
254
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
255
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
256
|
+
*/
|
|
257
|
+
onAxisClick: PropTypes.func,
|
|
258
|
+
onLineClick: PropTypes.func,
|
|
259
|
+
onMarkClick: PropTypes.func,
|
|
236
260
|
/**
|
|
237
261
|
* Indicate which axis to display the right of the charts.
|
|
238
262
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -261,6 +285,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
261
285
|
tickSize: PropTypes.number
|
|
262
286
|
}), PropTypes.string]),
|
|
263
287
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
288
|
+
/**
|
|
289
|
+
* If `true`, animations are skipped.
|
|
290
|
+
* @default false
|
|
291
|
+
*/
|
|
292
|
+
skipAnimation: PropTypes.bool,
|
|
264
293
|
/**
|
|
265
294
|
* The props used for each component slot.
|
|
266
295
|
* @default {}
|