refactor: clean up imports and move logprobToColor function to utils

This commit is contained in:
ecwu
2025-01-03 11:34:46 +08:00
parent 3728766d7f
commit 34360e5370
5 changed files with 3 additions and 12 deletions

14
src/utils/logprob.tsx Normal file
View File

@@ -0,0 +1,14 @@
const logprobToColor = (logprob: number) => {
// 将logprob转换为百分比
const percent = Math.exp(logprob) * 100;
// 计算颜色值
// 绿色的RGB值为(0, 255, 0)红色的RGB值为(255, 0, 0)
const red = Math.round(255 * (1 - percent / 100));
const green = Math.round(255 * (percent / 100));
const color = `rgba(${red}, ${green}, 0, 0.5)`;
return color;
};
export default logprobToColor;