chart = {
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height])
.attr("style", "max-width: 100%; height: auto;");
const path = d3.geoPath();
const states = topojson.feature(us, us.objects.states);
const statemap = new Map(states.features.map(d => [d.id, d]));
const statemesh = topojson.mesh(us, us.objects.states, (a, b) => a !== b);
svg.append("path")
.datum(topojson.mesh(us, us.objects.nation))
.attr("fill", "#E7E7E7")
.attr("stroke", "#B1B1B1")
.attr("stroke-linejoin", "round")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "#FFFFFF")
.attr("stroke-linejoin", "round")
.attr("d", path);
let simulation = d3
.forceSimulation(data3)
.force(
"x",
d3
.forceX()
.x((d) => d.position[0])
.strength(0.5)
)
.force(
"y",
d3
.forceY()
.y((d) => d.position[1])
.strength(0.5)
)
.force(
"collision",
d3.forceCollide().radius(radius)
)
.on("tick", function () {
let u = svg.selectAll(".nodes").data(data3);
u.enter()
.append("circle")
.attr("class", "nodes")
.attr("r", radius)
.attr("fill", (d) => d.arrests=="Y" ? "#ff7900" : "#4e4e4e")
.attr("fill-opacity", 1)
.attr("stroke", "#E7E7E7")
.attr("stroke-width", 0.8)
.merge(u)
.attr("cx", (d) => d.x)
.attr("cy", (d) => d.y)
.append("title")
.text(
(d) => `${d.id}`
);
u.exit().remove();
});
return svg.node();
}