@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
|
@@ -38,6 +38,7 @@ var ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, re
|
|
|
38
38
|
leftAxis = props.leftAxis,
|
|
39
39
|
rightAxis = props.rightAxis,
|
|
40
40
|
bottomAxis = props.bottomAxis,
|
|
41
|
+
onItemClick = props.onItemClick,
|
|
41
42
|
children = props.children,
|
|
42
43
|
slots = props.slots,
|
|
43
44
|
slotProps = props.slotProps;
|
|
@@ -56,7 +57,8 @@ var ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, re
|
|
|
56
57
|
yAxis: yAxis,
|
|
57
58
|
sx: sx,
|
|
58
59
|
children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
|
|
59
|
-
voronoiMaxRadius: voronoiMaxRadius
|
|
60
|
+
voronoiMaxRadius: voronoiMaxRadius,
|
|
61
|
+
onItemClick: onItemClick
|
|
60
62
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
61
63
|
topAxis: topAxis,
|
|
62
64
|
leftAxis: leftAxis,
|
|
@@ -66,7 +68,8 @@ var ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, re
|
|
|
66
68
|
slotProps: slotProps
|
|
67
69
|
}), /*#__PURE__*/_jsx(ScatterPlot, {
|
|
68
70
|
slots: slots,
|
|
69
|
-
slotProps: slotProps
|
|
71
|
+
slotProps: slotProps,
|
|
72
|
+
onItemClick: disableVoronoi ? onItemClick : undefined
|
|
70
73
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
71
74
|
slots: slots,
|
|
72
75
|
slotProps: slotProps
|
|
@@ -195,6 +198,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
195
198
|
right: PropTypes.number,
|
|
196
199
|
top: PropTypes.number
|
|
197
200
|
}),
|
|
201
|
+
/**
|
|
202
|
+
* Callback fired when clicking on a scatter item.
|
|
203
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element if using Voronoi cells. Or the Mouse event from the scatter element, when `disableVoronoi=true`.
|
|
204
|
+
* @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
|
|
205
|
+
*/
|
|
206
|
+
onItemClick: PropTypes.func,
|
|
198
207
|
/**
|
|
199
208
|
* Indicate which axis to display the right of the charts.
|
|
200
209
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -18,7 +18,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
18
18
|
function ScatterPlot(props) {
|
|
19
19
|
var _slots$scatter;
|
|
20
20
|
var slots = props.slots,
|
|
21
|
-
slotProps = props.slotProps
|
|
21
|
+
slotProps = props.slotProps,
|
|
22
|
+
onItemClick = props.onItemClick;
|
|
22
23
|
var seriesData = React.useContext(SeriesContext).scatter;
|
|
23
24
|
var axisData = React.useContext(CartesianContext);
|
|
24
25
|
if (seriesData === undefined) {
|
|
@@ -48,7 +49,8 @@ function ScatterPlot(props) {
|
|
|
48
49
|
yScale: yScale,
|
|
49
50
|
color: color,
|
|
50
51
|
markerSize: markerSize != null ? markerSize : 4,
|
|
51
|
-
series: series[seriesId]
|
|
52
|
+
series: series[seriesId],
|
|
53
|
+
onItemClick: onItemClick
|
|
52
54
|
}, slotProps == null ? void 0 : slotProps.scatter), id);
|
|
53
55
|
})
|
|
54
56
|
});
|
|
@@ -58,6 +60,12 @@ process.env.NODE_ENV !== "production" ? ScatterPlot.propTypes = {
|
|
|
58
60
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
59
61
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
60
62
|
// ----------------------------------------------------------------------
|
|
63
|
+
/**
|
|
64
|
+
* Callback fired when clicking on a scatter item.
|
|
65
|
+
* @param {MouseEvent} event Mouse event recorded on the `<svg/>` element.
|
|
66
|
+
* @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
|
|
67
|
+
*/
|
|
68
|
+
onItemClick: PropTypes.func,
|
|
61
69
|
/**
|
|
62
70
|
* The props used for each component slot.
|
|
63
71
|
* @default {}
|
|
@@ -92,9 +92,11 @@ var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props
|
|
|
92
92
|
}
|
|
93
93
|
}), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
94
94
|
children: [/*#__PURE__*/_jsx(AreaPlot, {
|
|
95
|
+
skipAnimation: true,
|
|
95
96
|
slots: slots,
|
|
96
97
|
slotProps: slotProps
|
|
97
98
|
}), /*#__PURE__*/_jsx(LinePlot, {
|
|
99
|
+
skipAnimation: true,
|
|
98
100
|
slots: slots,
|
|
99
101
|
slotProps: slotProps
|
|
100
102
|
}), /*#__PURE__*/_jsx(LineHighlightPlot, {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
4
|
+
import useId from '@mui/utils/useId';
|
|
3
5
|
import useChartDimensions from '../hooks/useChartDimensions';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -12,7 +14,8 @@ export var DrawingContext = /*#__PURE__*/React.createContext({
|
|
|
12
14
|
bottom: 0,
|
|
13
15
|
right: 0,
|
|
14
16
|
height: 300,
|
|
15
|
-
width: 400
|
|
17
|
+
width: 400,
|
|
18
|
+
chartId: ''
|
|
16
19
|
});
|
|
17
20
|
export var SVGContext = /*#__PURE__*/React.createContext({
|
|
18
21
|
current: null
|
|
@@ -30,10 +33,16 @@ function DrawingProvider(props) {
|
|
|
30
33
|
svgRef = props.svgRef,
|
|
31
34
|
children = props.children;
|
|
32
35
|
var drawingArea = useChartDimensions(width, height, margin);
|
|
36
|
+
var chartId = useId();
|
|
37
|
+
var value = React.useMemo(function () {
|
|
38
|
+
return _extends({
|
|
39
|
+
chartId: chartId != null ? chartId : ''
|
|
40
|
+
}, drawingArea);
|
|
41
|
+
}, [chartId, drawingArea]);
|
|
33
42
|
return /*#__PURE__*/_jsx(SVGContext.Provider, {
|
|
34
43
|
value: svgRef,
|
|
35
44
|
children: /*#__PURE__*/_jsx(DrawingContext.Provider, {
|
|
36
|
-
value:
|
|
45
|
+
value: value,
|
|
37
46
|
children: children
|
|
38
47
|
})
|
|
39
48
|
});
|
|
@@ -5,13 +5,17 @@ export function useDrawingArea() {
|
|
|
5
5
|
left = _React$useContext.left,
|
|
6
6
|
top = _React$useContext.top,
|
|
7
7
|
width = _React$useContext.width,
|
|
8
|
-
height = _React$useContext.height
|
|
8
|
+
height = _React$useContext.height,
|
|
9
|
+
bottom = _React$useContext.bottom,
|
|
10
|
+
right = _React$useContext.right;
|
|
9
11
|
return React.useMemo(function () {
|
|
10
12
|
return {
|
|
11
13
|
left: left,
|
|
12
14
|
top: top,
|
|
13
15
|
width: width,
|
|
14
|
-
height: height
|
|
16
|
+
height: height,
|
|
17
|
+
bottom: bottom,
|
|
18
|
+
right: right
|
|
15
19
|
};
|
|
16
|
-
}, [height, left, top, width]);
|
|
20
|
+
}, [height, left, top, width, bottom, right]);
|
|
17
21
|
}
|
package/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v7.0.0-beta.
|
|
2
|
+
* @mui/x-charts v7.0.0-beta.1
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -20,6 +20,7 @@ export * from './ChartsTooltip';
|
|
|
20
20
|
export * from './ChartsLegend';
|
|
21
21
|
export * from './ChartsAxisHighlight';
|
|
22
22
|
export * from './ChartsVoronoiHandler';
|
|
23
|
+
export * from './ChartsOnAxisClickHandler';
|
|
23
24
|
export * from './BarChart';
|
|
24
25
|
export * from './LineChart';
|
|
25
26
|
export * from './PieChart';
|
|
@@ -15,7 +15,7 @@ export function getMinXTranslation(width, height) {
|
|
|
15
15
|
if (process.env.NODE_ENV !== 'production') {
|
|
16
16
|
if (!warnedOnce && angle > 90 && angle < -90) {
|
|
17
17
|
warnedOnce = true;
|
|
18
|
-
console.warn(["MUI X: It seems you applied an angle larger than 90\xB0 or smaller than -90\xB0 to an axis text.", "This could cause some text overlapping.", "If you encounter a use case where it's needed, please open an issue."].join('\n'));
|
|
18
|
+
console.warn(["MUI X Charts: It seems you applied an angle larger than 90\xB0 or smaller than -90\xB0 to an axis text.", "This could cause some text overlapping.", "If you encounter a use case where it's needed, please open an issue."].join('\n'));
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
var standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { interpolateString } from 'd3-interpolate';
|
|
3
|
+
import { useSpring, to } from '@react-spring/web';
|
|
4
|
+
function usePrevious(value) {
|
|
5
|
+
var ref = React.useRef(null);
|
|
6
|
+
React.useEffect(function () {
|
|
7
|
+
ref.current = value;
|
|
8
|
+
}, [value]);
|
|
9
|
+
return ref.current;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Taken from Nivo
|
|
13
|
+
export var useAnimatedPath = function useAnimatedPath(path, skipAnimation) {
|
|
14
|
+
var previousPath = usePrevious(path);
|
|
15
|
+
var interpolator = React.useMemo(function () {
|
|
16
|
+
return previousPath ? interpolateString(previousPath, path) : function () {
|
|
17
|
+
return path;
|
|
18
|
+
};
|
|
19
|
+
}, [previousPath, path]);
|
|
20
|
+
var _useSpring = useSpring({
|
|
21
|
+
from: {
|
|
22
|
+
value: 0
|
|
23
|
+
},
|
|
24
|
+
to: {
|
|
25
|
+
value: 1
|
|
26
|
+
},
|
|
27
|
+
reset: true,
|
|
28
|
+
immediate: skipAnimation
|
|
29
|
+
}),
|
|
30
|
+
value = _useSpring.value;
|
|
31
|
+
return to([value], interpolator);
|
|
32
|
+
};
|
|
@@ -42,4 +42,11 @@ export function getPercentageValue(value, refValue) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
throw Error("MUI-Charts: Received an unknown value \"".concat(value, "\". It should be a number, or a string with a percentage value."));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Remove spaces to have viable ids
|
|
49
|
+
*/
|
|
50
|
+
export function cleanId(id) {
|
|
51
|
+
return id.replace(' ', '_');
|
|
45
52
|
}
|
|
@@ -10,6 +10,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
|
|
|
10
10
|
import { ChartsLegend } from '../ChartsLegend';
|
|
11
11
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
12
12
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
13
|
+
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
16
|
/**
|
|
@@ -43,6 +44,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
43
44
|
rightAxis,
|
|
44
45
|
bottomAxis,
|
|
45
46
|
skipAnimation,
|
|
47
|
+
onItemClick,
|
|
48
|
+
onAxisClick,
|
|
46
49
|
children,
|
|
47
50
|
slots,
|
|
48
51
|
slotProps
|
|
@@ -80,13 +83,16 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
80
83
|
colors: colors,
|
|
81
84
|
dataset: dataset,
|
|
82
85
|
sx: sx,
|
|
83
|
-
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
84
|
-
children: [/*#__PURE__*/_jsx(
|
|
86
|
+
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
|
|
87
|
+
children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
|
|
88
|
+
onAxisClick: onAxisClick
|
|
89
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
85
90
|
clipPath: `url(#${clipPathId})`,
|
|
86
91
|
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
87
92
|
slots: slots,
|
|
88
93
|
slotProps: slotProps,
|
|
89
|
-
skipAnimation: skipAnimation
|
|
94
|
+
skipAnimation: skipAnimation,
|
|
95
|
+
onItemClick: onItemClick
|
|
90
96
|
})
|
|
91
97
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
92
98
|
topAxis: topAxis,
|
|
@@ -226,6 +232,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
226
232
|
right: PropTypes.number,
|
|
227
233
|
top: PropTypes.number
|
|
228
234
|
}),
|
|
235
|
+
/**
|
|
236
|
+
* The function called for onClick events.
|
|
237
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
238
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
239
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
240
|
+
*/
|
|
241
|
+
onAxisClick: PropTypes.func,
|
|
242
|
+
/**
|
|
243
|
+
* Callback fired when a bar item is clicked.
|
|
244
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
245
|
+
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
246
|
+
*/
|
|
247
|
+
onItemClick: PropTypes.func,
|
|
229
248
|
/**
|
|
230
249
|
* Indicate which axis to display the right of the charts.
|
|
231
250
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -255,7 +274,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
255
274
|
}), PropTypes.string]),
|
|
256
275
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
257
276
|
/**
|
|
258
|
-
* If `true`, animations are
|
|
277
|
+
* If `true`, animations are skipped.
|
|
259
278
|
* @default false
|
|
260
279
|
*/
|
|
261
280
|
skipAnimation: PropTypes.bool,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style"];
|
|
3
|
+
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style", "onClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
@@ -49,7 +49,8 @@ function BarElement(props) {
|
|
|
49
49
|
highlightScope,
|
|
50
50
|
slots,
|
|
51
51
|
slotProps,
|
|
52
|
-
style
|
|
52
|
+
style,
|
|
53
|
+
onClick
|
|
53
54
|
} = props,
|
|
54
55
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
55
56
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -85,7 +86,9 @@ function BarElement(props) {
|
|
|
85
86
|
dataIndex
|
|
86
87
|
}), {
|
|
87
88
|
style,
|
|
88
|
-
className: classes.root
|
|
89
|
+
className: classes.root,
|
|
90
|
+
onClick,
|
|
91
|
+
cursor: onClick ? 'pointer' : 'unset'
|
|
89
92
|
}),
|
|
90
93
|
ownerState
|
|
91
94
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["skipAnimation"];
|
|
3
|
+
const _excluded = ["skipAnimation", "onItemClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { useTransition } from '@react-spring/web';
|
|
@@ -38,7 +38,7 @@ function getBandSize({
|
|
|
38
38
|
offset
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const useAggregatedData = () => {
|
|
42
42
|
const seriesData = React.useContext(SeriesContext).bar ?? {
|
|
43
43
|
series: {},
|
|
44
44
|
stackingGroups: [],
|
|
@@ -166,9 +166,10 @@ const getInStyle = ({
|
|
|
166
166
|
* - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
|
|
167
167
|
*/
|
|
168
168
|
function BarPlot(props) {
|
|
169
|
-
const completedData =
|
|
169
|
+
const completedData = useAggregatedData();
|
|
170
170
|
const {
|
|
171
|
-
skipAnimation
|
|
171
|
+
skipAnimation,
|
|
172
|
+
onItemClick
|
|
172
173
|
} = props,
|
|
173
174
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
174
175
|
const transition = useTransition(completedData, {
|
|
@@ -191,6 +192,13 @@ function BarPlot(props) {
|
|
|
191
192
|
highlightScope: highlightScope,
|
|
192
193
|
color: color
|
|
193
194
|
}, other, {
|
|
195
|
+
onClick: onItemClick && (event => {
|
|
196
|
+
onItemClick(event, {
|
|
197
|
+
type: 'bar',
|
|
198
|
+
seriesId,
|
|
199
|
+
dataIndex
|
|
200
|
+
});
|
|
201
|
+
}),
|
|
194
202
|
style: style
|
|
195
203
|
})))
|
|
196
204
|
});
|
|
@@ -201,7 +209,13 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
|
|
|
201
209
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
202
210
|
// ----------------------------------------------------------------------
|
|
203
211
|
/**
|
|
204
|
-
*
|
|
212
|
+
* Callback fired when a bar item is clicked.
|
|
213
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
214
|
+
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
215
|
+
*/
|
|
216
|
+
onItemClick: PropTypes.func,
|
|
217
|
+
/**
|
|
218
|
+
* If `true`, animations are skipped.
|
|
205
219
|
* @default false
|
|
206
220
|
*/
|
|
207
221
|
skipAnimation: PropTypes.bool,
|
|
@@ -65,7 +65,7 @@ const formatter = (params, dataset) => {
|
|
|
65
65
|
return {
|
|
66
66
|
seriesOrder,
|
|
67
67
|
stackingGroups,
|
|
68
|
-
series: defaultizeValueFormatter(completedSeries, v => v
|
|
68
|
+
series: defaultizeValueFormatter(completedSeries, v => v == null ? '' : v.toLocaleString())
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
export default formatter;
|
|
@@ -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
|
+
const {
|
|
10
|
+
onAxisClick
|
|
11
|
+
} = props;
|
|
12
|
+
const svgRef = React.useContext(SVGContext);
|
|
13
|
+
const series = React.useContext(SeriesContext);
|
|
14
|
+
const {
|
|
15
|
+
axis
|
|
16
|
+
} = React.useContext(InteractionContext);
|
|
17
|
+
const {
|
|
18
|
+
xAxisIds,
|
|
19
|
+
xAxis,
|
|
20
|
+
yAxisIds,
|
|
21
|
+
yAxis
|
|
22
|
+
} = React.useContext(CartesianContext);
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
const element = svgRef.current;
|
|
25
|
+
if (element === null || !onAxisClick) {
|
|
26
|
+
return () => {};
|
|
27
|
+
}
|
|
28
|
+
const handleMouseClick = event => {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
const isXaxis = (axis.x && axis.x.index) !== undefined;
|
|
31
|
+
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
32
|
+
const dataIndex = isXaxis ? axis.x && axis.x.index : axis.y && axis.y.index;
|
|
33
|
+
if (dataIndex == null) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const seriesValues = {};
|
|
37
|
+
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
38
|
+
series[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
39
|
+
const seriesItem = series[seriesType].series[seriesId];
|
|
40
|
+
const axisKey = isXaxis ? seriesItem.xAxisKey : seriesItem.yAxisKey;
|
|
41
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
42
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
const axisValue = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data?.[dataIndex];
|
|
47
|
+
onAxisClick(event, {
|
|
48
|
+
dataIndex,
|
|
49
|
+
axisValue,
|
|
50
|
+
seriesValues
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
element.addEventListener('click', handleMouseClick);
|
|
54
|
+
return () => {
|
|
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';
|
|
@@ -69,7 +69,7 @@ function ChartsXReferenceLine(props) {
|
|
|
69
69
|
if (process.env.NODE_ENV !== 'production') {
|
|
70
70
|
if (!warnedOnce) {
|
|
71
71
|
warnedOnce = true;
|
|
72
|
-
console.error(`MUI X: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
|
|
72
|
+
console.error(`MUI X Charts: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
return null;
|
|
@@ -69,7 +69,7 @@ function ChartsYReferenceLine(props) {
|
|
|
69
69
|
if (process.env.NODE_ENV !== 'production') {
|
|
70
70
|
if (!warnedOnce) {
|
|
71
71
|
warnedOnce = true;
|
|
72
|
-
console.error(`MUI X: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
|
|
72
|
+
console.error(`MUI X Charts: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
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
|
const {
|
|
@@ -27,7 +28,7 @@ function ChartsAxisTooltipContent(props) {
|
|
|
27
28
|
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
28
29
|
const relevantSeries = React.useMemo(() => {
|
|
29
30
|
const rep = [];
|
|
30
|
-
Object.keys(series).filter(
|
|
31
|
+
Object.keys(series).filter(isCartesianSeriesType).forEach(seriesType => {
|
|
31
32
|
series[seriesType].seriesOrder.forEach(seriesId => {
|
|
32
33
|
const item = series[seriesType].series[seriesId];
|
|
33
34
|
const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
|
|
@@ -66,11 +67,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
|
|
|
66
67
|
axisData: PropTypes.shape({
|
|
67
68
|
x: PropTypes.shape({
|
|
68
69
|
index: PropTypes.number,
|
|
69
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
70
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
70
71
|
}),
|
|
71
72
|
y: PropTypes.shape({
|
|
72
73
|
index: PropTypes.number,
|
|
73
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
74
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
74
75
|
})
|
|
75
76
|
}).isRequired,
|
|
76
77
|
classes: PropTypes.object.isRequired,
|
|
@@ -80,11 +81,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
|
|
|
80
81
|
axisData: PropTypes.shape({
|
|
81
82
|
x: PropTypes.shape({
|
|
82
83
|
index: PropTypes.number,
|
|
83
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
84
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
84
85
|
}),
|
|
85
86
|
y: PropTypes.shape({
|
|
86
87
|
index: PropTypes.number,
|
|
87
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
88
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
88
89
|
})
|
|
89
90
|
}),
|
|
90
91
|
axisValue: PropTypes.any,
|
|
@@ -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 } 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) {
|
|
@@ -33,14 +34,15 @@ function DefaultChartsAxisTooltipContent(props) {
|
|
|
33
34
|
})
|
|
34
35
|
})
|
|
35
36
|
}), /*#__PURE__*/_jsx("tbody", {
|
|
36
|
-
children: series.map(({
|
|
37
|
+
children: series.filter(isCartesianSeries).map(({
|
|
37
38
|
color,
|
|
38
39
|
id,
|
|
39
40
|
label,
|
|
40
41
|
valueFormatter,
|
|
41
42
|
data
|
|
42
43
|
}) => {
|
|
43
|
-
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
const formattedValue = valueFormatter(data[dataIndex] ?? null);
|
|
44
46
|
if (formattedValue == null) {
|
|
45
47
|
return null;
|
|
46
48
|
}
|
|
@@ -87,11 +89,11 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
|
|
|
87
89
|
axisData: PropTypes.shape({
|
|
88
90
|
x: PropTypes.shape({
|
|
89
91
|
index: PropTypes.number,
|
|
90
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
92
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
91
93
|
}),
|
|
92
94
|
y: PropTypes.shape({
|
|
93
95
|
index: PropTypes.number,
|
|
94
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
96
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
95
97
|
})
|
|
96
98
|
}).isRequired,
|
|
97
99
|
/**
|
|
@@ -78,4 +78,10 @@ export function getTooltipHasData(trigger, displayedData) {
|
|
|
78
78
|
const hasAxisXData = displayedData.x !== null;
|
|
79
79
|
const hasAxisYData = displayedData.y !== null;
|
|
80
80
|
return hasAxisXData || hasAxisYData;
|
|
81
|
+
}
|
|
82
|
+
export function isCartesianSeriesType(seriesType) {
|
|
83
|
+
return ['bar', 'line', 'scatter'].includes(seriesType);
|
|
84
|
+
}
|
|
85
|
+
export function isCartesianSeries(series) {
|
|
86
|
+
return isCartesianSeriesType(series.type);
|
|
81
87
|
}
|