@mui/x-charts
Version:
The community edition of MUI X Charts components.
37 lines • 1.8 kB
JavaScript
import { warnOnce } from '@mui/x-internals/warning';
import { createSelector, createSelectorMemoized } from '@mui/x-internals/store';
import { selectorChartSeriesProcessed } from "./plugins/corePlugins/useChartSeries/useChartSeries.selectors.mjs";
import { useStore } from "./store/useStore.mjs";
export const selectorAllSeriesOfType = createSelector(selectorChartSeriesProcessed, (processedSeries, seriesType) => processedSeries[seriesType]);
export const selectorSeriesOfType = createSelectorMemoized(selectorChartSeriesProcessed, (processedSeries, seriesType, ids) => {
if (ids === undefined) {
return processedSeries[seriesType]?.seriesOrder?.map(seriesId => processedSeries[seriesType]?.series[seriesId]) ?? [];
}
if (!Array.isArray(ids)) {
return processedSeries[seriesType]?.series?.[ids];
}
const result = [];
const failedIds = [];
for (const id of ids) {
const series = processedSeries[seriesType]?.series?.[id];
if (series) {
result.push(series);
} else {
failedIds.push(id);
}
}
if (process.env.NODE_ENV !== 'production' && failedIds.length > 0) {
const formattedIds = failedIds.map(v => JSON.stringify(v)).join(', ');
const fnName = `use${seriesType.charAt(0).toUpperCase()}${seriesType.slice(1)}Series`;
warnOnce([`MUI X Charts: The following ids provided to "${fnName}" could not be found: ${formattedIds}.`, `Make sure that they exist and their series are using the "${seriesType}" series type.`]);
}
return result;
});
export const useAllSeriesOfType = seriesType => {
const store = useStore();
return store.use(selectorAllSeriesOfType, seriesType);
};
export const useSeriesOfType = (seriesType, seriesId) => {
const store = useStore();
return store.use(selectorSeriesOfType, seriesType, seriesId);
};