chart = {
const width = 960;
const height = 600;
const projection = d3.geoAlbersUsa().scale(1200).translate([width/2, height/2])
const path = d3.geoPath().projection(projection)
const radius = d3.scaleSqrt().domain(extent).range([10, 30]);
const translate = (coords) => {
const [x, y] = projection([+coords.longitude, +coords.latitude])
return `translate(${x},${y})`
}
const svg = d3.create("svg")
.attr("viewBox", `0 0 ${width} ${height}`)
.style("width", "100%")
.style("height", "auto")
.style('background-color', null)
const states = svg.append("g")
.selectAll("path")
.data(topojson.feature(us, us.objects.states).features)
.join("path")
.attr("fill", "#ccc")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);
const bubbles = svg.append("g")
.attr("fill", "brown")
.attr("fill-opacity", 0.5)
.attr("stroke", "#fff")
.attr("stroke-width", 0.5)
.selectAll("circles")
.data(data)
.join("circle")
.attr("transform", translate)
.attr("r", d => radius(d.count))
const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", `translate(${width - 80},${height - 10})`)
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll(".legend")
.data([10, 25, 50])
.join("g")
legend.append("circle")
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("cy", d => -radius(d))
.attr("r", radius);
legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(d => d)
return svg.node();
}