@mui/x-charts
Version:
The community edition of MUI X Charts components.
56 lines • 1.4 kB
JavaScript
import { getSeriesColorFn } from "./getSeriesColorFn.mjs";
export function resolveColorProcessor(params) {
const {
series,
valueColorScale,
categoryColorScale,
categoryValues
} = params;
const getSeriesColor = getSeriesColorFn(series);
if (valueColorScale) {
return dataIndex => {
if (dataIndex === undefined) {
return series.color;
}
const value = series.data[dataIndex];
const color = value === null ? getSeriesColor({
value,
dataIndex
}) : valueColorScale(value);
if (color === null) {
return getSeriesColor({
value,
dataIndex
});
}
return color;
};
}
if (categoryColorScale && categoryValues) {
return dataIndex => {
if (dataIndex === undefined) {
return series.color;
}
const value = categoryValues[dataIndex];
const fallbackValue = {
value: series.data[dataIndex],
dataIndex
};
const color = value === null ? getSeriesColor(fallbackValue) : categoryColorScale(value);
if (color === null) {
return getSeriesColor(fallbackValue);
}
return color;
};
}
return dataIndex => {
if (dataIndex === undefined) {
return series.color;
}
const value = series.data[dataIndex];
return getSeriesColor({
value,
dataIndex
});
};
}