@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
|
@@ -6,11 +6,11 @@ export interface InteractionProviderProps {
|
|
|
6
6
|
export type ItemInteractionData<T extends ChartSeriesType> = ChartItemIdentifier<T>;
|
|
7
7
|
export type AxisInteractionData = {
|
|
8
8
|
x: null | {
|
|
9
|
-
value: number | Date;
|
|
9
|
+
value: number | Date | string;
|
|
10
10
|
index?: number;
|
|
11
11
|
};
|
|
12
12
|
y: null | {
|
|
13
|
-
value: number | Date;
|
|
13
|
+
value: number | Date | string;
|
|
14
14
|
index?: number;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
@@ -19,7 +19,7 @@ type InteractionActions<T extends ChartSeriesType = ChartSeriesType> = {
|
|
|
19
19
|
data: ItemInteractionData<T>;
|
|
20
20
|
} | {
|
|
21
21
|
type: 'leaveItem';
|
|
22
|
-
data: ItemInteractionData<T
|
|
22
|
+
data: Partial<ItemInteractionData<T>>;
|
|
23
23
|
} | {
|
|
24
24
|
type: 'exitChart';
|
|
25
25
|
} | {
|
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -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
|
|
@@ -83,13 +86,16 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
83
86
|
colors: colors,
|
|
84
87
|
dataset: dataset,
|
|
85
88
|
sx: sx,
|
|
86
|
-
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
87
|
-
children: [/*#__PURE__*/_jsx(
|
|
89
|
+
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none' && !onAxisClick,
|
|
90
|
+
children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
|
|
91
|
+
onAxisClick: onAxisClick
|
|
92
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
88
93
|
clipPath: `url(#${clipPathId})`,
|
|
89
94
|
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
90
95
|
slots: slots,
|
|
91
96
|
slotProps: slotProps,
|
|
92
|
-
skipAnimation: skipAnimation
|
|
97
|
+
skipAnimation: skipAnimation,
|
|
98
|
+
onItemClick: onItemClick
|
|
93
99
|
})
|
|
94
100
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
95
101
|
topAxis: topAxis,
|
|
@@ -229,6 +235,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
229
235
|
right: PropTypes.number,
|
|
230
236
|
top: PropTypes.number
|
|
231
237
|
}),
|
|
238
|
+
/**
|
|
239
|
+
* The function called for onClick events.
|
|
240
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
241
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
242
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
243
|
+
*/
|
|
244
|
+
onAxisClick: PropTypes.func,
|
|
245
|
+
/**
|
|
246
|
+
* Callback fired when a bar item is clicked.
|
|
247
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
248
|
+
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
249
|
+
*/
|
|
250
|
+
onItemClick: PropTypes.func,
|
|
232
251
|
/**
|
|
233
252
|
* Indicate which axis to display the right of the charts.
|
|
234
253
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -258,7 +277,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
258
277
|
}), PropTypes.string]),
|
|
259
278
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
260
279
|
/**
|
|
261
|
-
* If `true`, animations are
|
|
280
|
+
* If `true`, animations are skipped.
|
|
262
281
|
* @default false
|
|
263
282
|
*/
|
|
264
283
|
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';
|
|
@@ -50,7 +50,8 @@ function BarElement(props) {
|
|
|
50
50
|
highlightScope,
|
|
51
51
|
slots,
|
|
52
52
|
slotProps,
|
|
53
|
-
style
|
|
53
|
+
style,
|
|
54
|
+
onClick
|
|
54
55
|
} = props,
|
|
55
56
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
56
57
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -86,7 +87,9 @@ function BarElement(props) {
|
|
|
86
87
|
dataIndex
|
|
87
88
|
}), {
|
|
88
89
|
style,
|
|
89
|
-
className: classes.root
|
|
90
|
+
className: classes.root,
|
|
91
|
+
onClick,
|
|
92
|
+
cursor: onClick ? 'pointer' : 'unset'
|
|
90
93
|
}),
|
|
91
94
|
ownerState
|
|
92
95
|
});
|
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -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
|
var _React$useContext$bar;
|
|
43
43
|
const seriesData = (_React$useContext$bar = React.useContext(SeriesContext).bar) != null ? _React$useContext$bar : {
|
|
44
44
|
series: {},
|
|
@@ -169,9 +169,10 @@ const getInStyle = ({
|
|
|
169
169
|
* - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
|
|
170
170
|
*/
|
|
171
171
|
function BarPlot(props) {
|
|
172
|
-
const completedData =
|
|
172
|
+
const completedData = useAggregatedData();
|
|
173
173
|
const {
|
|
174
|
-
skipAnimation
|
|
174
|
+
skipAnimation,
|
|
175
|
+
onItemClick
|
|
175
176
|
} = props,
|
|
176
177
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
177
178
|
const transition = useTransition(completedData, {
|
|
@@ -194,6 +195,13 @@ function BarPlot(props) {
|
|
|
194
195
|
highlightScope: highlightScope,
|
|
195
196
|
color: color
|
|
196
197
|
}, other, {
|
|
198
|
+
onClick: onItemClick && (event => {
|
|
199
|
+
onItemClick(event, {
|
|
200
|
+
type: 'bar',
|
|
201
|
+
seriesId,
|
|
202
|
+
dataIndex
|
|
203
|
+
});
|
|
204
|
+
}),
|
|
197
205
|
style: style
|
|
198
206
|
})))
|
|
199
207
|
});
|
|
@@ -204,7 +212,13 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
|
|
|
204
212
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
205
213
|
// ----------------------------------------------------------------------
|
|
206
214
|
/**
|
|
207
|
-
*
|
|
215
|
+
* Callback fired when a bar item is clicked.
|
|
216
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
217
|
+
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
218
|
+
*/
|
|
219
|
+
onItemClick: PropTypes.func,
|
|
220
|
+
/**
|
|
221
|
+
* If `true`, animations are skipped.
|
|
208
222
|
* @default false
|
|
209
223
|
*/
|
|
210
224
|
skipAnimation: PropTypes.bool,
|
|
@@ -69,7 +69,7 @@ const formatter = (params, dataset) => {
|
|
|
69
69
|
return {
|
|
70
70
|
seriesOrder,
|
|
71
71
|
stackingGroups,
|
|
72
|
-
series: defaultizeValueFormatter(completedSeries, v => v
|
|
72
|
+
series: defaultizeValueFormatter(completedSeries, v => v == null ? '' : v.toLocaleString())
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
export default formatter;
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
var _USED_AXIS_ID$data;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
const isXaxis = (axis.x && axis.x.index) !== undefined;
|
|
32
|
+
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
33
|
+
const dataIndex = isXaxis ? axis.x && axis.x.index : axis.y && axis.y.index;
|
|
34
|
+
if (dataIndex == null) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const seriesValues = {};
|
|
38
|
+
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
39
|
+
var _series$seriesType;
|
|
40
|
+
(_series$seriesType = series[seriesType]) == null || _series$seriesType.seriesOrder.forEach(seriesId => {
|
|
41
|
+
const seriesItem = series[seriesType].series[seriesId];
|
|
42
|
+
const axisKey = isXaxis ? seriesItem.xAxisKey : seriesItem.yAxisKey;
|
|
43
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
44
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const axisValue = (_USED_AXIS_ID$data = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data) == null ? void 0 : _USED_AXIS_ID$data[dataIndex];
|
|
49
|
+
onAxisClick(event, {
|
|
50
|
+
dataIndex,
|
|
51
|
+
axisValue,
|
|
52
|
+
seriesValues
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
element.addEventListener('click', handleMouseClick);
|
|
56
|
+
return () => {
|
|
57
|
+
element.removeEventListener('click', handleMouseClick);
|
|
58
|
+
};
|
|
59
|
+
}, [axis.x, axis.y, onAxisClick, series, svgRef, xAxis, xAxisIds, yAxis, yAxisIds]);
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
62
|
+
return /*#__PURE__*/_jsx(React.Fragment, {});
|
|
63
|
+
}
|
|
64
|
+
process.env.NODE_ENV !== "production" ? ChartsOnAxisClickHandler.propTypes = {
|
|
65
|
+
// ----------------------------- Warning --------------------------------
|
|
66
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
67
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
68
|
+
// ----------------------------------------------------------------------
|
|
69
|
+
/**
|
|
70
|
+
* The function called for onClick events.
|
|
71
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
72
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
73
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
74
|
+
*/
|
|
75
|
+
onAxisClick: PropTypes.func
|
|
76
|
+
} : void 0;
|
|
77
|
+
export { ChartsOnAxisClickHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChartsOnAxisClickHandler';
|
|
@@ -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 ${x} does not exist in the data of x axis with id ${axisId}.`);
|
|
73
|
+
console.error(`MUI X Charts: the value ${x} does not exist in the data of x axis with id ${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 ${y} does not exist in the data of y axis with id ${axisId}.`);
|
|
73
|
+
console.error(`MUI X Charts: the value ${y} does not exist in the data of y axis with id ${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
|
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) {
|
|
@@ -34,14 +35,16 @@ function DefaultChartsAxisTooltipContent(props) {
|
|
|
34
35
|
})
|
|
35
36
|
})
|
|
36
37
|
}), /*#__PURE__*/_jsx("tbody", {
|
|
37
|
-
children: series.map(({
|
|
38
|
+
children: series.filter(isCartesianSeries).map(({
|
|
38
39
|
color,
|
|
39
40
|
id,
|
|
40
41
|
label,
|
|
41
42
|
valueFormatter,
|
|
42
43
|
data
|
|
43
44
|
}) => {
|
|
44
|
-
|
|
45
|
+
var _data$dataIndex;
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
const formattedValue = valueFormatter((_data$dataIndex = data[dataIndex]) != null ? _data$dataIndex : null);
|
|
45
48
|
if (formattedValue == null) {
|
|
46
49
|
return null;
|
|
47
50
|
}
|
|
@@ -88,11 +91,11 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
|
|
|
88
91
|
axisData: PropTypes.shape({
|
|
89
92
|
x: PropTypes.shape({
|
|
90
93
|
index: PropTypes.number,
|
|
91
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
94
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
92
95
|
}),
|
|
93
96
|
y: PropTypes.shape({
|
|
94
97
|
index: PropTypes.number,
|
|
95
|
-
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
98
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
96
99
|
})
|
|
97
100
|
}).isRequired,
|
|
98
101
|
/**
|
|
@@ -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
|
}
|
|
@@ -12,7 +12,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
12
12
|
function ChartsVoronoiHandler(props) {
|
|
13
13
|
var _React$useContext$sca;
|
|
14
14
|
const {
|
|
15
|
-
voronoiMaxRadius
|
|
15
|
+
voronoiMaxRadius,
|
|
16
|
+
onItemClick
|
|
16
17
|
} = props;
|
|
17
18
|
const svgRef = React.useContext(SVGContext);
|
|
18
19
|
const {
|
|
@@ -50,6 +51,8 @@ function ChartsVoronoiHandler(props) {
|
|
|
50
51
|
};
|
|
51
52
|
}, [dispatch]);
|
|
52
53
|
useEnhancedEffect(() => {
|
|
54
|
+
// This effect generate and store the Delaunay object that's used to map coordinate to closest point.
|
|
55
|
+
|
|
53
56
|
if (seriesOrder === undefined || series === undefined) {
|
|
54
57
|
// If there is no scatter chart series
|
|
55
58
|
return;
|
|
@@ -83,81 +86,126 @@ function ChartsVoronoiHandler(props) {
|
|
|
83
86
|
if (element === null) {
|
|
84
87
|
return undefined;
|
|
85
88
|
}
|
|
86
|
-
const handleMouseOut = () => {
|
|
87
|
-
dispatch({
|
|
88
|
-
type: 'exitChart'
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
89
|
|
|
92
90
|
// TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
|
|
93
|
-
|
|
91
|
+
function getClosestPoint(event) {
|
|
94
92
|
var _voronoiRef$current$d;
|
|
95
93
|
// Get mouse coordinate in global SVG space
|
|
96
94
|
const svgPoint = getSVGPoint(svgRef.current, event);
|
|
97
95
|
const outsideX = svgPoint.x < left || svgPoint.x > left + width;
|
|
98
96
|
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
99
97
|
if (outsideX || outsideY) {
|
|
100
|
-
|
|
101
|
-
type: 'exitChart'
|
|
102
|
-
});
|
|
103
|
-
return;
|
|
98
|
+
return 'outside-chart';
|
|
104
99
|
}
|
|
105
100
|
if (!voronoiRef.current.delauney) {
|
|
106
|
-
return;
|
|
101
|
+
return 'no-point-found';
|
|
107
102
|
}
|
|
108
103
|
const closestPointIndex = (_voronoiRef$current$d = voronoiRef.current.delauney) == null ? void 0 : _voronoiRef$current$d.find(svgPoint.x, svgPoint.y);
|
|
109
|
-
if (closestPointIndex
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return
|
|
115
|
-
});
|
|
116
|
-
if (seriesId === undefined) {
|
|
117
|
-
return;
|
|
104
|
+
if (closestPointIndex === undefined) {
|
|
105
|
+
return 'no-point-found';
|
|
106
|
+
}
|
|
107
|
+
const seriesId = Object.keys(voronoiRef.current).find(id => {
|
|
108
|
+
if (id === 'delauney') {
|
|
109
|
+
return false;
|
|
118
110
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
111
|
+
return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
|
|
112
|
+
});
|
|
113
|
+
if (seriesId === undefined) {
|
|
114
|
+
return 'no-point-found';
|
|
115
|
+
}
|
|
116
|
+
const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
|
|
117
|
+
if (voronoiMaxRadius !== undefined) {
|
|
118
|
+
const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
|
|
119
|
+
const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
|
|
120
|
+
const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
|
|
121
|
+
if (dist2 > voronoiMaxRadius ** 2) {
|
|
122
|
+
// The closest point is too far to be considered.
|
|
123
|
+
return 'outside-voronoi-max-radius';
|
|
136
124
|
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
seriesId,
|
|
128
|
+
dataIndex
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const handleMouseOut = () => {
|
|
132
|
+
dispatch({
|
|
133
|
+
type: 'exitChart'
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
const handleMouseMove = event => {
|
|
137
|
+
const closestPoint = getClosestPoint(event);
|
|
138
|
+
if (closestPoint === 'outside-chart') {
|
|
139
|
+
dispatch({
|
|
140
|
+
type: 'exitChart'
|
|
141
|
+
});
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (closestPoint === 'outside-voronoi-max-radius' || closestPoint === 'no-point-found') {
|
|
137
145
|
dispatch({
|
|
138
|
-
type: '
|
|
146
|
+
type: 'leaveItem',
|
|
139
147
|
data: {
|
|
140
|
-
type: 'scatter'
|
|
141
|
-
seriesId,
|
|
142
|
-
dataIndex
|
|
148
|
+
type: 'scatter'
|
|
143
149
|
}
|
|
144
150
|
});
|
|
151
|
+
return;
|
|
145
152
|
}
|
|
153
|
+
const {
|
|
154
|
+
seriesId,
|
|
155
|
+
dataIndex
|
|
156
|
+
} = closestPoint;
|
|
157
|
+
dispatch({
|
|
158
|
+
type: 'enterItem',
|
|
159
|
+
data: {
|
|
160
|
+
type: 'scatter',
|
|
161
|
+
seriesId,
|
|
162
|
+
dataIndex
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
const handleMouseClick = event => {
|
|
167
|
+
if (!onItemClick) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const closestPoint = getClosestPoint(event);
|
|
171
|
+
if (typeof closestPoint === 'string') {
|
|
172
|
+
// No point fond for any reason
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const {
|
|
176
|
+
seriesId,
|
|
177
|
+
dataIndex
|
|
178
|
+
} = closestPoint;
|
|
179
|
+
onItemClick(event, {
|
|
180
|
+
type: 'scatter',
|
|
181
|
+
seriesId,
|
|
182
|
+
dataIndex
|
|
183
|
+
});
|
|
146
184
|
};
|
|
147
185
|
element.addEventListener('mouseout', handleMouseOut);
|
|
148
186
|
element.addEventListener('mousemove', handleMouseMove);
|
|
187
|
+
element.addEventListener('click', handleMouseClick);
|
|
149
188
|
return () => {
|
|
150
189
|
element.removeEventListener('mouseout', handleMouseOut);
|
|
151
190
|
element.removeEventListener('mousemove', handleMouseMove);
|
|
191
|
+
element.removeEventListener('click', handleMouseClick);
|
|
152
192
|
};
|
|
153
|
-
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
|
|
154
|
-
|
|
193
|
+
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick]);
|
|
194
|
+
|
|
195
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
196
|
+
return /*#__PURE__*/_jsx(React.Fragment, {});
|
|
155
197
|
}
|
|
156
198
|
process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
|
|
157
199
|
// ----------------------------- Warning --------------------------------
|
|
158
200
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
159
201
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
160
202
|
// ----------------------------------------------------------------------
|
|
203
|
+
/**
|
|
204
|
+
* Callback fired when clicking on a scatter item.
|
|
205
|
+
* @param {MouseEvent} event Mouse event catched at the svg level
|
|
206
|
+
* @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
|
|
207
|
+
*/
|
|
208
|
+
onItemClick: PropTypes.func,
|
|
161
209
|
/**
|
|
162
210
|
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
163
211
|
* If `undefined`, the radius is assumed to be infinite.
|