feat: enhance HomePage with tag metrics and analytics integration
- Added TagAnalyticsService to fetch tag distribution metrics for the HomePage. - Updated HomePageClient and ProductivityAnalytics components to utilize new tag metrics. - Refactored TagsClient to use utility functions for color validation and generation. - Simplified TagForm to use centralized tag colors from TAG_COLORS.
This commit is contained in:
67
src/lib/tag-colors.ts
Normal file
67
src/lib/tag-colors.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Lib centralisée pour la gestion des couleurs des tags
|
||||
*/
|
||||
|
||||
// Couleurs prédéfinies pour les tags (cohérentes avec TagForm et TagsClient)
|
||||
export const TAG_COLORS = [
|
||||
'#3B82F6', // Blue
|
||||
'#EF4444', // Red
|
||||
'#10B981', // Green
|
||||
'#F59E0B', // Yellow
|
||||
'#8B5CF6', // Purple
|
||||
'#EC4899', // Pink
|
||||
'#06B6D4', // Cyan
|
||||
'#84CC16', // Lime
|
||||
'#F97316', // Orange
|
||||
'#6366F1', // Indigo
|
||||
'#14B8A6', // Teal
|
||||
'#F43F5E', // Rose
|
||||
'#22C55E', // Emerald
|
||||
'#EAB308', // Amber
|
||||
'#A855F7', // Violet
|
||||
'#D946EF', // Fuchsia
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Génère une couleur pour un tag basée sur son nom (hash déterministe)
|
||||
*/
|
||||
export function generateTagColor(tagName: string): string {
|
||||
// Hash simple du nom pour choisir une couleur
|
||||
let hash = 0;
|
||||
for (let i = 0; i < tagName.length; i++) {
|
||||
hash = tagName.charCodeAt(i) + ((hash << 5) - hash);
|
||||
}
|
||||
|
||||
return TAG_COLORS[Math.abs(hash) % TAG_COLORS.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère une couleur aléatoire pour un nouveau tag
|
||||
*/
|
||||
export function generateRandomTagColor(): string {
|
||||
return TAG_COLORS[Math.floor(Math.random() * TAG_COLORS.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Valide si une couleur est valide (format hex)
|
||||
*/
|
||||
export function isValidTagColor(color: string): boolean {
|
||||
return /^#[0-9A-F]{6}$/i.test(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la couleur d'un tag, en générant une couleur par défaut si nécessaire
|
||||
*/
|
||||
export function getTagColor(tagName: string, existingColor?: string): string {
|
||||
if (existingColor && isValidTagColor(existingColor)) {
|
||||
return existingColor;
|
||||
}
|
||||
return generateTagColor(tagName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère un tableau de couleurs pour les graphiques en respectant les couleurs des tags
|
||||
*/
|
||||
export function generateChartColors(tags: Array<{ name: string; color?: string }>): string[] {
|
||||
return tags.map(tag => getTagColor(tag.name, tag.color));
|
||||
}
|
||||
Reference in New Issue
Block a user