fix: stabilize color mapping by using persistent global hash and add SSE heartbeat
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m18s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m18s
This commit is contained in:
@@ -15,6 +15,17 @@ const COLORS = [
|
||||
'#67e8f9', '#f9a8d4', '#fde047', '#a5b4fc', '#5eead4'
|
||||
];
|
||||
|
||||
const globalColorMap: Record<string, string> = {};
|
||||
let globalColorIndex = 0;
|
||||
|
||||
const getProductColor = (name: string) => {
|
||||
if (!globalColorMap[name]) {
|
||||
globalColorMap[name] = COLORS[globalColorIndex % COLORS.length];
|
||||
globalColorIndex++;
|
||||
}
|
||||
return globalColorMap[name];
|
||||
};
|
||||
|
||||
const formatCurrency = (value: number) => {
|
||||
return new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(value);
|
||||
};
|
||||
@@ -75,8 +86,8 @@ const Dashboard = () => {
|
||||
const displayProducts = Array.from(new Set([...topSalesNames, ...topRevenueNames])).sort();
|
||||
const productColors: Record<string, string> = {};
|
||||
|
||||
displayProducts.forEach((name, index) => {
|
||||
productColors[name] = COLORS[index % COLORS.length];
|
||||
displayProducts.forEach((name) => {
|
||||
productColors[name] = getProductColor(name);
|
||||
});
|
||||
|
||||
const productsData = topSalesNames.map(name => ({
|
||||
|
||||
Reference in New Issue
Block a user