You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
657 B

import { isString } from "lodash-es";
// 获取当前颜色
export function getCurrentColor({
color,
max,
value,
}: {
color: string | string[];
max: number;
value: number;
}) {
if (isString(color)) {
return color;
} else {
const colorArray = color
.map((item, index) => {
if (isString(item)) {
return {
color: item,
value: (index + 1) * (max / color.length),
};
}
return item;
})
.sort((a, b) => a.value - b.value);
for (let i = 0; i < colorArray.length; i++) {
if (colorArray[i].value >= value) {
return colorArray[i].color;
}
}
return colorArray[colorArray.length - 1].color;
}
}