@mui/x-charts 9.11.0 → 9.12.0

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 (68) hide show
  1. package/BarChart/BarChart.js +7 -0
  2. package/BarChart/BarChart.mjs +7 -0
  3. package/CHANGELOG.md +165 -0
  4. package/ChartsContainer/ChartsContainer.js +7 -0
  5. package/ChartsContainer/ChartsContainer.mjs +7 -0
  6. package/ChartsContainer/useChartsContainerProps.js +3 -1
  7. package/ChartsContainer/useChartsContainerProps.mjs +3 -1
  8. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -9
  9. package/ChartsTooltip/ChartsAxisTooltipContent.mjs +2 -9
  10. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  11. package/ChartsTooltip/ChartsItemTooltipContent.mjs +2 -2
  12. package/ChartsTooltip/ChartsTooltipContainer.js +6 -2
  13. package/ChartsTooltip/ChartsTooltipContainer.mjs +6 -2
  14. package/LineChart/CircleMarkElement.js +0 -4
  15. package/LineChart/CircleMarkElement.mjs +0 -4
  16. package/LineChart/LineChart.js +7 -0
  17. package/LineChart/LineChart.mjs +7 -0
  18. package/PieChart/PieChart.js +7 -0
  19. package/PieChart/PieChart.mjs +7 -0
  20. package/RadarChart/RadarAxis/RadarAxis.utils.d.mts +1 -1
  21. package/RadarChart/RadarAxis/RadarAxis.utils.d.ts +1 -1
  22. package/RadarChart/RadarChart.js +7 -0
  23. package/RadarChart/RadarChart.mjs +7 -0
  24. package/RadarChart/useRadarChartProps.js +3 -1
  25. package/RadarChart/useRadarChartProps.mjs +3 -1
  26. package/ScatterChart/ScatterChart.js +7 -0
  27. package/ScatterChart/ScatterChart.mjs +7 -0
  28. package/SparkLineChart/SparkLineChart.js +7 -0
  29. package/SparkLineChart/SparkLineChart.mjs +7 -0
  30. package/hooks/useInteractionItemProps.js +4 -0
  31. package/hooks/useInteractionItemProps.mjs +4 -0
  32. package/index.js +1 -1
  33. package/index.mjs +1 -1
  34. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.js +13 -3
  35. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.mjs +12 -3
  36. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.d.mts +8 -0
  37. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.d.ts +8 -0
  38. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.js +25 -0
  39. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.mjs +19 -0
  40. package/internals/components/ChartsAccessibilityProxy/index.d.mts +2 -1
  41. package/internals/components/ChartsAccessibilityProxy/index.d.ts +2 -1
  42. package/internals/components/ChartsAccessibilityProxy/index.js +11 -0
  43. package/internals/components/ChartsAccessibilityProxy/index.mjs +2 -1
  44. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.js +3 -1
  45. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.mjs +3 -1
  46. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.types.d.mts +5 -0
  47. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.types.d.ts +5 -0
  48. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +10 -0
  49. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.mjs +10 -0
  50. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +22 -0
  51. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.mjs +22 -0
  52. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +27 -1
  53. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.mjs +27 -1
  54. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.types.d.mts +20 -0
  55. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.types.d.ts +20 -0
  56. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +209 -35
  57. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.mjs +211 -36
  58. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.mts +3 -0
  59. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +3 -0
  60. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +12 -5
  61. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.mjs +11 -4
  62. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.mts +29 -0
  63. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +29 -0
  64. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.d.mts +28 -0
  65. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.d.ts +28 -0
  66. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.js +81 -0
  67. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.mjs +76 -0
  68. package/package.json +4 -4
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getItemAtAxisPosition = getItemAtAxisPosition;
7
+ var _composition = require("../../../../../models/seriesType/composition");
8
+ var _getAxisValue = require("../../useChartCartesianAxis/getAxisValue");
9
+ var _getNonEmptySeriesArray = require("./getNonEmptySeriesArray");
10
+ var _findVisibleDataIndex = require("./findVisibleDataIndex");
11
+ /**
12
+ * Resolves the item a click falls on when it hit no item, by looking at the axis under the
13
+ * pointer. Keeps the focused series when there is one, so clicking the empty space above a bar
14
+ * moves along the series the user was already navigating.
15
+ *
16
+ * Returns `null` for charts without a cartesian axis, and when the axis resolves no index.
17
+ */
18
+ function getItemAtAxisPosition({
19
+ point,
20
+ xAxis,
21
+ yAxis,
22
+ processedSeries,
23
+ focusedItem
24
+ }) {
25
+ const target = getTargetSeries(processedSeries, focusedItem);
26
+ if (target === null) {
27
+ return null;
28
+ }
29
+ const series = processedSeries[target.type]?.series[target.seriesId];
30
+ const data = series?.data;
31
+ if (!data || data.length === 0) {
32
+ return null;
33
+ }
34
+
35
+ // Read the index off the axis the target series is bound to, which is not necessarily the
36
+ // default one on a chart with several axes.
37
+ const xAxisId = (series && 'xAxisId' in series ? series.xAxisId : undefined) ?? xAxis?.axisIds[0];
38
+ const yAxisId = (series && 'yAxisId' in series ? series.yAxisId : undefined) ?? yAxis?.axisIds[0];
39
+ const xAxisConfig = xAxisId === undefined ? undefined : xAxis?.axis[xAxisId];
40
+ const yAxisConfig = yAxisId === undefined ? undefined : yAxis?.axis[yAxisId];
41
+ if (!xAxisConfig && !yAxisConfig) {
42
+ return null;
43
+ }
44
+ const xIndex = xAxisConfig ? (0, _getAxisValue.getAxisIndex)(xAxisConfig, point.x) : -1;
45
+ const yIndex = yAxisConfig ? (0, _getAxisValue.getAxisIndex)(yAxisConfig, point.y) : -1;
46
+ const dataIndex = xIndex !== -1 ? xIndex : yIndex;
47
+ if (dataIndex === -1) {
48
+ return null;
49
+ }
50
+
51
+ // The axis can be longer than the series it is shared with, and the index may be hidden.
52
+ const findVisible = direction => (0, _findVisibleDataIndex.findVisibleDataIndex)({
53
+ processedSeries,
54
+ type: target.type,
55
+ seriesId: target.seriesId,
56
+ startIndex: Math.min(dataIndex, data.length - 1),
57
+ dataLength: data.length,
58
+ direction,
59
+ allowCycles: false
60
+ });
61
+ const visibleDataIndex = findVisible(1) ?? findVisible(-1);
62
+ if (visibleDataIndex === null) {
63
+ return null;
64
+ }
65
+ return {
66
+ type: target.type,
67
+ seriesId: target.seriesId,
68
+ dataIndex: visibleDataIndex
69
+ };
70
+ }
71
+
72
+ /** The focused series when it is a cartesian one, the first series with data otherwise. */
73
+ function getTargetSeries(processedSeries, focusedItem) {
74
+ if (focusedItem != null && _composition.composableCartesianSeriesTypes.has(focusedItem.type) && processedSeries[focusedItem.type]?.series[focusedItem.seriesId] !== undefined) {
75
+ return {
76
+ type: focusedItem.type,
77
+ seriesId: focusedItem.seriesId
78
+ };
79
+ }
80
+ return (0, _getNonEmptySeriesArray.getNonEmptySeriesArray)(processedSeries, _composition.composableCartesianSeriesTypes)[0] ?? null;
81
+ }
@@ -0,0 +1,76 @@
1
+ import { composableCartesianSeriesTypes } from "../../../../../models/seriesType/composition.mjs";
2
+ import { getAxisIndex } from "../../useChartCartesianAxis/getAxisValue.mjs";
3
+ import { getNonEmptySeriesArray } from "./getNonEmptySeriesArray.mjs";
4
+ import { findVisibleDataIndex } from "./findVisibleDataIndex.mjs";
5
+
6
+ /**
7
+ * Resolves the item a click falls on when it hit no item, by looking at the axis under the
8
+ * pointer. Keeps the focused series when there is one, so clicking the empty space above a bar
9
+ * moves along the series the user was already navigating.
10
+ *
11
+ * Returns `null` for charts without a cartesian axis, and when the axis resolves no index.
12
+ */
13
+ export function getItemAtAxisPosition({
14
+ point,
15
+ xAxis,
16
+ yAxis,
17
+ processedSeries,
18
+ focusedItem
19
+ }) {
20
+ const target = getTargetSeries(processedSeries, focusedItem);
21
+ if (target === null) {
22
+ return null;
23
+ }
24
+ const series = processedSeries[target.type]?.series[target.seriesId];
25
+ const data = series?.data;
26
+ if (!data || data.length === 0) {
27
+ return null;
28
+ }
29
+
30
+ // Read the index off the axis the target series is bound to, which is not necessarily the
31
+ // default one on a chart with several axes.
32
+ const xAxisId = (series && 'xAxisId' in series ? series.xAxisId : undefined) ?? xAxis?.axisIds[0];
33
+ const yAxisId = (series && 'yAxisId' in series ? series.yAxisId : undefined) ?? yAxis?.axisIds[0];
34
+ const xAxisConfig = xAxisId === undefined ? undefined : xAxis?.axis[xAxisId];
35
+ const yAxisConfig = yAxisId === undefined ? undefined : yAxis?.axis[yAxisId];
36
+ if (!xAxisConfig && !yAxisConfig) {
37
+ return null;
38
+ }
39
+ const xIndex = xAxisConfig ? getAxisIndex(xAxisConfig, point.x) : -1;
40
+ const yIndex = yAxisConfig ? getAxisIndex(yAxisConfig, point.y) : -1;
41
+ const dataIndex = xIndex !== -1 ? xIndex : yIndex;
42
+ if (dataIndex === -1) {
43
+ return null;
44
+ }
45
+
46
+ // The axis can be longer than the series it is shared with, and the index may be hidden.
47
+ const findVisible = direction => findVisibleDataIndex({
48
+ processedSeries,
49
+ type: target.type,
50
+ seriesId: target.seriesId,
51
+ startIndex: Math.min(dataIndex, data.length - 1),
52
+ dataLength: data.length,
53
+ direction,
54
+ allowCycles: false
55
+ });
56
+ const visibleDataIndex = findVisible(1) ?? findVisible(-1);
57
+ if (visibleDataIndex === null) {
58
+ return null;
59
+ }
60
+ return {
61
+ type: target.type,
62
+ seriesId: target.seriesId,
63
+ dataIndex: visibleDataIndex
64
+ };
65
+ }
66
+
67
+ /** The focused series when it is a cartesian one, the first series with data otherwise. */
68
+ function getTargetSeries(processedSeries, focusedItem) {
69
+ if (focusedItem != null && composableCartesianSeriesTypes.has(focusedItem.type) && processedSeries[focusedItem.type]?.series[focusedItem.seriesId] !== undefined) {
70
+ return {
71
+ type: focusedItem.type,
72
+ seriesId: focusedItem.seriesId
73
+ };
74
+ }
75
+ return getNonEmptySeriesArray(processedSeries, composableCartesianSeriesTypes)[0] ?? null;
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "9.11.0",
3
+ "version": "9.12.0",
4
4
  "author": "MUI Team",
5
5
  "description": "The community edition of MUI X Charts components.",
6
6
  "license": "MIT",
@@ -34,9 +34,9 @@
34
34
  "prop-types": "^15.8.1",
35
35
  "reselect": "^5.2.0",
36
36
  "use-sync-external-store": "^1.6.0",
37
- "@mui/x-internal-gestures": "^9.10.0",
38
- "@mui/x-internals": "^9.11.0",
39
- "@mui/x-charts-vendor": "^9.11.0"
37
+ "@mui/x-charts-vendor": "^9.11.1",
38
+ "@mui/x-internals": "^9.12.0",
39
+ "@mui/x-internal-gestures": "^9.12.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@emotion/react": "^11.9.0",