@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.
- package/BarChart/BarElement.js +1 -1
- package/BarChart/FocusedBar.js +1 -1
- package/BarChart/seriesConfig/bar/keyboardFocusHandler.d.ts +3 -0
- package/BarChart/seriesConfig/bar/keyboardFocusHandler.js +23 -0
- package/BarChart/seriesConfig/bar/seriesProcessor.js +2 -2
- package/BarChart/seriesConfig/index.js +3 -1
- package/CHANGELOG.md +101 -0
- package/LineChart/FocusedLineMark.js +1 -1
- package/LineChart/seriesConfig/index.js +3 -1
- package/LineChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
- package/LineChart/seriesConfig/keyboardFocusHandler.js +23 -0
- package/LineChart/seriesConfig/seriesProcessor.js +2 -2
- package/PieChart/FocusedPieArc.js +1 -1
- package/PieChart/dataTransform/useTransformData.js +1 -1
- package/PieChart/seriesConfig/index.js +3 -1
- package/PieChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
- package/PieChart/seriesConfig/keyboardFocusHandler.js +23 -0
- package/ScatterChart/FocusedScatterMark.js +1 -1
- package/ScatterChart/seriesConfig/index.js +3 -1
- package/ScatterChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
- package/ScatterChart/seriesConfig/keyboardFocusHandler.js +23 -0
- package/esm/BarChart/BarElement.js +1 -1
- package/esm/BarChart/FocusedBar.js +1 -1
- package/esm/BarChart/seriesConfig/bar/keyboardFocusHandler.d.ts +3 -0
- package/esm/BarChart/seriesConfig/bar/keyboardFocusHandler.js +17 -0
- package/esm/BarChart/seriesConfig/bar/seriesProcessor.js +1 -1
- package/esm/BarChart/seriesConfig/index.js +3 -1
- package/esm/LineChart/FocusedLineMark.js +1 -1
- package/esm/LineChart/seriesConfig/index.js +3 -1
- package/esm/LineChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
- package/esm/LineChart/seriesConfig/keyboardFocusHandler.js +17 -0
- package/esm/LineChart/seriesConfig/seriesProcessor.js +1 -1
- package/esm/PieChart/FocusedPieArc.js +1 -1
- package/esm/PieChart/dataTransform/useTransformData.js +1 -1
- package/esm/PieChart/seriesConfig/index.js +3 -1
- package/esm/PieChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
- package/esm/PieChart/seriesConfig/keyboardFocusHandler.js +17 -0
- package/esm/ScatterChart/FocusedScatterMark.js +1 -1
- package/esm/ScatterChart/seriesConfig/index.js +3 -1
- package/esm/ScatterChart/seriesConfig/keyboardFocusHandler.d.ts +3 -0
- package/esm/ScatterChart/seriesConfig/keyboardFocusHandler.js +17 -0
- package/esm/hooks/useFocusedItem.d.ts +1 -12
- package/esm/hooks/useFocusedItem.js +3 -10
- package/esm/hooks/useIsItemFocused.d.ts +4 -3
- package/esm/hooks/useIsItemFocused.js +1 -1
- package/esm/hooks/useIsItemFocusedGetter.d.ts +3 -2
- package/esm/hooks/useIsItemFocusedGetter.js +2 -1
- package/esm/index.js +1 -1
- package/esm/internals/commonNextFocusItem.d.ts +14 -0
- package/esm/internals/commonNextFocusItem.js +84 -0
- package/esm/internals/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.d.ts +13 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.js +1 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.d.ts +2 -2
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +12 -105
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +5 -31
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +9 -15
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +6 -21
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.d.ts +15 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +45 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.d.ts +11 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +40 -0
- package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +1 -9
- package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.js +2 -2
- package/esm/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +2 -0
- package/esm/internals/plugins/models/seriesConfig/seriesProcessor.types.d.ts +1 -1
- package/esm/internals/seriesHasData.d.ts +4 -0
- package/esm/internals/seriesHasData.js +8 -0
- package/esm/internals/stacking/index.d.ts +1 -0
- package/esm/internals/stacking/index.js +1 -0
- package/esm/internals/stacking/offset/index.d.ts +1 -0
- package/esm/internals/stacking/offset/index.js +1 -0
- package/esm/internals/stacking/offset/offsetDiverging.d.ts +8 -0
- package/esm/internals/stacking/offset/offsetDiverging.js +47 -0
- package/esm/internals/{stackSeries.d.ts → stacking/stackSeries.d.ts} +8 -8
- package/esm/internals/{stackSeries.js → stacking/stackSeries.js} +8 -6
- package/esm/models/seriesType/index.d.ts +3 -1
- package/hooks/useFocusedItem.d.ts +1 -12
- package/hooks/useFocusedItem.js +1 -10
- package/hooks/useIsItemFocused.d.ts +4 -3
- package/hooks/useIsItemFocused.js +1 -1
- package/hooks/useIsItemFocusedGetter.d.ts +3 -2
- package/hooks/useIsItemFocusedGetter.js +2 -1
- package/index.js +1 -1
- package/internals/commonNextFocusItem.d.ts +14 -0
- package/internals/commonNextFocusItem.js +93 -0
- package/internals/index.d.ts +1 -1
- package/internals/index.js +4 -4
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.d.ts +13 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/keyboardFocusHandler.types.js +5 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.d.ts +2 -2
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +11 -104
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +5 -31
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +10 -16
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +6 -21
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.d.ts +15 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +51 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.d.ts +11 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +46 -0
- package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +1 -9
- package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.js +1 -1
- package/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +2 -0
- package/internals/plugins/models/seriesConfig/seriesProcessor.types.d.ts +1 -1
- package/internals/seriesHasData.d.ts +4 -0
- package/internals/seriesHasData.js +14 -0
- package/internals/stacking/index.d.ts +1 -0
- package/internals/stacking/index.js +16 -0
- package/internals/stacking/offset/index.d.ts +1 -0
- package/internals/stacking/offset/index.js +16 -0
- package/internals/stacking/offset/offsetDiverging.d.ts +8 -0
- package/internals/stacking/offset/offsetDiverging.js +53 -0
- package/internals/{stackSeries.d.ts → stacking/stackSeries.d.ts} +8 -8
- package/internals/{stackSeries.js → stacking/stackSeries.js} +3 -1
- package/models/seriesType/index.d.ts +3 -1
- package/package.json +4 -4
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.d.ts +0 -3
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.js +0 -4
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.d.ts +0 -21
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.js +0 -92
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.d.ts +0 -3
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/isFocusableSeriesType.js +0 -10
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.helpers.d.ts +0 -21
- 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 {
|
|
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
|
-
|
|
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 {
|
|
2
|
-
type
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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:
|
|
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
|
|
14
|
+
return item => focusedItem !== null && fastObjectShallowCompare(focusedItem, item);
|
|
14
15
|
}
|
package/esm/index.js
CHANGED
|
@@ -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
|
+
}
|
package/esm/internals/index.d.ts
CHANGED
|
@@ -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 "./
|
|
50
|
+
export * from "./stacking/index.js";
|
|
51
51
|
export * from "./getCurve.js";
|
|
52
52
|
export * from "./consumeSlots.js";
|
|
53
53
|
export * from "./consumeThemeProps.js";
|
package/esm/internals/index.js
CHANGED
|
@@ -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 "./
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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 {
|
|
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:
|
|
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
|
|
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
|
-
}) =>
|
|
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
|
|
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 => (
|
|
19
|
-
if (
|
|
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(
|
|
36
|
-
export const selectorChartsKeyboardYAxisIndex = createSelector(
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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 |
|
|
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;
|