Files
nofx/web/src/utils/traderColors.ts
Ember b79878ab36 feat: add ESLint and Prettier with pre-commit hook
- Install ESLint 9 with TypeScript and React support
- Install Prettier with custom configuration (no semicolons)
- Add husky and lint-staged for pre-commit hooks
- Configure lint-staged to auto-fix and format on commit
- Relax ESLint rules to avoid large-scale code changes
- Format all existing code with Prettier (no semicolons)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-11-05 11:41:14 +08:00

32 lines
934 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Trader颜色配置 - 统一的颜色分配逻辑
// 用于 ComparisonChart 和 Leaderboard确保颜色一致性
export const TRADER_COLORS = [
'#60a5fa', // blue-400
'#c084fc', // purple-400
'#34d399', // emerald-400
'#fb923c', // orange-400
'#f472b6', // pink-400
'#fbbf24', // amber-400
'#38bdf8', // sky-400
'#a78bfa', // violet-400
'#4ade80', // green-400
'#fb7185', // rose-400
]
/**
* 根据trader的索引位置获取颜色
* @param traders - trader列表
* @param traderId - 当前trader的ID
* @returns 对应的颜色值
*/
export function getTraderColor(
traders: Array<{ trader_id: string }>,
traderId: string
): string {
const traderIndex = traders.findIndex((t) => t.trader_id === traderId)
if (traderIndex === -1) return TRADER_COLORS[0] // 默认返回第一个颜色
// 如果超出颜色池大小,循环使用
return TRADER_COLORS[traderIndex % TRADER_COLORS.length]
}