From 7d7017adef13b1f8ec9f33a92d52015ebd52bc67 Mon Sep 17 00:00:00 2001 From: "Benjamin Arntzen (aider)" Date: Thu, 27 Jun 2024 08:35:00 +0100 Subject: [PATCH] Filtered out empty or undefined color values from the color distribution before updating the pie chart. --- public/app.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/public/app.js b/public/app.js index abe8801..3fdbc18 100644 --- a/public/app.js +++ b/public/app.js @@ -39,8 +39,16 @@ function updatePieChart() { pieChartContainer.style.display = 'block'; pieChartContainer.style.zIndex = '10000'; - const colors = Object.keys(colorDistribution); - const data = colors.map(color => colorDistribution[color]); + // Filter out empty or undefined values + const filteredColorDistribution = Object.entries(colorDistribution).reduce((acc, [color, count]) => { + if (color && color.trim() !== '' && count > 0) { + acc[color] = count; + } + return acc; + }, {}); + + const colors = Object.keys(filteredColorDistribution); + const data = colors.map(color => filteredColorDistribution[color]); if (pieChart) { pieChart.destroy(); @@ -82,7 +90,7 @@ function updatePieChart() { // Update color distribution text const totalNodes = nodes.length; const distributionText = colors.map(color => { - const count = colorDistribution[color]; + const count = filteredColorDistribution[color]; const percentage = ((count / totalNodes) * 100).toFixed(1); return `${count}/${totalNodes} (${percentage}%) nodes are ${color}`; }).join('
');