Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): unique color per message type in 'by type' chart (#486)
Ulises Cuñee52fd7e939fd
diff --git a/dashboard/src/components/DashboardCharts.tsx b/dashboard/src/components/DashboardCharts.tsxindex fbd7c9deb..05df5384c 100644--- a/dashboard/src/components/DashboardCharts.tsx+++ b/dashboard/src/components/DashboardCharts.tsx@@ -22,8 +22,31 @@ import './DashboardCharts.css';const PERIODS: StatsPeriod[] = ['24h', '7d', '30d'];-// Distinct, theme-agnostic palette for the donut slices (recharts needs literal colors).-const TYPE_COLORS = ['#25d366', '#3b82f6', '#a855f7', '#f59e0b', '#ef4444', '#06b6d4', '#ec4899', '#64748b'];+// Stable, distinct color per message type (recharts needs literal colors). Keyed by type name —+// not array index — so two types can never share a color, and a slice keeps its color even when the+// set of present types changes between requests. Covers every type mapMessageType() can emit.+const TYPE_COLORS: Record<string, string> = {+ text: '#25d366',+ image: '#3b82f6',+ contact: '#a855f7',+ document: '#f59e0b',+ audio: '#06b6d4',+ voice: '#ec4899',+ video: '#14b8a6',+ sticker: '#ef4444',+ location: '#84cc16',+ revoked: '#f43f5e',+ unknown: '#64748b',+};++// Deterministic fallback for any unmapped type, so its color is stable across renders.+const FALLBACK_COLORS = ['#0ea5e9', '#d946ef', '#f97316', '#10b981', '#6366f1', '#eab308'];+function colorForType(name: string): string {+ if (TYPE_COLORS[name]) return TYPE_COLORS[name];+ let hash = 0;+ for (let i = 0; i < name.length; i++) hash = (hash * 31 + name.charCodeAt(i)) | 0;+ return FALLBACK_COLORS[Math.abs(hash) % FALLBACK_COLORS.length];+}// '2026-06-24 14:00:00' (hour buckets) → '14:00'; '2026-06-24' (day buckets) → '06-24'.function formatTick(ts: string, period: StatsPeriod): string {@@ -125,8 +148,8 @@ export function DashboardCharts() {<ResponsiveContainer width="100%" height={260}><PieChart><Pie data={byType} dataKey="value" nameKey="name" innerRadius={55} outerRadius={90} paddingAngle={2}>- {byType.map((entry, i) => (- <Cell key={entry.name} fill={TYPE_COLORS[i % TYPE_COLORS.length]} />+ {byType.map(entry => (+ <Cell key={entry.name} fill={colorForType(entry.name)} />))}</Pie><Tooltip />