@mui/x-charts
Version:
The community edition of MUI X Charts components.
27 lines (26 loc) • 1.48 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.cleanIdentifier = void 0;
var _formatErrorMessage2 = _interopRequireDefault(require("@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.
*/
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.' : (0, _formatErrorMessage2.default)(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);
};
exports.cleanIdentifier = cleanIdentifier;