UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

131 lines (130 loc) 5.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createGetNextIndexFocusedItem = createGetNextIndexFocusedItem; exports.createGetNextSeriesFocusedItem = createGetNextSeriesFocusedItem; exports.createGetPreviousIndexFocusedItem = createGetPreviousIndexFocusedItem; exports.createGetPreviousSeriesFocusedItem = createGetPreviousSeriesFocusedItem; var _getPreviousNonEmptySeries = require("./plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries"); var _getMaxSeriesLength = require("./plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength"); var _useChartSeries = require("./plugins/corePlugins/useChartSeries"); var _getNextNonEmptySeries = require("./plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries"); var _seriesHasData = require("./seriesHasData"); function createGetNextIndexFocusedItem( /** * The set of series types compatible with this navigation action. */ compatibleSeriesTypes, /** * If true, allows cycling from the last item to the first one. */ allowCycles = false) { return function getNextIndexFocusedItem(currentItem, state) { const processedSeries = (0, _useChartSeries.selectorChartSeriesProcessed)(state); let seriesId = currentItem?.seriesId; let type = currentItem?.type; if (!type || seriesId == null || !(0, _seriesHasData.seriesHasData)(processedSeries, type, seriesId)) { const nextSeries = (0, _getNextNonEmptySeries.getNextNonEmptySeries)(processedSeries, compatibleSeriesTypes, type, seriesId); if (nextSeries === null) { return null; } type = nextSeries.type; seriesId = nextSeries.seriesId; } const maxLength = (0, _getMaxSeriesLength.getMaxSeriesLength)(processedSeries, compatibleSeriesTypes); let dataIndex = currentItem?.dataIndex == null ? 0 : currentItem.dataIndex + 1; if (allowCycles) { dataIndex = dataIndex % maxLength; } else { dataIndex = Math.min(maxLength - 1, dataIndex); } return { type, seriesId, dataIndex }; }; } function createGetPreviousIndexFocusedItem( /** * The set of series types compatible with this navigation action. */ compatibleSeriesTypes, /** * If true, allows cycling from the last item to the first one. */ allowCycles = false) { return function getPreviousIndexFocusedItem(currentItem, state) { const processedSeries = (0, _useChartSeries.selectorChartSeriesProcessed)(state); let seriesId = currentItem?.seriesId; let type = currentItem?.type; if (!type || seriesId == null || !(0, _seriesHasData.seriesHasData)(processedSeries, type, seriesId)) { const previousSeries = (0, _getPreviousNonEmptySeries.getPreviousNonEmptySeries)(processedSeries, compatibleSeriesTypes, type, seriesId); if (previousSeries === null) { return null; } type = previousSeries.type; seriesId = previousSeries.seriesId; } const maxLength = (0, _getMaxSeriesLength.getMaxSeriesLength)(processedSeries, compatibleSeriesTypes); let dataIndex = currentItem?.dataIndex == null ? maxLength - 1 : currentItem.dataIndex - 1; if (allowCycles) { dataIndex = (maxLength + dataIndex) % maxLength; } else { dataIndex = Math.max(0, dataIndex); } return { type, seriesId, dataIndex }; }; } function createGetNextSeriesFocusedItem( /** * The set of series types compatible with this navigation action. */ compatibleSeriesTypes) { return function getNextSeriesFocusedItem(currentItem, state) { const processedSeries = (0, _useChartSeries.selectorChartSeriesProcessed)(state); let seriesId = currentItem?.seriesId; let type = currentItem?.type; const nextSeries = (0, _getNextNonEmptySeries.getNextNonEmptySeries)(processedSeries, compatibleSeriesTypes, type, seriesId); if (nextSeries === null) { return null; // No series to move the focus to. } type = nextSeries.type; seriesId = nextSeries.seriesId; const dataIndex = currentItem?.dataIndex == null ? 0 : currentItem.dataIndex; return { type, seriesId, dataIndex }; }; } function createGetPreviousSeriesFocusedItem( /** * The set of series types compatible with this navigation action. */ compatibleSeriesTypes) { return function getPreviousSeriesFocusedItem(currentItem, state) { const processedSeries = (0, _useChartSeries.selectorChartSeriesProcessed)(state); let seriesId = currentItem?.seriesId; let type = currentItem?.type; const previousSeries = (0, _getPreviousNonEmptySeries.getPreviousNonEmptySeries)(processedSeries, compatibleSeriesTypes, type, seriesId); if (previousSeries === null) { return null; // No series to move the focus to. } type = previousSeries.type; seriesId = previousSeries.seriesId; const data = processedSeries[type].series[seriesId].data; const dataIndex = currentItem?.dataIndex == null ? data.length - 1 : currentItem.dataIndex; return { type, seriesId, dataIndex }; }; }