mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-09 05:51:01 +08:00
UI: Unify trader colors between Leaderboard and Performance Chart
Problem: - Leaderboard used ai_model-based colors (qwen=purple, other=blue) - Performance Comparison used index-based colors (10 color pool) - This caused color mismatch between the two components - Same trader showed different colors in different sections Solution: - Create shared color utility (utils/traderColors.ts) - Define single color pool with 10 distinct colors - Implement unified getTraderColor function based on trader index - Update both ComparisonChart and CompetitionPage to use shared utility Changes: - New file: web/src/utils/traderColors.ts (shared color logic) - Updated: ComparisonChart.tsx (use shared utility) - Updated: CompetitionPage.tsx (use shared utility in Leaderboard and Head-to-Head sections) Now traders consistently display the same color across all UI sections. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
31
web/src/utils/traderColors.ts
Normal file
31
web/src/utils/traderColors.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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];
|
||||
}
|
||||
Reference in New Issue
Block a user