@mui/x-charts
Version:
The community edition of MUI X Charts components.
18 lines (17 loc) • 893 B
JavaScript
import { getNonEmptySeriesArray } from "./getNonEmptySeriesArray.js";
/**
* Returns the next series type and id that contains some data.
* Returns `null` if no other series have data.
* @param series - The processed series from the store.
* @param availableSeriesTypes - The set of series types that can be focused.
* @param type - The current series type.
* @param seriesId - The current series id.
*/
export function getNextNonEmptySeries(series, availableSeriesTypes, type, seriesId) {
const nonEmptySeries = getNonEmptySeriesArray(series, availableSeriesTypes);
if (nonEmptySeries.length === 0) {
return null;
}
const currentSeriesIndex = type !== undefined && seriesId !== undefined ? nonEmptySeries.findIndex(seriesItem => seriesItem.type === type && seriesItem.seriesId === seriesId) : -1;
return nonEmptySeries[(currentSeriesIndex + 1) % nonEmptySeries.length];
}