map2= ()=>{
for (let i = 0; i < 200; i++) {
simulation.tick();
}
const width = 800;
const height = 400;
const margin = { top: 20, right: 30, bottom: 80, left: 50 };
const svg = d3.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
const sphere = ({ type: "Sphere" });
svg
.append("g")
.append("path")
.datum(sphere)
.attr("class", "graticuleOutline")
.attr("d", path)
.style('fill', "#9ACBE3");
svg
.append("g")
.append("path")
.datum(d3.geoGraticule10())
.attr("class", "graticule")
.attr("d", path)
.attr("clip-path", "url(#clip)")
.style('fill', "none")
.style('stroke', "white")
.style('stroke-width', .8)
.style('stroke-opacity', .5)
.style('stroke-dasharray', 2);
svg
.append("path")
.datum(topojson.feature(world, world.objects.world_countries_data))
.attr("fill", "white")
.style('fill-opacity', .5)
.attr("d", path);
const tooltip = d3.select("body")
.append("div")
.style("opacity", 0)
.attr("class", "tooltip")
.style("position", "absolute")
.style("background-color", "white")
.style("border", "solid")
.style("border-width", "1px")
.style("border-radius", "5px")
.style("padding", "10px");
function formatValue(value) {
if (value >= 1000000000) {
return (value / 1000000000).toFixed(1) + " billion";
} else if (value >= 1000000) {
return (value / 1000000).toFixed(1) + " million";
} else {
return value;
}
}
svg
.selectAll("circle")
.data(result)
.enter()
.append("circle")
.attr("r", d => radius(d.received))
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("fill", "steelblue")
.attr("fill-opacity", 0.9)
.attr("stroke", "#fff")
.attr("stroke-width", 0.5)
.on("mouseover", (event, d) => {
tooltip.transition().duration(200).style("opacity", 0.9);
tooltip.html(`ID: ${d.name} <br>Received: ${formatValue(d.received)}`)
.style("left", (event.pageX + 10) + "px")
.style("top", (event.pageY - 28) + "px");
})
.on("mouseout", () => {
tooltip.transition().duration(500).style("opacity", 0);
});
svg
.selectAll("text")
.data(result)
.enter()
.append("text")
.attr("x", d => d.x)
.attr("y", d => d.y)
.text(d => d.id)
.attr("text-anchor", "middle")
.attr("dominant-baseline", "middle")
.attr("font-family", "sans-serif")
.attr("fill", "white")
.style("font-size", d => (d.received > 200000000 ? `${radius(d.received) * 0.8}px` : 0));
return svg.node();
}