map = {
const width = 1200
const height = 600
const margin = 10
let svg = d3.select(DOM.svg(width, height));
const path = d3.geoPath();
svg.append("text")
.attr("x", margin*14)
.attr("y",height-30)
.attr("dy", ".35em")
.text();
const aa = svg.append("g");
const countyMap = aa.append("g")
.attr("transform","translate("+margin+","+margin+")")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.join("path")
.attr("fill", d => color(data.get(d.id+" "+dateToString(date))))
.attr("d", path)
.on("mouseover", function(d) {
d3.select(this)
.attr("stroke" , "orange")
})
.on("mouseout", function(d) {
d3.select(this)
.attr("stroke" , "null")
})
.on('click', function(e, d) {
d3.selectAll("path")
.style('stroke', null);
d3.select(this)
.style('stroke', 'orange');
svg.select("text").text(`${d.properties.name}, ${states.get(d.id.slice(0, 2)).name}, ID: ${d.id}`);
})
.append("title")
.text(d => `${d.properties.name}, ${states.get(d.id.slice(0, 2)).name}
${format(data.get(d.id+" "+ dateToString(date)))}`);
svg.append(legend)
.attr("transform", "translate(100,500)");
aa.append("path")
.attr("transform","translate("+margin+","+margin+") ")
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path(topojson.mesh(us, us.objects.states, (a, b) => a !== b)));
function update(date) {
countyMap.attr("fill", function(d) {
var fclass = data.get(d.id+" "+dateToString(date));
});
}
var zoom = d3.zoom()
.scaleExtent([1, 8])
.on('zoom', zoomed);
function zoomed(event) {
const {transform} = event;
aa.attr("transform", transform);
aa.attr("stroke-width", 1 / transform.k);
}
aa.call(zoom);
return Object.assign(svg.node(), {update});
}