@mui/x-charts 8.22.1 → 8.23.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 (124) hide show
  1. package/BarChart/BarElement.js +1 -1
  2. package/BarChart/FocusedBar.js +1 -1
  3. package/BarChart/seriesConfig/bar/keyboardFocusHandler.d.ts +3 -0
  4. package/BarChart/seriesConfig/bar/keyboardFocusHandler.js +23 -0
  5. package/BarChart/seriesConfig/bar/seriesProcessor.js +2 -2
  6. package/BarChart/seriesConfig/index.js +3 -1
  7. package/CHANGELOG.md +101 -0
  8. package/LineChart/FocusedLineMark.js +1 -1
  9. package/LineChart/seriesConfig/index.js +3 -1
  10. package/LineChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  11. package/LineChart/seriesConfig/keyboardFocusHandler.js +23 -0
  12. package/LineChart/seriesConfig/seriesProcessor.js +2 -2
  13. package/PieChart/FocusedPieArc.js +1 -1
  14. package/PieChart/dataTransform/useTransformData.js +1 -1
  15. package/PieChart/seriesConfig/index.js +3 -1
  16. package/PieChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  17. package/PieChart/seriesConfig/keyboardFocusHandler.js +23 -0
  18. package/ScatterChart/FocusedScatterMark.js +1 -1
  19. package/ScatterChart/seriesConfig/index.js +3 -1
  20. package/ScatterChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  21. package/ScatterChart/seriesConfig/keyboardFocusHandler.js +23 -0
  22. package/esm/BarChart/BarElement.js +1 -1
  23. package/esm/BarChart/FocusedBar.js +1 -1
  24. package/esm/BarChart/seriesConfig/bar/keyboardFocusHandler.d.ts +3 -0
  25. package/esm/BarChart/seriesConfig/bar/keyboardFocusHandler.js +17 -0
  26. package/esm/BarChart/seriesConfig/bar/seriesProcessor.js +1 -1
  27. package/esm/BarChart/seriesConfig/index.js +3 -1
  28. package/esm/LineChart/FocusedLineMark.js +1 -1
  29. package/esm/LineChart/seriesConfig/index.js +3 -1
  30. package/esm/LineChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  31. package/esm/LineChart/seriesConfig/keyboardFocusHandler.js +17 -0
  32. package/esm/LineChart/seriesConfig/seriesProcessor.js +1 -1
  33. package/esm/PieChart/FocusedPieArc.js +1 -1
  34. package/esm/PieChart/dataTransform/useTransformData.js +1 -1
  35. package/esm/PieChart/seriesConfig/index.js +3 -1
  36. package/esm/PieChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  37. package/esm/PieChart/seriesConfig/keyboardFocusHandler.js +17 -0
  38. package/esm/ScatterChart/FocusedScatterMark.js +1 -1
  39. package/esm/ScatterChart/seriesConfig/index.js +3 -1
  40. package/esm/ScatterChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
  41. package/esm/ScatterChart/seriesConfig/keyboardFocusHandler.js +17 -0
  42. package/esm/hooks/useFocusedItem.d.ts +1 -12
  43. package/esm/hooks/useFocusedItem.js +3 -10
  44. package/esm/hooks/useIsItemFocused.d.ts +4 -3
  45. package/esm/hooks/useIsItemFocused.js +1 -1
  46. package/esm/hooks/useIsItemFocusedGetter.d.ts +3 -2
  47. package/esm/hooks/useIsItemFocusedGetter.js +2 -1
  48. package/esm/index.js +1 -1
  49. package/esm/internals/commonNextFocusItem.d.ts +14 -0
  50. package/esm/internals/commonNextFocusItem.js +84 -0
  51. package/esm/internals/index.d.ts +1 -1
  52. package/esm/internals/index.js +1 -1
  53. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.d.ts +13 -0
  54. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.js +1 -0
  55. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.d.ts +2 -2
  56. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +12 -105
  57. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +5 -31
  58. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +9 -15
  59. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +6 -21
  60. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.d.ts +15 -0
  61. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +45 -0
  62. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.d.ts +11 -0
  63. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +40 -0
  64. package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +1 -9
  65. package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.js +2 -2
  66. package/esm/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +2 -0
  67. package/esm/internals/plugins/models/seriesConfig/seriesProcessor.types.d.ts +1 -1
  68. package/esm/internals/seriesHasData.d.ts +4 -0
  69. package/esm/internals/seriesHasData.js +8 -0
  70. package/esm/internals/stacking/index.d.ts +1 -0
  71. package/esm/internals/stacking/index.js +1 -0
  72. package/esm/internals/stacking/offset/index.d.ts +1 -0
  73. package/esm/internals/stacking/offset/index.js +1 -0
  74. package/esm/internals/stacking/offset/offsetDiverging.d.ts +8 -0
  75. package/esm/internals/stacking/offset/offsetDiverging.js +47 -0
  76. package/esm/internals/{stackSeries.d.ts → stacking/stackSeries.d.ts} +8 -8
  77. package/esm/internals/{stackSeries.js → stacking/stackSeries.js} +8 -6
  78. package/esm/models/seriesType/index.d.ts +3 -1
  79. package/hooks/useFocusedItem.d.ts +1 -12
  80. package/hooks/useFocusedItem.js +1 -10
  81. package/hooks/useIsItemFocused.d.ts +4 -3
  82. package/hooks/useIsItemFocused.js +1 -1
  83. package/hooks/useIsItemFocusedGetter.d.ts +3 -2
  84. package/hooks/useIsItemFocusedGetter.js +2 -1
  85. package/index.js +1 -1
  86. package/internals/commonNextFocusItem.d.ts +14 -0
  87. package/internals/commonNextFocusItem.js +93 -0
  88. package/internals/index.d.ts +1 -1
  89. package/internals/index.js +4 -4
  90. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.d.ts +13 -0
  91. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.js +5 -0
  92. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.d.ts +2 -2
  93. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +11 -104
  94. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +5 -31
  95. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +10 -16
  96. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +6 -21
  97. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.d.ts +15 -0
  98. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +51 -0
  99. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.d.ts +11 -0
  100. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +46 -0
  101. package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +1 -9
  102. package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.js +1 -1
  103. package/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +2 -0
  104. package/internals/plugins/models/seriesConfig/seriesProcessor.types.d.ts +1 -1
  105. package/internals/seriesHasData.d.ts +4 -0
  106. package/internals/seriesHasData.js +14 -0
  107. package/internals/stacking/index.d.ts +1 -0
  108. package/internals/stacking/index.js +16 -0
  109. package/internals/stacking/offset/index.d.ts +1 -0
  110. package/internals/stacking/offset/index.js +16 -0
  111. package/internals/stacking/offset/offsetDiverging.d.ts +8 -0
  112. package/internals/stacking/offset/offsetDiverging.js +53 -0
  113. package/internals/{stackSeries.d.ts → stacking/stackSeries.d.ts} +8 -8
  114. package/internals/{stackSeries.js → stacking/stackSeries.js} +3 -1
  115. package/models/seriesType/index.d.ts +3 -1
  116. package/package.json +4 -4
  117. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.d.ts +0 -3
  118. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.js +0 -4
  119. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.d.ts +0 -21
  120. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.js +0 -92
  121. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.d.ts +0 -3
  122. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.js +0 -10
  123. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.d.ts +0 -21
  124. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.js +0 -99
@@ -1,15 +1,4 @@
1
- import { type ChartSeriesType } from "../models/seriesType/config.js";
2
- import { type SeriesId } from "../models/seriesType/common.js";
3
- export type FocusedItemData = {
4
- seriesType: ChartSeriesType;
5
- seriesId: SeriesId;
6
- dataIndex: number;
7
- };
8
1
  /**
9
2
  * Get the focused item from keyboard navigation.
10
3
  */
11
- export declare function useFocusedItem(): {
12
- seriesType: "line" | "bar" | "scatter" | "pie";
13
- seriesId: SeriesId;
14
- dataIndex: number;
15
- } | null;
4
+ export declare function useFocusedItem(): import("../index.js").FocusedItemIdentifier<keyof import("../internals/index.js").ChartsSeriesConfig> | null;
@@ -1,19 +1,12 @@
1
1
  'use client';
2
2
 
3
- import * as React from 'react';
4
3
  import { useStore } from "../internals/store/useStore.js";
5
- import { selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex } from "../internals/plugins/featurePlugins/useChartKeyboardNavigation/index.js";
4
+ import { selectorChartsFocusedItem } from "../internals/plugins/featurePlugins/useChartKeyboardNavigation/index.js";
5
+
6
6
  /**
7
7
  * Get the focused item from keyboard navigation.
8
8
  */
9
9
  export function useFocusedItem() {
10
10
  const store = useStore();
11
- const focusedSeriesType = store.use(selectorChartsFocusedSeriesType);
12
- const focusedSeriesId = store.use(selectorChartsFocusedSeriesId);
13
- const focusedDataIndex = store.use(selectorChartsFocusedDataIndex);
14
- return React.useMemo(() => focusedSeriesType === undefined || focusedSeriesId === undefined || focusedDataIndex === undefined ? null : {
15
- seriesType: focusedSeriesType,
16
- seriesId: focusedSeriesId,
17
- dataIndex: focusedDataIndex
18
- }, [focusedSeriesType, focusedSeriesId, focusedDataIndex]);
11
+ return store.use(selectorChartsFocusedItem);
19
12
  }
@@ -1,11 +1,12 @@
1
- import { type FocusedItemData } from "./useFocusedItem.js";
2
- type UseItemFocusedParams = FocusedItemData;
1
+ import type { ChartSeriesType } from "../models/seriesType/config.js";
2
+ import type { FocusedItemIdentifier } from "../models/seriesType/index.js";
3
+ type UseItemFocusedParams = FocusedItemIdentifier<ChartSeriesType>;
3
4
  /**
4
5
  * A hook to check if an item has the focus.
5
6
  *
6
7
  * If you need to process multiple points, use the `useIsItemFocusedGetter` hook instead.
7
8
  *
8
- * @param {FocusedItemData} item is the item to check
9
+ * @param {FocusedItemIdentifier} item is the item to check
9
10
  * @returns {boolean} the focus state
10
11
  */
11
12
  export declare function useIsItemFocused(item: UseItemFocusedParams): boolean;
@@ -7,7 +7,7 @@ import { selectorChartsItemIsFocused } from "../internals/plugins/featurePlugins
7
7
  *
8
8
  * If you need to process multiple points, use the `useIsItemFocusedGetter` hook instead.
9
9
  *
10
- * @param {FocusedItemData} item is the item to check
10
+ * @param {FocusedItemIdentifier} item is the item to check
11
11
  * @returns {boolean} the focus state
12
12
  */
13
13
  export function useIsItemFocused(item) {
@@ -1,8 +1,9 @@
1
- import { type FocusedItemData } from "./useFocusedItem.js";
1
+ import type { FocusedItemIdentifier } from "../models/seriesType/index.js";
2
+ import type { ChartSeriesType } from "../models/seriesType/config.js";
2
3
  /**
3
4
  * A hook to check focus state of multiple items.
4
5
  * If you're interested by a single one, consider using `useIsItemFocused`.
5
6
  *
6
7
  * @returns {(item: FocusedItemData) => boolean} callback to get the state of the item.
7
8
  */
8
- export declare function useIsItemFocusedGetter(): (item: FocusedItemData) => boolean;
9
+ export declare function useIsItemFocusedGetter(): (item: FocusedItemIdentifier<ChartSeriesType>) => boolean;
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
 
3
+ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
3
4
  import { useFocusedItem } from "./useFocusedItem.js";
4
5
 
5
6
  /**
@@ -10,5 +11,5 @@ import { useFocusedItem } from "./useFocusedItem.js";
10
11
  */
11
12
  export function useIsItemFocusedGetter() {
12
13
  const focusedItem = useFocusedItem();
13
- return item => focusedItem !== null && focusedItem.seriesType === item.seriesType && focusedItem.seriesId === item.seriesId && focusedItem.dataIndex === item.dataIndex;
14
+ return item => focusedItem !== null && fastObjectShallowCompare(focusedItem, item);
14
15
  }
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.22.1
2
+ * @mui/x-charts v8.23.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1,14 @@
1
+ import type { UseChartKeyboardNavigationSignature } from "./plugins/featurePlugins/useChartKeyboardNavigation/index.js";
2
+ import type { ChartState } from "./plugins/models/chart.js";
3
+ import type { ChartSeriesType } from "../models/seriesType/config.js";
4
+ import type { FocusedItemIdentifier, SeriesId, SeriesItemIdentifier } from "../models/seriesType/index.js";
5
+ type ReturnedItem<OutSeriesType extends ChartSeriesType> = {
6
+ type: OutSeriesType;
7
+ seriesId: SeriesId;
8
+ dataIndex: number;
9
+ } | null;
10
+ export declare function createGetNextIndexFocusedItem<InSeriesType extends Exclude<ChartSeriesType, 'sankey'>, OutSeriesType extends Exclude<ChartSeriesType, 'sankey'> = InSeriesType>(compatibleSeriesTypes: Set<OutSeriesType>): (currentItem: FocusedItemIdentifier<InSeriesType> | null, state: ChartState<[UseChartKeyboardNavigationSignature], []>) => ReturnedItem<OutSeriesType>;
11
+ export declare function createGetPreviousIndexFocusedItem<InSeriesType extends Exclude<ChartSeriesType, 'sankey'>, OutSeriesType extends Exclude<ChartSeriesType, 'sankey'> = InSeriesType>(compatibleSeriesTypes: Set<OutSeriesType>): (currentItem: SeriesItemIdentifier<InSeriesType> | null, state: ChartState<[UseChartKeyboardNavigationSignature], []>) => ReturnedItem<OutSeriesType>;
12
+ export declare function createGetNextSeriesFocusedItem<InSeriesType extends Exclude<ChartSeriesType, 'sankey'>, OutSeriesType extends Exclude<ChartSeriesType, 'sankey'> = InSeriesType>(compatibleSeriesTypes: Set<OutSeriesType>): (currentItem: SeriesItemIdentifier<InSeriesType> | null, state: ChartState<[UseChartKeyboardNavigationSignature], []>) => ReturnedItem<OutSeriesType>;
13
+ export declare function createGetPreviousSeriesFocusedItem<InSeriesType extends Exclude<ChartSeriesType, 'sankey'>, OutSeriesType extends Exclude<ChartSeriesType, 'sankey'> = InSeriesType>(compatibleSeriesTypes: Set<OutSeriesType>): (currentItem: SeriesItemIdentifier<InSeriesType> | null, state: ChartState<[UseChartKeyboardNavigationSignature], []>) => ReturnedItem<OutSeriesType>;
14
+ export {};
@@ -0,0 +1,84 @@
1
+ import { getPreviousNonEmptySeries } from "./plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js";
2
+ import { selectorChartSeriesProcessed } from "./plugins/corePlugins/useChartSeries/index.js";
3
+ import { getNextNonEmptySeries } from "./plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js";
4
+ import { seriesHasData } from "./seriesHasData.js";
5
+ export function createGetNextIndexFocusedItem(compatibleSeriesTypes) {
6
+ return function getNextIndexFocusedItem(currentItem, state) {
7
+ const processedSeries = selectorChartSeriesProcessed(state);
8
+ let seriesId = currentItem?.seriesId;
9
+ let type = currentItem?.type;
10
+ if (!type || seriesId == null || !seriesHasData(processedSeries, type, seriesId)) {
11
+ const nextSeries = getNextNonEmptySeries(processedSeries, compatibleSeriesTypes, type, seriesId);
12
+ if (nextSeries === null) {
13
+ return null;
14
+ }
15
+ type = nextSeries.type;
16
+ seriesId = nextSeries.seriesId;
17
+ }
18
+ const dataLength = processedSeries[type].series[seriesId].data.length;
19
+ return {
20
+ type,
21
+ seriesId,
22
+ dataIndex: ((currentItem?.dataIndex ?? -1) + 1) % dataLength
23
+ };
24
+ };
25
+ }
26
+ export function createGetPreviousIndexFocusedItem(compatibleSeriesTypes) {
27
+ return function getPreviousIndexFocusedItem(currentItem, state) {
28
+ const processedSeries = selectorChartSeriesProcessed(state);
29
+ let seriesId = currentItem?.seriesId;
30
+ let type = currentItem?.type;
31
+ if (!type || seriesId == null || !seriesHasData(processedSeries, type, seriesId)) {
32
+ const previousSeries = getPreviousNonEmptySeries(processedSeries, compatibleSeriesTypes, type, seriesId);
33
+ if (previousSeries === null) {
34
+ return null;
35
+ }
36
+ type = previousSeries.type;
37
+ seriesId = previousSeries.seriesId;
38
+ }
39
+ const dataLength = processedSeries[type].series[seriesId].data.length;
40
+ return {
41
+ type,
42
+ seriesId,
43
+ dataIndex: (dataLength + (currentItem?.dataIndex ?? 1) - 1) % dataLength
44
+ };
45
+ };
46
+ }
47
+ export function createGetNextSeriesFocusedItem(compatibleSeriesTypes) {
48
+ return function getNextSeriesFocusedItem(currentItem, state) {
49
+ const processedSeries = selectorChartSeriesProcessed(state);
50
+ let seriesId = currentItem?.seriesId;
51
+ let type = currentItem?.type;
52
+ const nextSeries = getNextNonEmptySeries(processedSeries, compatibleSeriesTypes, type, seriesId);
53
+ if (nextSeries === null) {
54
+ return null; // No series to move the focus to.
55
+ }
56
+ type = nextSeries.type;
57
+ seriesId = nextSeries.seriesId;
58
+ const dataLength = processedSeries[type].series[seriesId].data.length;
59
+ return {
60
+ type,
61
+ seriesId,
62
+ dataIndex: Math.min(dataLength - 1, currentItem?.dataIndex ?? 0)
63
+ };
64
+ };
65
+ }
66
+ export function createGetPreviousSeriesFocusedItem(compatibleSeriesTypes) {
67
+ return function getPreviousSeriesFocusedItem(currentItem, state) {
68
+ const processedSeries = selectorChartSeriesProcessed(state);
69
+ let seriesId = currentItem?.seriesId;
70
+ let type = currentItem?.type;
71
+ const previousSeries = getPreviousNonEmptySeries(processedSeries, compatibleSeriesTypes, type, seriesId);
72
+ if (previousSeries === null) {
73
+ return null; // No series to move the focus to.
74
+ }
75
+ type = previousSeries.type;
76
+ seriesId = previousSeries.seriesId;
77
+ const dataLength = processedSeries[type].series[seriesId].data.length;
78
+ return {
79
+ type,
80
+ seriesId,
81
+ dataIndex: Math.min(dataLength - 1, currentItem?.dataIndex ?? 0)
82
+ };
83
+ };
84
+ }
@@ -47,7 +47,7 @@ export * from "./getLabel.js";
47
47
  export * from "./getSVGPoint.js";
48
48
  export * from "./isDefined.js";
49
49
  export * from "./getScale.js";
50
- export * from "./stackSeries.js";
50
+ export * from "./stacking/index.js";
51
51
  export * from "./getCurve.js";
52
52
  export * from "./consumeSlots.js";
53
53
  export * from "./consumeThemeProps.js";
@@ -57,7 +57,7 @@ export * from "./getLabel.js";
57
57
  export * from "./getSVGPoint.js";
58
58
  export * from "./isDefined.js";
59
59
  export * from "./getScale.js";
60
- export * from "./stackSeries.js";
60
+ export * from "./stacking/index.js";
61
61
  export * from "./getCurve.js";
62
62
  export * from "./consumeSlots.js";
63
63
  export * from "./consumeThemeProps.js";
@@ -0,0 +1,13 @@
1
+ import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
2
+ import type { FocusedItemIdentifier } from "../../../../models/seriesType/index.js";
3
+ import type { UseChartKeyboardNavigationSignature } from "./useChartKeyboardNavigation.types.js";
4
+ import type { ChartState } from "../../models/chart.js";
5
+ export type FocusedItemUpdater<TSeriesType extends ChartSeriesType, OutputSeriesType extends ChartSeriesType = ChartSeriesType> = (currentItem: (TSeriesType extends any ? FocusedItemIdentifier<TSeriesType> : never) | null, state: ChartState<[UseChartKeyboardNavigationSignature], []>) => FocusedItemIdentifier<OutputSeriesType> | null;
6
+ /**
7
+ * Get the next focusable item in the chart.
8
+ * @param {SeriesItemIdentifier<TSeriesType> | null} currentItem The current focused item.
9
+ * @param {KeyboardEvent} event The keyboard event that triggered the navigation.
10
+ * @param {ChartState<[UseChartKeyboardNavigationSignature], []>} state The current chart state.
11
+ * @returns {SeriesItemIdentifier<ChartSeriesType> | null} The next focusable item or null if none found.
12
+ */
13
+ export type KeyboardFocusHandler<TSeriesType extends ChartSeriesType, OutputSeriesType extends ChartSeriesType = ChartSeriesType> = (event: KeyboardEvent) => FocusedItemUpdater<TSeriesType, OutputSeriesType> | null;
@@ -1,3 +1,3 @@
1
- import { type ChartPlugin } from "../../models/index.js";
2
- import { type UseChartKeyboardNavigationSignature } from "./useChartKeyboardNavigation.types.js";
1
+ import type { ChartPlugin } from "../../models/index.js";
2
+ import type { UseChartKeyboardNavigationSignature } from "./useChartKeyboardNavigation.types.js";
3
3
  export declare const useChartKeyboardNavigation: ChartPlugin<UseChartKeyboardNavigationSignature>;
@@ -4,92 +4,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import useEventCallback from '@mui/utils/useEventCallback';
6
6
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
- import { getNextSeriesWithData, getPreviousSeriesWithData, seriesHasData } from "./useChartKeyboardNavigation.helpers.js";
8
- import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
9
- function getNextIndexFocusedItem(state) {
10
- const processedSeries = selectorChartSeriesProcessed(state);
11
- let {
12
- type,
13
- seriesId
14
- } = state.keyboardNavigation.item ?? {};
15
- if (type === undefined ||
16
- // @ts-ignore sankey is not in MIT version
17
- type === 'sankey' || seriesId === undefined || !seriesHasData(processedSeries, type, seriesId)) {
18
- const nextSeries = getNextSeriesWithData(processedSeries, type, seriesId);
19
- if (nextSeries === null) {
20
- return null;
21
- }
22
- type = nextSeries.type;
23
- seriesId = nextSeries.seriesId;
24
- }
25
- const dataLength = processedSeries[type].series[seriesId].data.length;
26
- return {
27
- type,
28
- seriesId,
29
- dataIndex: ((state.keyboardNavigation.item?.dataIndex ?? -1) + 1) % dataLength
30
- };
31
- }
32
- function getPreviousIndexFocusedItem(state) {
33
- const processedSeries = selectorChartSeriesProcessed(state);
34
- let {
35
- type,
36
- seriesId
37
- } = state.keyboardNavigation.item ?? {};
38
- if (type === undefined ||
39
- // @ts-ignore sankey is not in MIT version
40
- type === 'sankey' || seriesId === undefined || !seriesHasData(processedSeries, type, seriesId)) {
41
- const previousSeries = getPreviousSeriesWithData(processedSeries, type, seriesId);
42
- if (previousSeries === null) {
43
- return null;
44
- }
45
- type = previousSeries.type;
46
- seriesId = previousSeries.seriesId;
47
- }
48
- const dataLength = processedSeries[type].series[seriesId].data.length;
49
- return {
50
- type,
51
- seriesId,
52
- dataIndex: (dataLength + (state.keyboardNavigation.item?.dataIndex ?? 1) - 1) % dataLength
53
- };
54
- }
55
- function getNextSeriesFocusedItem(state) {
56
- const processedSeries = selectorChartSeriesProcessed(state);
57
- let {
58
- type,
59
- seriesId
60
- } = state.keyboardNavigation.item ?? {};
61
- const nextSeries = getNextSeriesWithData(processedSeries, type, seriesId);
62
- if (nextSeries === null) {
63
- return null; // No series to move the focus to.
64
- }
65
- type = nextSeries.type;
66
- seriesId = nextSeries.seriesId;
67
- const dataLength = processedSeries[type].series[seriesId].data.length;
68
- return {
69
- type,
70
- seriesId,
71
- dataIndex: Math.min(dataLength - 1, state.keyboardNavigation.item?.dataIndex ?? 0)
72
- };
73
- }
74
- function getPreviousSeriesFocusedItem(state) {
75
- const processedSeries = selectorChartSeriesProcessed(state);
76
- let {
77
- type,
78
- seriesId
79
- } = state.keyboardNavigation.item ?? {};
80
- const previousSeries = getPreviousSeriesWithData(processedSeries, type, seriesId);
81
- if (previousSeries === null) {
82
- return null; // No series to move the focus to.
83
- }
84
- type = previousSeries.type;
85
- seriesId = previousSeries.seriesId;
86
- const dataLength = processedSeries[type].series[seriesId].data.length;
87
- return {
88
- type,
89
- seriesId,
90
- dataIndex: Math.min(dataLength - 1, state.keyboardNavigation.item?.dataIndex ?? 0)
91
- };
92
- }
7
+ import { selectorChartDefaultizedSeries } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
93
8
  export const useChartKeyboardNavigation = ({
94
9
  params,
95
10
  store,
@@ -109,26 +24,18 @@ export const useChartKeyboardNavigation = ({
109
24
  }
110
25
  function keyboardHandler(event) {
111
26
  let newFocusedItem = store.state.keyboardNavigation.item;
112
- switch (event.key) {
113
- case 'ArrowRight':
114
- newFocusedItem = getNextIndexFocusedItem(store.state);
115
- break;
116
- case 'ArrowLeft':
117
- newFocusedItem = getPreviousIndexFocusedItem(store.state);
118
- break;
119
- case 'ArrowDown':
120
- {
121
- newFocusedItem = getPreviousSeriesFocusedItem(store.state);
122
- break;
123
- }
124
- case 'ArrowUp':
125
- {
126
- newFocusedItem = getNextSeriesFocusedItem(store.state);
127
- break;
128
- }
129
- default:
130
- break;
27
+ let seriesType = newFocusedItem?.type;
28
+ if (!seriesType) {
29
+ seriesType = Object.keys(selectorChartDefaultizedSeries(store.state)).find(key => store.state.series.seriesConfig[key] !== undefined);
30
+ if (seriesType === undefined) {
31
+ return;
32
+ }
33
+ }
34
+ const calculateFocusedItem = store.state.series.seriesConfig[seriesType]?.keyboardFocusHandler?.(event);
35
+ if (!calculateFocusedItem) {
36
+ return;
131
37
  }
38
+ newFocusedItem = calculateFocusedItem(newFocusedItem, store.state);
132
39
  if (newFocusedItem !== store.state.keyboardNavigation.item) {
133
40
  event.preventDefault();
134
41
  store.update(_extends({}, store.state.highlight && {
@@ -1,21 +1,14 @@
1
- import { type SeriesId } from "../../../../models/seriesType/common.js";
1
+ import type { FocusedItemIdentifier } from "../../../../models/seriesType/index.js";
2
2
  import { type AxisItemIdentifier } from "../../../../models/axis.js";
3
- import { type FocusedItemData } from "../../../../hooks/useFocusedItem.js";
4
3
  export declare const selectorChartsItemIsFocused: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
5
4
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
6
- }, item: FocusedItemData) => boolean;
5
+ }, item: FocusedItemIdentifier<keyof import("../../../index.js").ChartsSeriesConfig>) => boolean;
7
6
  export declare const selectorChartsHasFocusedItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
8
7
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
9
8
  }) => boolean;
10
- export declare const selectorChartsFocusedSeriesType: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
9
+ export declare const selectorChartsFocusedItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
11
10
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
12
- }) => "line" | "bar" | "scatter" | "pie" | undefined;
13
- export declare const selectorChartsFocusedSeriesId: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
14
- cacheKey: import("../../models/index.js").ChartStateCacheKey;
15
- }) => SeriesId | undefined;
16
- export declare const selectorChartsFocusedDataIndex: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
17
- cacheKey: import("../../models/index.js").ChartStateCacheKey;
18
- }) => number | undefined;
11
+ }) => FocusedItemIdentifier<keyof import("../../../index.js").ChartsSeriesConfig> | null;
19
12
  export declare const selectorChartsIsKeyboardNavigationEnabled: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
20
13
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
21
14
  }) => boolean;
@@ -27,23 +20,4 @@ export declare const selectorChartsKeyboardYAxisIndex: (args_0: import("../../co
27
20
  }) => AxisItemIdentifier | undefined;
28
21
  export declare const selectorChartsKeyboardItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
29
22
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
30
- }) => {
31
- type: "line";
32
- seriesId: SeriesId;
33
- dataIndex: number;
34
- } | {
35
- type: "bar";
36
- seriesId: SeriesId;
37
- dataIndex: number;
38
- } | {
39
- type: "scatter";
40
- seriesId: SeriesId;
41
- dataIndex: number;
42
- } | {
43
- type: "pie";
44
- seriesId: SeriesId;
45
- dataIndex: number;
46
- } | null;
47
- export declare const selectorChartsKeyboardItemIsDefined: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
48
- cacheKey: import("../../models/index.js").ChartStateCacheKey;
49
- }) => boolean;
23
+ }) => FocusedItemIdentifier<keyof import("../../../index.js").ChartsSeriesConfig> | null;
@@ -1,25 +1,22 @@
1
1
  import { createSelector } from '@mui/x-internals/store';
2
+ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
2
3
  import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
3
4
  import { selectorChartXAxis, selectorChartYAxis } from "../useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js";
4
5
  const selectKeyboardNavigation = state => state.keyboardNavigation;
5
- export const selectorChartsItemIsFocused = createSelector(selectKeyboardNavigation, (keyboardNavigationState, item) => {
6
- return keyboardNavigationState?.item != null && keyboardNavigationState.item.type === item.seriesType && keyboardNavigationState.item.seriesId === item.seriesId && keyboardNavigationState.item.dataIndex === item.dataIndex;
7
- });
6
+ export const selectorChartsItemIsFocused = createSelector(selectKeyboardNavigation, (keyboardNavigationState, item) => keyboardNavigationState?.item != null && fastObjectShallowCompare(keyboardNavigationState.item, item));
8
7
  export const selectorChartsHasFocusedItem = createSelector(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item != null);
9
- export const selectorChartsFocusedSeriesType = createSelector(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item?.type);
10
- export const selectorChartsFocusedSeriesId = createSelector(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item?.seriesId);
11
- export const selectorChartsFocusedDataIndex = createSelector(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item?.dataIndex);
8
+ export const selectorChartsFocusedItem = createSelector(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item ?? null);
12
9
  export const selectorChartsIsKeyboardNavigationEnabled = createSelector(selectKeyboardNavigation, keyboardNavigationState => !!keyboardNavigationState?.enableKeyboardNavigation);
13
10
 
14
11
  /**
15
12
  * Selectors to override highlight behavior.
16
13
  */
17
14
 
18
- const createSelectAxisHighlight = direction => (type, seriesId, dataIndex, axis, series) => {
19
- if (type === undefined || seriesId === undefined || dataIndex === undefined) {
15
+ const createSelectAxisHighlight = direction => (item, axis, series) => {
16
+ if (item == null || !('dataIndex' in item) || item.dataIndex === undefined) {
20
17
  return undefined;
21
18
  }
22
- const seriesConfig = series[type]?.series[seriesId];
19
+ const seriesConfig = series[item.type]?.series[item.seriesId];
23
20
  if (!seriesConfig) {
24
21
  return undefined;
25
22
  }
@@ -29,11 +26,11 @@ const createSelectAxisHighlight = direction => (type, seriesId, dataIndex, axis,
29
26
  }
30
27
  return {
31
28
  axisId,
32
- dataIndex
29
+ dataIndex: item.dataIndex
33
30
  };
34
31
  };
35
- export const selectorChartsKeyboardXAxisIndex = createSelector(selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex, selectorChartXAxis, selectorChartSeriesProcessed, createSelectAxisHighlight('x'));
36
- export const selectorChartsKeyboardYAxisIndex = createSelector(selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex, selectorChartYAxis, selectorChartSeriesProcessed, createSelectAxisHighlight('y'));
32
+ export const selectorChartsKeyboardXAxisIndex = createSelector(selectorChartsFocusedItem, selectorChartXAxis, selectorChartSeriesProcessed, createSelectAxisHighlight('x'));
33
+ export const selectorChartsKeyboardYAxisIndex = createSelector(selectorChartsFocusedItem, selectorChartYAxis, selectorChartSeriesProcessed, createSelectAxisHighlight('y'));
37
34
  export const selectorChartsKeyboardItem = createSelector(selectKeyboardNavigation, function selectorChartsKeyboardItem(keyboardState) {
38
35
  if (keyboardState?.item == null) {
39
36
  return null;
@@ -46,7 +43,4 @@ export const selectorChartsKeyboardItem = createSelector(selectKeyboardNavigatio
46
43
  return null;
47
44
  }
48
45
  return keyboardState.item;
49
- });
50
- export const selectorChartsKeyboardItemIsDefined = createSelector(selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex, function selectorChartsKeyboardItemIsDefined(seriesType, seriesId, dataIndex) {
51
- return seriesId !== undefined && dataIndex !== undefined;
52
46
  });
@@ -1,27 +1,12 @@
1
- import { type ChartPluginSignature } from "../../models/index.js";
2
- import { type ChartSeriesType } from "../../../../models/seriesType/config.js";
3
- import { type SeriesId } from "../../../../models/seriesType/common.js";
4
- import { type UseChartInteractionSignature } from "../useChartInteraction/index.js";
5
- import { type UseChartHighlightSignature } from "../useChartHighlight/index.js";
1
+ import type { ChartPluginSignature } from "../../models/index.js";
2
+ import type { UseChartInteractionSignature } from "../useChartInteraction/index.js";
3
+ import type { UseChartHighlightSignature } from "../useChartHighlight/index.js";
4
+ import type { FocusedItemIdentifier } from "../../../../models/seriesType/index.js";
5
+ import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
6
6
  export interface UseChartKeyboardNavigationInstance {}
7
- type SeriesItemIdentifier<SeriesType extends ChartSeriesType = FocusableSeriesTypes> = SeriesType extends FocusableSeriesTypes ? {
8
- /**
9
- * The type of the series
10
- */
11
- type: SeriesType;
12
- /**
13
- * The id of the series with focus.
14
- */
15
- seriesId: SeriesId;
16
- /**
17
- * The index of the data point with focus.
18
- */
19
- dataIndex: number;
20
- } : never;
21
- export type FocusableSeriesTypes = 'bar' | 'line' | 'scatter' | 'pie';
22
7
  export interface UseChartKeyboardNavigationState {
23
8
  keyboardNavigation: {
24
- item: null | SeriesItemIdentifier;
9
+ item: null | FocusedItemIdentifier<ChartSeriesType>;
25
10
  enableKeyboardNavigation: boolean;
26
11
  };
27
12
  }
@@ -0,0 +1,15 @@
1
+ import type { ChartSeriesType } from "../../../../../models/seriesType/config.js";
2
+ import type { SeriesId } from "../../../../../models/seriesType/common.js";
3
+ import type { ProcessedSeries } from "../../../corePlugins/useChartSeries/index.js";
4
+ /**
5
+ * Returns the next series type and id that contains some data.
6
+ * Returns `null` if no other series have data.
7
+ * @param series - The processed series from the store.
8
+ * @param availableSeriesTypes - The set of series types that can be focused.
9
+ * @param type - The current series type.
10
+ * @param seriesId - The current series id.
11
+ */
12
+ export declare function getNextNonEmptySeries<OutSeriesType extends Exclude<ChartSeriesType, 'sankey'> = Exclude<ChartSeriesType, 'sankey'>>(series: ProcessedSeries<ChartSeriesType>, availableSeriesTypes: Set<OutSeriesType>, type?: ChartSeriesType, seriesId?: SeriesId): {
13
+ type: OutSeriesType;
14
+ seriesId: SeriesId;
15
+ } | null;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Returns the next series type and id that contains some data.
3
+ * Returns `null` if no other series have data.
4
+ * @param series - The processed series from the store.
5
+ * @param availableSeriesTypes - The set of series types that can be focused.
6
+ * @param type - The current series type.
7
+ * @param seriesId - The current series id.
8
+ */
9
+ export function getNextNonEmptySeries(series, availableSeriesTypes, type, seriesId) {
10
+ const seriesType = Object.keys(series);
11
+ const currentSeriesIndex = type !== undefined && seriesId !== undefined && series[type] && series[type].series[seriesId] ? series[type].seriesOrder.indexOf(seriesId) : -1;
12
+ const typesAvailable = seriesType.filter(t => availableSeriesTypes?.has(t));
13
+ const startingTypeIndex = type !== undefined && series[type] ? typesAvailable.indexOf(type) : 0;
14
+
15
+ // Loop over all series types starting with the current seriesType
16
+ for (let typeGap = 0; typeGap < typesAvailable.length; typeGap += 1) {
17
+ const typeIndex = (startingTypeIndex + typeGap) % typesAvailable.length;
18
+ const seriesOfType = series[typesAvailable[typeIndex]];
19
+
20
+ // Edge case for the current series type: we don't loop on previous series of the same type.
21
+ const startingSeriesIndex = typeGap === 0 ? currentSeriesIndex + 1 : 0;
22
+ for (let seriesIndex = startingSeriesIndex; seriesIndex < seriesOfType.seriesOrder.length; seriesIndex += 1) {
23
+ if (seriesOfType.series[seriesOfType.seriesOrder[seriesIndex]].data.length > 0) {
24
+ return {
25
+ type: typesAvailable[typeIndex],
26
+ seriesId: seriesOfType.seriesOrder[seriesIndex]
27
+ };
28
+ }
29
+ }
30
+ }
31
+
32
+ // End looping on the initial type up to the initial series (excluded)
33
+ const typeIndex = startingTypeIndex;
34
+ const seriesOfType = series[typesAvailable[typeIndex]];
35
+ const endingSeriesIndex = currentSeriesIndex;
36
+ for (let seriesIndex = 0; seriesIndex < endingSeriesIndex; seriesIndex += 1) {
37
+ if (seriesOfType.series[seriesOfType.seriesOrder[seriesIndex]].data.length > 0) {
38
+ return {
39
+ type: typesAvailable[typeIndex],
40
+ seriesId: seriesOfType.seriesOrder[seriesIndex]
41
+ };
42
+ }
43
+ }
44
+ return null;
45
+ }
@@ -0,0 +1,11 @@
1
+ import type { ChartSeriesType } from "../../../../../models/seriesType/config.js";
2
+ import type { SeriesId } from "../../../../../models/seriesType/common.js";
3
+ import type { ProcessedSeries } from "../../../corePlugins/useChartSeries/index.js";
4
+ /**
5
+ * Returns the previous series type and id that contains some data.
6
+ * Returns `null` if no other series have data.
7
+ */
8
+ export declare function getPreviousNonEmptySeries<OutSeriesType extends Exclude<ChartSeriesType, 'sankey'> = Exclude<ChartSeriesType, 'sankey'>>(series: ProcessedSeries<ChartSeriesType>, availableSeriesTypes: Set<OutSeriesType>, type?: ChartSeriesType, seriesId?: SeriesId): {
9
+ type: OutSeriesType;
10
+ seriesId: SeriesId;
11
+ } | null;