From 03f85183b97d4d87ea65d916df87be7d9e1e3bcf Mon Sep 17 00:00:00 2001 From: "Ian Clarke (aider)" Date: Sat, 30 Nov 2024 11:55:57 -0500 Subject: [PATCH] refactor: Move node drawing code into initialization function to fix reset network issue --- .../static/html/eventual_convergence_viz.html | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/hugo-site/static/html/eventual_convergence_viz.html b/hugo-site/static/html/eventual_convergence_viz.html index 0d15c356..8373b7fa 100644 --- a/hugo-site/static/html/eventual_convergence_viz.html +++ b/hugo-site/static/html/eventual_convergence_viz.html @@ -134,6 +134,30 @@

Freenet Eventual Convergence Simulation

.attr("stroke", "#1e90ff") .attr("stroke-width", 2); + // Draw nodes as pie charts + const node = svg + .selectAll(".node") + .data(root.descendants()) + .enter() + .append("g") + .attr("class", "node") + .attr("transform", (d) => `translate(${d.x},${d.y})`) + .attr("id", (d) => `node-${d.data.id}`); + + node.each(function (d) { + const nodeGroup = d3.select(this); + drawPie(nodeGroup, d.data.receivedColors); + }); + + node + .on("mouseover", function (event, d) { + // Show all colors in the tooltip + const colorInfo = d.data.receivedColors.join(", "); + d3.select(this).append("title").text(colorInfo); + }) + .on("click", function (event, d) { + initiatePropagation(d); + }); } // Initial visualization @@ -164,16 +188,6 @@

Freenet Eventual Convergence Simulation

initializeVisualization(); } - // Draw nodes as pie charts - const node = svg - .selectAll(".node") - .data(root.descendants()) - .enter() - .append("g") - .attr("class", "node") - .attr("transform", (d) => `translate(${d.x},${d.y})`) - .attr("id", (d) => `node-${d.data.id}`); - const arcGenerator = d3.arc().innerRadius(0).outerRadius(10); const messageArcGenerator = d3.arc().innerRadius(0).outerRadius(5);