From a7bdd07c09506bcc768052d8032368b6c7e6fac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 6 May 2026 17:44:49 -0300 Subject: [PATCH] feat: implement consistent color mapping for products across charts --- src/pages/Dashboard.tsx | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index d0e5034..ae95e3c 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -63,20 +63,26 @@ const Dashboard = () => { } }); + const uniqueProducts = Array.from(new Set(filteredData.map(order => order.Descricao_Produto.split(' TAMANHO')[0]))).sort(); + const productColors: Record = {}; + uniqueProducts.forEach((productName, index) => { + productColors[productName] = COLORS[index % COLORS.length]; + }); + const productsData = Object.keys(productSalesMap).map(key => ({ name: key, value: productSalesMap[key] - })).sort((a, b) => b.value - a.value).slice(0, 10).map((item, index) => ({ + })).sort((a, b) => b.value - a.value).slice(0, 10).map(item => ({ ...item, - fill: COLORS[index % COLORS.length] + fill: productColors[item.name] })); const revenueData = Object.keys(productRevenueMap).map(key => ({ name: key, value: productRevenueMap[key] - })).sort((a, b) => b.value - a.value).slice(0, 10).map((item, index) => ({ + })).sort((a, b) => b.value - a.value).slice(0, 10).map(item => ({ ...item, - fill: COLORS[index % COLORS.length] + fill: productColors[item.name] })); return { totalRevenue: revenue, totalOrders: totalItems, averageOrderValue: revenue / (filteredData.length || 1), salesByProduct: productsData, revenueByProduct: revenueData }; @@ -148,17 +154,17 @@ const Dashboard = () => { } cursor={{ fill: '#222222' }} /> - {salesByProduct.map((_, index) => ( - + {salesByProduct.map((entry) => ( + ))}
- {salesByProduct.map((entry, index) => ( + {salesByProduct.map((entry) => (
- + {entry.name}
))} @@ -171,8 +177,8 @@ const Dashboard = () => { - {revenueByProduct.map((_, index) => ( - + {revenueByProduct.map((entry) => ( + ))} } cursor={{ fill: '#222222' }} /> @@ -180,9 +186,9 @@ const Dashboard = () => {
- {revenueByProduct.map((entry, index) => ( -
- + {revenueByProduct.map((entry) => ( +
+ {entry.name}
))}