UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

52 lines (49 loc) 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardXAxisIndex = exports.selectorChartsKeyboardItem = exports.selectorChartsItemIsFocused = exports.selectorChartsIsKeyboardNavigationEnabled = exports.selectorChartsHasFocusedItem = exports.selectorChartsFocusedItem = void 0; var _store = require("@mui/x-internals/store"); var _fastObjectShallowCompare = require("@mui/x-internals/fastObjectShallowCompare"); var _useChartSeries = require("../../corePlugins/useChartSeries"); var _useChartCartesianAxisRendering = require("../useChartCartesianAxis/useChartCartesianAxisRendering.selectors"); const selectKeyboardNavigation = state => state.keyboardNavigation; const selectorChartsItemIsFocused = exports.selectorChartsItemIsFocused = (0, _store.createSelector)(selectKeyboardNavigation, (keyboardNavigationState, item) => keyboardNavigationState?.item != null && (0, _fastObjectShallowCompare.fastObjectShallowCompare)(keyboardNavigationState.item, item)); const selectorChartsHasFocusedItem = exports.selectorChartsHasFocusedItem = (0, _store.createSelector)(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item != null); const selectorChartsFocusedItem = exports.selectorChartsFocusedItem = (0, _store.createSelector)(selectKeyboardNavigation, keyboardNavigationState => keyboardNavigationState?.item ?? null); const selectorChartsIsKeyboardNavigationEnabled = exports.selectorChartsIsKeyboardNavigationEnabled = (0, _store.createSelector)(selectKeyboardNavigation, keyboardNavigationState => !!keyboardNavigationState?.enableKeyboardNavigation); /** * Selectors to override highlight behavior. */ const createSelectAxisHighlight = direction => (item, axis, series) => { if (item == null || !('dataIndex' in item) || item.dataIndex === undefined) { return undefined; } const seriesConfig = series[item.type]?.series[item.seriesId]; if (!seriesConfig) { return undefined; } let axisId = direction === 'x' ? 'xAxisId' in seriesConfig && seriesConfig.xAxisId : 'yAxisId' in seriesConfig && seriesConfig.yAxisId; if (axisId === undefined || axisId === false) { axisId = axis.axisIds[0]; } return { axisId, dataIndex: item.dataIndex }; }; const selectorChartsKeyboardXAxisIndex = exports.selectorChartsKeyboardXAxisIndex = (0, _store.createSelector)(selectorChartsFocusedItem, _useChartCartesianAxisRendering.selectorChartXAxis, _useChartSeries.selectorChartSeriesProcessed, createSelectAxisHighlight('x')); const selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardYAxisIndex = (0, _store.createSelector)(selectorChartsFocusedItem, _useChartCartesianAxisRendering.selectorChartYAxis, _useChartSeries.selectorChartSeriesProcessed, createSelectAxisHighlight('y')); const selectorChartsKeyboardItem = exports.selectorChartsKeyboardItem = (0, _store.createSelector)(selectKeyboardNavigation, function selectorChartsKeyboardItem(keyboardState) { if (keyboardState?.item == null) { return null; } const { type, seriesId } = keyboardState.item; if (type === undefined || seriesId === undefined) { return null; } return keyboardState.item; });