@mui/x-charts
Version:
The community edition of MUI X Charts components.
23 lines (22 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPreviousNonEmptySeries = getPreviousNonEmptySeries;
var _getNonEmptySeriesArray = require("./getNonEmptySeriesArray");
/**
* Returns the previous series type and id that contains some data.
* Returns `null` if no other series have data.
*/
function getPreviousNonEmptySeries(series, availableSeriesTypes, type, seriesId) {
const nonEmptySeries = (0, _getNonEmptySeriesArray.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];
}