@mui/x-charts
Version:
The community edition of MUI X Charts components.
25 lines (24 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.serializeIdentifier = void 0;
/**
* Serializes a series item identifier into a unique string using the appropriate serializer
* from the provided series configuration.
*
* @param {ChartSeriesConfig<ChartSeriesType>} seriesConfig - The configuration object for chart series.
* @param {SeriesItemIdentifier<ChartSeriesType>} identifier - The series item identifier to serialize.
* @returns {string} A unique string representation of the identifier.
* @throws Will throw an error if no serializer is found for the given series type.
*/
const serializeIdentifier = (seriesConfig, identifier) => {
const serializer = seriesConfig[identifier.type]?.identifierSerializer;
if (!serializer) {
throw new Error(`MUI X Charts: No identifier serializer found for series type "${identifier.type}".`);
}
// @ts-expect-error identifierSerializer expects the full object,
// but this function accepts a partial one in order be able to serialize all identifiers.
return serializer(identifier);
};
exports.serializeIdentifier = serializeIdentifier;