UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

18 lines (17 loc) 853 B
import { getNonEmptySeriesArray } from "./getNonEmptySeriesArray.js"; /** * Returns the previous series type and id that contains some data. * Returns `null` if no other series have data. */ export function getPreviousNonEmptySeries(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; if (currentSeriesIndex <= 0) { // If no current series, or if it's the first series return nonEmptySeries[nonEmptySeries.length - 1]; } return nonEmptySeries[(currentSeriesIndex - 1 + nonEmptySeries.length) % nonEmptySeries.length]; }