puffin-app/server/utils/portfolioColors.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

/**
* Portfolio Color Palette System
* Ported from frontend src/utils/portfolioColors.ts
*/
export const portfolioColorPalette = [
'#3B82F6', // Blue 500
'#06B6D4', // Cyan 500
'#10B981', // Green 500
'#14B8A6', // Teal 500
'#8B5CF6', // Violet 500
'#6366F1', // Indigo 500
'#0EA5E9', // Sky 500
'#22C55E', // Green 400
'#84CC16', // Lime 500
'#F59E0B', // Amber 500
'#EC4899', // Pink 500
'#EF4444', // Red 500
];
export function getProjectColor(index) {
return portfolioColorPalette[index % portfolioColorPalette.length];
}
/**
* Add colors and formatted percentages to portfolio projects
* @param {Array} projects - Portfolio projects from Wren API
* @returns {Array} Projects with color and percentage added
*/
export function formatPortfolioProjects(projects) {
if (!projects || !Array.isArray(projects)) {
return [];
}
return projects.map((project, index) => ({
name: project.name || 'Unnamed Project',
type: project.type || 'Carbon Offset',
percentage: project.percentage || Math.round((1 / projects.length) * 100),
color: getProjectColor(index),
}));
}