Skip to content

Commit

Permalink
refactor: Move node drawing code into initialization function to fix …
Browse files Browse the repository at this point in the history
…reset network issue
  • Loading branch information
sanity committed Nov 30, 2024
1 parent ccbb058 commit 03f8518
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions hugo-site/static/html/eventual_convergence_viz.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ <h1 class="title">Freenet Eventual Convergence Simulation</h1>
.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
Expand Down Expand Up @@ -164,16 +188,6 @@ <h1 class="title">Freenet Eventual Convergence Simulation</h1>
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);
Expand Down

0 comments on commit 03f8518

Please sign in to comment.