@mui/x-charts 8.0.0-alpha.10 → 8.0.0-alpha.11
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 +1 -2
- package/BarChart/BarChart.js +2 -4
- package/BarChart/BarChart.plugins.d.ts +12 -0
- package/BarChart/BarChart.plugins.js +5 -0
- package/BarChart/useBarChartProps.d.ts +2 -3
- package/BarChart/useBarChartProps.js +5 -8
- package/CHANGELOG.md +107 -2
- package/ChartContainer/ChartContainer.d.ts +2 -2
- package/ChartContainer/ChartContainer.js +8 -1
- package/ChartContainer/useChartContainerProps.d.ts +4 -3
- package/ChartContainer/useChartContainerProps.js +11 -7
- package/ChartDataProvider/ChartDataProvider.js +4 -1
- package/ChartsSurface/ChartsSurface.d.ts +0 -6
- package/ChartsSurface/ChartsSurface.js +1 -10
- package/ChartsTooltip/ChartsTooltipContainer.js +2 -2
- package/Gauge/Gauge.js +0 -6
- package/Gauge/GaugeContainer.js +0 -6
- package/LineChart/LineChart.d.ts +1 -2
- package/LineChart/LineChart.js +2 -4
- package/LineChart/LineChart.plugins.d.ts +12 -0
- package/LineChart/LineChart.plugins.js +5 -0
- package/LineChart/useLineChartProps.d.ts +2 -3
- package/LineChart/useLineChartProps.js +5 -8
- package/PieChart/PieChart.d.ts +3 -1
- package/PieChart/PieChart.js +8 -115
- package/PieChart/PieChart.plugins.d.ts +5 -0
- package/PieChart/PieChart.plugins.js +3 -0
- package/ScatterChart/ScatterChart.js +8 -1
- package/ScatterChart/ScatterChart.plugins.d.ts +12 -0
- package/ScatterChart/ScatterChart.plugins.js +5 -0
- package/ScatterChart/useScatterChartProps.d.ts +2 -1
- package/ScatterChart/useScatterChartProps.js +3 -1
- package/SparkLineChart/SparkLineChart.d.ts +12 -0
- package/SparkLineChart/SparkLineChart.js +24 -4
- package/colorPalettes/colorPalettes.d.ts +2 -0
- package/context/ChartProvider/ChartProvider.types.d.ts +2 -1
- package/hooks/useAxisEvents.d.ts +0 -1
- package/hooks/useAxisEvents.js +0 -165
- package/index.d.ts +0 -1
- package/index.js +1 -2
- package/internals/plugins/allPlugins.d.ts +1 -1
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +5 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +9 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.d.ts +1 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +19 -2
- package/models/axis.d.ts +17 -0
- package/models/axis.js +5 -1
- package/models/index.d.ts +1 -1
- package/modern/BarChart/BarChart.js +2 -4
- package/modern/BarChart/BarChart.plugins.js +5 -0
- package/modern/BarChart/useBarChartProps.js +5 -8
- package/modern/ChartContainer/ChartContainer.js +8 -1
- package/modern/ChartContainer/useChartContainerProps.js +11 -7
- package/modern/ChartDataProvider/ChartDataProvider.js +4 -1
- package/modern/ChartsSurface/ChartsSurface.js +1 -10
- package/modern/ChartsTooltip/ChartsTooltipContainer.js +2 -2
- package/modern/Gauge/Gauge.js +0 -6
- package/modern/Gauge/GaugeContainer.js +0 -6
- package/modern/LineChart/LineChart.js +2 -4
- package/modern/LineChart/LineChart.plugins.js +5 -0
- package/modern/LineChart/useLineChartProps.js +5 -8
- package/modern/PieChart/PieChart.js +8 -115
- package/modern/PieChart/PieChart.plugins.js +3 -0
- package/modern/ScatterChart/ScatterChart.js +8 -1
- package/modern/ScatterChart/ScatterChart.plugins.js +5 -0
- package/modern/ScatterChart/useScatterChartProps.js +3 -1
- package/modern/SparkLineChart/SparkLineChart.js +24 -4
- package/modern/hooks/useAxisEvents.js +0 -165
- package/modern/index.js +1 -2
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
- package/modern/models/axis.js +5 -1
- package/node/BarChart/BarChart.js +2 -4
- package/node/BarChart/BarChart.plugins.js +11 -0
- package/node/BarChart/useBarChartProps.js +5 -8
- package/node/ChartContainer/ChartContainer.js +8 -1
- package/node/ChartContainer/useChartContainerProps.js +11 -7
- package/node/ChartDataProvider/ChartDataProvider.js +4 -1
- package/node/ChartsSurface/ChartsSurface.js +1 -10
- package/node/ChartsTooltip/ChartsTooltipContainer.js +2 -2
- package/node/Gauge/Gauge.js +0 -6
- package/node/Gauge/GaugeContainer.js +0 -6
- package/node/LineChart/LineChart.js +2 -4
- package/node/LineChart/LineChart.plugins.js +11 -0
- package/node/LineChart/useLineChartProps.js +5 -8
- package/node/PieChart/PieChart.js +8 -115
- package/node/PieChart/PieChart.plugins.js +9 -0
- package/node/ScatterChart/ScatterChart.js +8 -1
- package/node/ScatterChart/ScatterChart.plugins.js +11 -0
- package/node/ScatterChart/useScatterChartProps.js +3 -1
- package/node/SparkLineChart/SparkLineChart.js +24 -4
- package/node/hooks/useAxisEvents.js +1 -173
- package/node/index.js +1 -12
- package/node/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +65 -0
- package/node/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +141 -4
- package/node/models/axis.js +5 -1
- package/package.json +2 -2
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +0 -20
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
- package/ChartsOnAxisClickHandler/index.d.ts +0 -1
- package/ChartsOnAxisClickHandler/index.js +0 -1
- package/ChartsOnAxisClickHandler/package.json +0 -6
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
- package/modern/ChartsOnAxisClickHandler/index.js +0 -1
- package/node/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -88
- package/node/ChartsOnAxisClickHandler/index.js +0 -16
package/node/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js
CHANGED
|
@@ -15,10 +15,16 @@ var _useSelector = require("../../../store/useSelector");
|
|
|
15
15
|
var _useChartDimensions = require("../../corePlugins/useChartDimensions/useChartDimensions.selectors");
|
|
16
16
|
var _useChartSeries = require("../../corePlugins/useChartSeries/useChartSeries.selectors");
|
|
17
17
|
var _defaultizeAxis = require("./defaultizeAxis");
|
|
18
|
+
var _useChartCartesianAxis = require("./useChartCartesianAxis.selectors");
|
|
19
|
+
var _getAxisValue = require("./getAxisValue");
|
|
20
|
+
var _getSVGPoint = require("../../../getSVGPoint");
|
|
21
|
+
var _useChartInteraction = require("../useChartInteraction");
|
|
18
22
|
const useChartCartesianAxis = ({
|
|
19
23
|
params,
|
|
20
24
|
store,
|
|
21
|
-
seriesConfig
|
|
25
|
+
seriesConfig,
|
|
26
|
+
svgRef,
|
|
27
|
+
instance
|
|
22
28
|
}) => {
|
|
23
29
|
const {
|
|
24
30
|
xAxis,
|
|
@@ -33,7 +39,16 @@ const useChartCartesianAxis = ({
|
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
const drawingArea = (0, _useSelector.useSelector)(store, _useChartDimensions.selectorChartDrawingArea);
|
|
36
|
-
const
|
|
42
|
+
const processedSeries = (0, _useSelector.useSelector)(store, _useChartSeries.selectorChartSeriesProcessed);
|
|
43
|
+
const interactionAxis = (0, _useSelector.useSelector)(store, _useChartInteraction.selectorChartsInteractionAxis);
|
|
44
|
+
const {
|
|
45
|
+
axis: xAxisWithScale,
|
|
46
|
+
axisIds: xAxisIds
|
|
47
|
+
} = (0, _useSelector.useSelector)(store, _useChartCartesianAxis.selectorChartXAxis);
|
|
48
|
+
const {
|
|
49
|
+
axis: yAxisWithScale,
|
|
50
|
+
axisIds: yAxisIds
|
|
51
|
+
} = (0, _useSelector.useSelector)(store, _useChartCartesianAxis.selectorChartYAxis);
|
|
37
52
|
|
|
38
53
|
// The effect do not track any value defined synchronously during the 1st render by hooks called after `useChartCartesianAxis`
|
|
39
54
|
// As a consequence, the state generated by the 1st run of this useEffect will always be equal to the initialization one
|
|
@@ -49,14 +64,136 @@ const useChartCartesianAxis = ({
|
|
|
49
64
|
y: (0, _defaultizeAxis.defaultizeAxis)(yAxis, dataset, 'y')
|
|
50
65
|
})
|
|
51
66
|
}));
|
|
52
|
-
}, [seriesConfig, drawingArea,
|
|
67
|
+
}, [seriesConfig, drawingArea, xAxis, yAxis, dataset, store]);
|
|
68
|
+
const usedXAxis = xAxisIds[0];
|
|
69
|
+
const usedYAxis = yAxisIds[0];
|
|
70
|
+
|
|
71
|
+
// Use a ref to avoid rerendering on every mousemove event.
|
|
72
|
+
const mousePosition = React.useRef({
|
|
73
|
+
isInChart: false,
|
|
74
|
+
x: -1,
|
|
75
|
+
y: -1
|
|
76
|
+
});
|
|
77
|
+
React.useEffect(() => {
|
|
78
|
+
const element = svgRef.current;
|
|
79
|
+
if (element === null || params.disableAxisListener) {
|
|
80
|
+
return () => {};
|
|
81
|
+
}
|
|
82
|
+
const handleOut = () => {
|
|
83
|
+
mousePosition.current = {
|
|
84
|
+
isInChart: false,
|
|
85
|
+
x: -1,
|
|
86
|
+
y: -1
|
|
87
|
+
};
|
|
88
|
+
instance.cleanInteraction();
|
|
89
|
+
};
|
|
90
|
+
const handleMove = event => {
|
|
91
|
+
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
92
|
+
const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, target);
|
|
93
|
+
mousePosition.current.x = svgPoint.x;
|
|
94
|
+
mousePosition.current.y = svgPoint.y;
|
|
95
|
+
if (!instance.isPointInside(svgPoint, {
|
|
96
|
+
targetElement: event.target
|
|
97
|
+
})) {
|
|
98
|
+
if (mousePosition.current.isInChart) {
|
|
99
|
+
store.update(prev => (0, _extends2.default)({}, prev, {
|
|
100
|
+
interaction: {
|
|
101
|
+
item: null,
|
|
102
|
+
axis: {
|
|
103
|
+
x: null,
|
|
104
|
+
y: null
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}));
|
|
108
|
+
mousePosition.current.isInChart = false;
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
mousePosition.current.isInChart = true;
|
|
113
|
+
instance.setAxisInteraction({
|
|
114
|
+
x: (0, _getAxisValue.getAxisValue)(xAxisWithScale[usedXAxis], svgPoint.x),
|
|
115
|
+
y: (0, _getAxisValue.getAxisValue)(yAxisWithScale[usedYAxis], svgPoint.y)
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const handleDown = event => {
|
|
119
|
+
const target = event.currentTarget;
|
|
120
|
+
if (!target) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (target.hasPointerCapture(event.pointerId)) {
|
|
124
|
+
target.releasePointerCapture(event.pointerId);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
element.addEventListener('pointerdown', handleDown);
|
|
128
|
+
element.addEventListener('pointermove', handleMove);
|
|
129
|
+
element.addEventListener('pointerout', handleOut);
|
|
130
|
+
element.addEventListener('pointercancel', handleOut);
|
|
131
|
+
element.addEventListener('pointerleave', handleOut);
|
|
132
|
+
return () => {
|
|
133
|
+
element.removeEventListener('pointerdown', handleDown);
|
|
134
|
+
element.removeEventListener('pointermove', handleMove);
|
|
135
|
+
element.removeEventListener('pointerout', handleOut);
|
|
136
|
+
element.removeEventListener('pointercancel', handleOut);
|
|
137
|
+
element.removeEventListener('pointerleave', handleOut);
|
|
138
|
+
};
|
|
139
|
+
}, [svgRef, store, xAxisWithScale, usedXAxis, yAxisWithScale, usedYAxis, instance, params.disableAxisListener]);
|
|
140
|
+
React.useEffect(() => {
|
|
141
|
+
const element = svgRef.current;
|
|
142
|
+
if (element === null || !params.onAxisClick) {
|
|
143
|
+
return () => {};
|
|
144
|
+
}
|
|
145
|
+
const handleMouseClick = event => {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
let dataIndex = null;
|
|
148
|
+
let isXaxis = false;
|
|
149
|
+
if (interactionAxis.x === null && interactionAxis.y === null) {
|
|
150
|
+
const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, event);
|
|
151
|
+
const xIndex = (0, _getAxisValue.getAxisValue)(xAxisWithScale[usedXAxis], svgPoint.x)?.index ?? null;
|
|
152
|
+
isXaxis = xIndex !== null && xIndex !== -1;
|
|
153
|
+
dataIndex = isXaxis ? xIndex : (0, _getAxisValue.getAxisValue)(yAxisWithScale[usedYAxis], svgPoint.y)?.index ?? null;
|
|
154
|
+
} else {
|
|
155
|
+
isXaxis = interactionAxis.x !== null && interactionAxis.x.index !== -1;
|
|
156
|
+
dataIndex = isXaxis ? interactionAxis.x && interactionAxis.x.index : interactionAxis.y && interactionAxis.y.index;
|
|
157
|
+
}
|
|
158
|
+
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
159
|
+
if (dataIndex == null || dataIndex === -1) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The .data exist because otherwise the dataIndex would be null or -1.
|
|
164
|
+
const axisValue = (isXaxis ? xAxisWithScale : yAxisWithScale)[USED_AXIS_ID].data[dataIndex];
|
|
165
|
+
const seriesValues = {};
|
|
166
|
+
Object.keys(processedSeries).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
167
|
+
processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
168
|
+
const seriesItem = processedSeries[seriesType].series[seriesId];
|
|
169
|
+
const providedXAxisId = seriesItem.xAxisId;
|
|
170
|
+
const providedYAxisId = seriesItem.yAxisId;
|
|
171
|
+
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
172
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
173
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
params.onAxisClick?.(event, {
|
|
178
|
+
dataIndex,
|
|
179
|
+
axisValue,
|
|
180
|
+
seriesValues
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
element.addEventListener('click', handleMouseClick);
|
|
184
|
+
return () => {
|
|
185
|
+
element.removeEventListener('click', handleMouseClick);
|
|
186
|
+
};
|
|
187
|
+
}, [params.onAxisClick, processedSeries, svgRef, xAxisWithScale, xAxisIds, yAxisWithScale, yAxisIds, params, interactionAxis, usedXAxis, usedYAxis]);
|
|
53
188
|
return {};
|
|
54
189
|
};
|
|
55
190
|
exports.useChartCartesianAxis = useChartCartesianAxis;
|
|
56
191
|
useChartCartesianAxis.params = {
|
|
57
192
|
xAxis: true,
|
|
58
193
|
yAxis: true,
|
|
59
|
-
dataset: true
|
|
194
|
+
dataset: true,
|
|
195
|
+
onAxisClick: true,
|
|
196
|
+
disableAxisListener: true
|
|
60
197
|
};
|
|
61
198
|
useChartCartesianAxis.getDefaultizedParams = ({
|
|
62
199
|
params
|
package/node/models/axis.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.11",
|
|
4
4
|
"description": "The community edition of the Charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"reselect": "^5.1.1",
|
|
40
40
|
"use-sync-external-store": "^1.4.0",
|
|
41
41
|
"@mui/x-charts-vendor": "8.0.0-alpha.10",
|
|
42
|
-
"@mui/x-internals": "8.0.0-alpha.
|
|
42
|
+
"@mui/x-internals": "8.0.0-alpha.11"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@emotion/react": "^11.9.0",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export type ChartsAxisData = {
|
|
3
|
-
dataIndex: number;
|
|
4
|
-
axisValue?: number | Date | string;
|
|
5
|
-
seriesValues: Record<string, number | null | undefined>;
|
|
6
|
-
};
|
|
7
|
-
export interface ChartsOnAxisClickHandlerProps {
|
|
8
|
-
/**
|
|
9
|
-
* The function called for onClick events.
|
|
10
|
-
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
11
|
-
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
12
|
-
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
13
|
-
*/
|
|
14
|
-
onAxisClick?: (event: MouseEvent, data: null | ChartsAxisData) => void;
|
|
15
|
-
}
|
|
16
|
-
declare function ChartsOnAxisClickHandler(props: ChartsOnAxisClickHandlerProps): React.JSX.Element;
|
|
17
|
-
declare namespace ChartsOnAxisClickHandler {
|
|
18
|
-
var propTypes: any;
|
|
19
|
-
}
|
|
20
|
-
export { ChartsOnAxisClickHandler };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { useSeries } from "../hooks/useSeries.js";
|
|
6
|
-
import { useSvgRef, useXAxes, useYAxes } from "../hooks/index.js";
|
|
7
|
-
import { useStore } from "../internals/store/useStore.js";
|
|
8
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
function ChartsOnAxisClickHandler(props) {
|
|
10
|
-
const {
|
|
11
|
-
onAxisClick
|
|
12
|
-
} = props;
|
|
13
|
-
const svgRef = useSvgRef();
|
|
14
|
-
const series = useSeries();
|
|
15
|
-
const store = useStore();
|
|
16
|
-
const {
|
|
17
|
-
xAxis,
|
|
18
|
-
xAxisIds
|
|
19
|
-
} = useXAxes();
|
|
20
|
-
const {
|
|
21
|
-
yAxis,
|
|
22
|
-
yAxisIds
|
|
23
|
-
} = useYAxes();
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
const element = svgRef.current;
|
|
26
|
-
if (element === null || !onAxisClick) {
|
|
27
|
-
return () => {};
|
|
28
|
-
}
|
|
29
|
-
const handleMouseClick = event => {
|
|
30
|
-
event.preventDefault();
|
|
31
|
-
const {
|
|
32
|
-
x: axisX,
|
|
33
|
-
y: axisY
|
|
34
|
-
} = store.value.interaction.axis;
|
|
35
|
-
const isXaxis = axisX && axisX.index !== -1;
|
|
36
|
-
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
37
|
-
const dataIndex = isXaxis ? axisX && axisX.index : axisY && axisY.index;
|
|
38
|
-
if (dataIndex == null) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const seriesValues = {};
|
|
42
|
-
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
43
|
-
series[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
44
|
-
const seriesItem = series[seriesType].series[seriesId];
|
|
45
|
-
const providedXAxisId = seriesItem.xAxisId;
|
|
46
|
-
const providedYAxisId = seriesItem.yAxisId;
|
|
47
|
-
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
48
|
-
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
49
|
-
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
const axisValue = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data?.[dataIndex];
|
|
54
|
-
onAxisClick(event, {
|
|
55
|
-
dataIndex,
|
|
56
|
-
axisValue,
|
|
57
|
-
seriesValues
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
element.addEventListener('click', handleMouseClick);
|
|
61
|
-
return () => {
|
|
62
|
-
element.removeEventListener('click', handleMouseClick);
|
|
63
|
-
};
|
|
64
|
-
}, [onAxisClick, series, store, svgRef, xAxis, xAxisIds, yAxis, yAxisIds]);
|
|
65
|
-
|
|
66
|
-
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
67
|
-
return /*#__PURE__*/_jsx(React.Fragment, {});
|
|
68
|
-
}
|
|
69
|
-
process.env.NODE_ENV !== "production" ? ChartsOnAxisClickHandler.propTypes = {
|
|
70
|
-
// ----------------------------- Warning --------------------------------
|
|
71
|
-
// | These PropTypes are generated from the TypeScript type definitions |
|
|
72
|
-
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
73
|
-
// ----------------------------------------------------------------------
|
|
74
|
-
/**
|
|
75
|
-
* The function called for onClick events.
|
|
76
|
-
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
77
|
-
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
78
|
-
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
79
|
-
*/
|
|
80
|
-
onAxisClick: PropTypes.func
|
|
81
|
-
} : void 0;
|
|
82
|
-
export { ChartsOnAxisClickHandler };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ChartsOnAxisClickHandler';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./ChartsOnAxisClickHandler.js";
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { useSeries } from "../hooks/useSeries.js";
|
|
6
|
-
import { useSvgRef, useXAxes, useYAxes } from "../hooks/index.js";
|
|
7
|
-
import { useStore } from "../internals/store/useStore.js";
|
|
8
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
function ChartsOnAxisClickHandler(props) {
|
|
10
|
-
const {
|
|
11
|
-
onAxisClick
|
|
12
|
-
} = props;
|
|
13
|
-
const svgRef = useSvgRef();
|
|
14
|
-
const series = useSeries();
|
|
15
|
-
const store = useStore();
|
|
16
|
-
const {
|
|
17
|
-
xAxis,
|
|
18
|
-
xAxisIds
|
|
19
|
-
} = useXAxes();
|
|
20
|
-
const {
|
|
21
|
-
yAxis,
|
|
22
|
-
yAxisIds
|
|
23
|
-
} = useYAxes();
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
const element = svgRef.current;
|
|
26
|
-
if (element === null || !onAxisClick) {
|
|
27
|
-
return () => {};
|
|
28
|
-
}
|
|
29
|
-
const handleMouseClick = event => {
|
|
30
|
-
event.preventDefault();
|
|
31
|
-
const {
|
|
32
|
-
x: axisX,
|
|
33
|
-
y: axisY
|
|
34
|
-
} = store.value.interaction.axis;
|
|
35
|
-
const isXaxis = axisX && axisX.index !== -1;
|
|
36
|
-
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
37
|
-
const dataIndex = isXaxis ? axisX && axisX.index : axisY && axisY.index;
|
|
38
|
-
if (dataIndex == null) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const seriesValues = {};
|
|
42
|
-
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
43
|
-
series[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
44
|
-
const seriesItem = series[seriesType].series[seriesId];
|
|
45
|
-
const providedXAxisId = seriesItem.xAxisId;
|
|
46
|
-
const providedYAxisId = seriesItem.yAxisId;
|
|
47
|
-
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
48
|
-
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
49
|
-
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
const axisValue = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data?.[dataIndex];
|
|
54
|
-
onAxisClick(event, {
|
|
55
|
-
dataIndex,
|
|
56
|
-
axisValue,
|
|
57
|
-
seriesValues
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
element.addEventListener('click', handleMouseClick);
|
|
61
|
-
return () => {
|
|
62
|
-
element.removeEventListener('click', handleMouseClick);
|
|
63
|
-
};
|
|
64
|
-
}, [onAxisClick, series, store, svgRef, xAxis, xAxisIds, yAxis, yAxisIds]);
|
|
65
|
-
|
|
66
|
-
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
67
|
-
return /*#__PURE__*/_jsx(React.Fragment, {});
|
|
68
|
-
}
|
|
69
|
-
process.env.NODE_ENV !== "production" ? ChartsOnAxisClickHandler.propTypes = {
|
|
70
|
-
// ----------------------------- Warning --------------------------------
|
|
71
|
-
// | These PropTypes are generated from the TypeScript type definitions |
|
|
72
|
-
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
73
|
-
// ----------------------------------------------------------------------
|
|
74
|
-
/**
|
|
75
|
-
* The function called for onClick events.
|
|
76
|
-
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
77
|
-
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
78
|
-
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
79
|
-
*/
|
|
80
|
-
onAxisClick: PropTypes.func
|
|
81
|
-
} : void 0;
|
|
82
|
-
export { ChartsOnAxisClickHandler };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./ChartsOnAxisClickHandler.js";
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use client';
|
|
3
|
-
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", {
|
|
7
|
-
value: true
|
|
8
|
-
});
|
|
9
|
-
exports.ChartsOnAxisClickHandler = ChartsOnAxisClickHandler;
|
|
10
|
-
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
|
-
var _useSeries = require("../hooks/useSeries");
|
|
13
|
-
var _hooks = require("../hooks");
|
|
14
|
-
var _useStore = require("../internals/store/useStore");
|
|
15
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
-
function ChartsOnAxisClickHandler(props) {
|
|
17
|
-
const {
|
|
18
|
-
onAxisClick
|
|
19
|
-
} = props;
|
|
20
|
-
const svgRef = (0, _hooks.useSvgRef)();
|
|
21
|
-
const series = (0, _useSeries.useSeries)();
|
|
22
|
-
const store = (0, _useStore.useStore)();
|
|
23
|
-
const {
|
|
24
|
-
xAxis,
|
|
25
|
-
xAxisIds
|
|
26
|
-
} = (0, _hooks.useXAxes)();
|
|
27
|
-
const {
|
|
28
|
-
yAxis,
|
|
29
|
-
yAxisIds
|
|
30
|
-
} = (0, _hooks.useYAxes)();
|
|
31
|
-
React.useEffect(() => {
|
|
32
|
-
const element = svgRef.current;
|
|
33
|
-
if (element === null || !onAxisClick) {
|
|
34
|
-
return () => {};
|
|
35
|
-
}
|
|
36
|
-
const handleMouseClick = event => {
|
|
37
|
-
event.preventDefault();
|
|
38
|
-
const {
|
|
39
|
-
x: axisX,
|
|
40
|
-
y: axisY
|
|
41
|
-
} = store.value.interaction.axis;
|
|
42
|
-
const isXaxis = axisX && axisX.index !== -1;
|
|
43
|
-
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
44
|
-
const dataIndex = isXaxis ? axisX && axisX.index : axisY && axisY.index;
|
|
45
|
-
if (dataIndex == null) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const seriesValues = {};
|
|
49
|
-
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
50
|
-
series[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
51
|
-
const seriesItem = series[seriesType].series[seriesId];
|
|
52
|
-
const providedXAxisId = seriesItem.xAxisId;
|
|
53
|
-
const providedYAxisId = seriesItem.yAxisId;
|
|
54
|
-
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
55
|
-
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
56
|
-
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
const axisValue = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data?.[dataIndex];
|
|
61
|
-
onAxisClick(event, {
|
|
62
|
-
dataIndex,
|
|
63
|
-
axisValue,
|
|
64
|
-
seriesValues
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
element.addEventListener('click', handleMouseClick);
|
|
68
|
-
return () => {
|
|
69
|
-
element.removeEventListener('click', handleMouseClick);
|
|
70
|
-
};
|
|
71
|
-
}, [onAxisClick, series, store, svgRef, xAxis, xAxisIds, yAxis, yAxisIds]);
|
|
72
|
-
|
|
73
|
-
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
74
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {});
|
|
75
|
-
}
|
|
76
|
-
process.env.NODE_ENV !== "production" ? ChartsOnAxisClickHandler.propTypes = {
|
|
77
|
-
// ----------------------------- Warning --------------------------------
|
|
78
|
-
// | These PropTypes are generated from the TypeScript type definitions |
|
|
79
|
-
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
80
|
-
// ----------------------------------------------------------------------
|
|
81
|
-
/**
|
|
82
|
-
* The function called for onClick events.
|
|
83
|
-
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
84
|
-
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
85
|
-
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
86
|
-
*/
|
|
87
|
-
onAxisClick: _propTypes.default.func
|
|
88
|
-
} : void 0;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _ChartsOnAxisClickHandler = require("./ChartsOnAxisClickHandler");
|
|
7
|
-
Object.keys(_ChartsOnAxisClickHandler).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _ChartsOnAxisClickHandler[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _ChartsOnAxisClickHandler[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|