@mui/x-charts
Version:
The community edition of MUI X Charts components.
19 lines • 1.2 kB
JavaScript
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
/**
* Cleans a series item identifier by extracting only the relevant properties
* using the appropriate cleaner from the provided series configuration.
*
* @param {ChartSeriesConfig<ChartSeriesType>} seriesConfig - The configuration object for chart series.
* @param {object} identifier - The series item identifier to clean.
* @returns {object} A cleaned identifier object with only the properties relevant to the series type.
* @throws Will throw an error if no cleaner is found for the given series type.
*/
export const cleanIdentifier = (seriesConfig, identifier) => {
const cleaner = seriesConfig[identifier.type]?.identifierCleaner;
if (!cleaner) {
throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Charts: No identifier cleaner found for series type "${identifier.type}". ` + 'This internal error occurs when the series configuration is incomplete.' : _formatErrorMessage(42, identifier.type));
}
// @ts-expect-error identifierCleaner expects the full object,
// but this function accepts a partial one in order to be able to clean all identifiers.
return cleaner(identifier);
};