@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.
Files changed (108) hide show
  1. package/BarChart/BarChart.d.ts +1 -2
  2. package/BarChart/BarChart.js +2 -4
  3. package/BarChart/BarChart.plugins.d.ts +12 -0
  4. package/BarChart/BarChart.plugins.js +5 -0
  5. package/BarChart/useBarChartProps.d.ts +2 -3
  6. package/BarChart/useBarChartProps.js +5 -8
  7. package/CHANGELOG.md +107 -2
  8. package/ChartContainer/ChartContainer.d.ts +2 -2
  9. package/ChartContainer/ChartContainer.js +8 -1
  10. package/ChartContainer/useChartContainerProps.d.ts +4 -3
  11. package/ChartContainer/useChartContainerProps.js +11 -7
  12. package/ChartDataProvider/ChartDataProvider.js +4 -1
  13. package/ChartsSurface/ChartsSurface.d.ts +0 -6
  14. package/ChartsSurface/ChartsSurface.js +1 -10
  15. package/ChartsTooltip/ChartsTooltipContainer.js +2 -2
  16. package/Gauge/Gauge.js +0 -6
  17. package/Gauge/GaugeContainer.js +0 -6
  18. package/LineChart/LineChart.d.ts +1 -2
  19. package/LineChart/LineChart.js +2 -4
  20. package/LineChart/LineChart.plugins.d.ts +12 -0
  21. package/LineChart/LineChart.plugins.js +5 -0
  22. package/LineChart/useLineChartProps.d.ts +2 -3
  23. package/LineChart/useLineChartProps.js +5 -8
  24. package/PieChart/PieChart.d.ts +3 -1
  25. package/PieChart/PieChart.js +8 -115
  26. package/PieChart/PieChart.plugins.d.ts +5 -0
  27. package/PieChart/PieChart.plugins.js +3 -0
  28. package/ScatterChart/ScatterChart.js +8 -1
  29. package/ScatterChart/ScatterChart.plugins.d.ts +12 -0
  30. package/ScatterChart/ScatterChart.plugins.js +5 -0
  31. package/ScatterChart/useScatterChartProps.d.ts +2 -1
  32. package/ScatterChart/useScatterChartProps.js +3 -1
  33. package/SparkLineChart/SparkLineChart.d.ts +12 -0
  34. package/SparkLineChart/SparkLineChart.js +24 -4
  35. package/colorPalettes/colorPalettes.d.ts +2 -0
  36. package/context/ChartProvider/ChartProvider.types.d.ts +2 -1
  37. package/hooks/useAxisEvents.d.ts +0 -1
  38. package/hooks/useAxisEvents.js +0 -165
  39. package/index.d.ts +0 -1
  40. package/index.js +1 -2
  41. package/internals/plugins/allPlugins.d.ts +1 -1
  42. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +5 -2
  43. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +9 -0
  44. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
  45. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.d.ts +1 -2
  46. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
  47. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +19 -2
  48. package/models/axis.d.ts +17 -0
  49. package/models/axis.js +5 -1
  50. package/models/index.d.ts +1 -1
  51. package/modern/BarChart/BarChart.js +2 -4
  52. package/modern/BarChart/BarChart.plugins.js +5 -0
  53. package/modern/BarChart/useBarChartProps.js +5 -8
  54. package/modern/ChartContainer/ChartContainer.js +8 -1
  55. package/modern/ChartContainer/useChartContainerProps.js +11 -7
  56. package/modern/ChartDataProvider/ChartDataProvider.js +4 -1
  57. package/modern/ChartsSurface/ChartsSurface.js +1 -10
  58. package/modern/ChartsTooltip/ChartsTooltipContainer.js +2 -2
  59. package/modern/Gauge/Gauge.js +0 -6
  60. package/modern/Gauge/GaugeContainer.js +0 -6
  61. package/modern/LineChart/LineChart.js +2 -4
  62. package/modern/LineChart/LineChart.plugins.js +5 -0
  63. package/modern/LineChart/useLineChartProps.js +5 -8
  64. package/modern/PieChart/PieChart.js +8 -115
  65. package/modern/PieChart/PieChart.plugins.js +3 -0
  66. package/modern/ScatterChart/ScatterChart.js +8 -1
  67. package/modern/ScatterChart/ScatterChart.plugins.js +5 -0
  68. package/modern/ScatterChart/useScatterChartProps.js +3 -1
  69. package/modern/SparkLineChart/SparkLineChart.js +24 -4
  70. package/modern/hooks/useAxisEvents.js +0 -165
  71. package/modern/index.js +1 -2
  72. package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
  73. package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
  74. package/modern/models/axis.js +5 -1
  75. package/node/BarChart/BarChart.js +2 -4
  76. package/node/BarChart/BarChart.plugins.js +11 -0
  77. package/node/BarChart/useBarChartProps.js +5 -8
  78. package/node/ChartContainer/ChartContainer.js +8 -1
  79. package/node/ChartContainer/useChartContainerProps.js +11 -7
  80. package/node/ChartDataProvider/ChartDataProvider.js +4 -1
  81. package/node/ChartsSurface/ChartsSurface.js +1 -10
  82. package/node/ChartsTooltip/ChartsTooltipContainer.js +2 -2
  83. package/node/Gauge/Gauge.js +0 -6
  84. package/node/Gauge/GaugeContainer.js +0 -6
  85. package/node/LineChart/LineChart.js +2 -4
  86. package/node/LineChart/LineChart.plugins.js +11 -0
  87. package/node/LineChart/useLineChartProps.js +5 -8
  88. package/node/PieChart/PieChart.js +8 -115
  89. package/node/PieChart/PieChart.plugins.js +9 -0
  90. package/node/ScatterChart/ScatterChart.js +8 -1
  91. package/node/ScatterChart/ScatterChart.plugins.js +11 -0
  92. package/node/ScatterChart/useScatterChartProps.js +3 -1
  93. package/node/SparkLineChart/SparkLineChart.js +24 -4
  94. package/node/hooks/useAxisEvents.js +1 -173
  95. package/node/index.js +1 -12
  96. package/node/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +65 -0
  97. package/node/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +141 -4
  98. package/node/models/axis.js +5 -1
  99. package/package.json +2 -2
  100. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +0 -20
  101. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
  102. package/ChartsOnAxisClickHandler/index.d.ts +0 -1
  103. package/ChartsOnAxisClickHandler/index.js +0 -1
  104. package/ChartsOnAxisClickHandler/package.json +0 -6
  105. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
  106. package/modern/ChartsOnAxisClickHandler/index.js +0 -1
  107. package/node/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -88
  108. package/node/ChartsOnAxisClickHandler/index.js +0 -16
@@ -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 formattedSeries = (0, _useSelector.useSelector)(store, _useChartSeries.selectorChartSeriesState);
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, formattedSeries, xAxis, yAxis, dataset, store]);
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
@@ -15,4 +15,8 @@ function isBandScaleConfig(scaleConfig) {
15
15
  }
16
16
  function isPointScaleConfig(scaleConfig) {
17
17
  return scaleConfig.scaleType === 'point';
18
- }
18
+ }
19
+
20
+ /**
21
+ * The data format returned by onAxisClick.
22
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "8.0.0-alpha.10",
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.10"
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,6 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "module": "./index.js",
4
- "main": "../node/ChartsOnAxisClickHandler/index.js",
5
- "types": "./index.d.ts"
6
- }
@@ -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
- });