Filtered out empty or undefined color values from the color distribution before updating the pie chart.
This commit is contained in:
+11
-3
@@ -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('<br>');
|
||||
|
||||
Reference in New Issue
Block a user