Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions mesa_viz_tornado/templates/js/NetworkModule_d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const NetworkModule = function (svg_width, svg_height) {

const nodes = g.append("g").attr("class", "nodes");

const labels = g.append("g").attr("class", "labels");

this.render = (data) => {
const graph = JSON.parse(JSON.stringify(data));

Expand All @@ -51,10 +53,10 @@ const NetworkModule = function (svg_width, svg_height) {

for (
let i = 0,
n = Math.ceil(
Math.log(simulation.alphaMin()) /
Math.log(1 - simulation.alphaDecay())
);
n = Math.ceil(
Math.log(simulation.alphaMin()) /
Math.log(1 - simulation.alphaDecay())
);
i < n;
++i
) {
Expand Down Expand Up @@ -120,7 +122,33 @@ const NetworkModule = function (svg_width, svg_height) {
});

nodes.selectAll("circle").data(graph.nodes).exit().remove();

// Create and update text labels
labels.selectAll("text").data(graph.nodes).enter().append("text");

labels
.selectAll("text")
.data(graph.nodes)
.attr("x", function (d) {
return d.x;
})
.attr("y", function (d) {
return d.y;
})
.attr("text-anchor", "middle")
.attr("dominant-baseline", "middle")
.attr("font-size", function (d) {
return (d.size * 1.5) + "px";
})
.attr("fill", function (d) {
return d.label_color || "#000000";
})
.text(function (d) {
return d.label || "";
});

labels.selectAll("text").data(graph.nodes).exit().remove();
};

this.reset = () => {};
this.reset = () => { };
};