@mui/x-charts
Version:
The community edition of MUI X Charts components.
27 lines (26 loc) • 1.51 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.serializeIdentifier = void 0;
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
/**
* 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(process.env.NODE_ENV !== "production" ? `MUI X Charts: No identifier serializer found for series type "${identifier.type}". ` + 'This internal error occurs when the series configuration is incomplete.' : (0, _formatErrorMessage2.default)(43, 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;