function make_map() {
let height = 0.625 * width;
let path = d3.geoPath().projection(
d3
.geoIdentity()
.reflectY(true)
.fitSize([width, height], map_data.counties)
);
let div = d3
.create('div')
.style("width", `${width}px`)
.style("height", `${height}px`)
.style('overflow', 'hidden');
let svg = div
.append('svg')
.style("width", `${width}px`)
.style("height", `${height}px`)
.style('overflow', 'hidden');
let map = svg.append('g');
let counties = map
.append('g')
.selectAll("path.county")
.data(map_data.counties.features)
.join("path")
.attr('d', path)
.attr('class', 'county')
.attr('data-geoid', d => d.properties.GEOID)
.style("fill", function(d) {
return color_map.get(d.properties.GEOID);
})
.style("stroke-width", '0.2px')
.style('stroke-opacity', 0.4)
.style("stroke", "#000")
.style("stroke-linejoin", "round");
counties
.on('mouseenter', function() {
d3.select(this)
.style('stroke-width', '1px')
.style('stroke-opacity', 1);
})
.on('mouseleave', function() {
d3.select(this)
.style('stroke-width', '0.2px')
.style('stroke-opacity', 0.4);
});
counties.nodes().forEach(c => {
let geoid = c.getAttribute('data-geoid');
let instance = tippy(c, {
allowHTML: true,
maxWidth: 420,
theme: 'light',
content: table_map.get(geoid),
onHide: function() {
d3.select(c)
.style('stroke-width', '0.2px')
.style('stroke-opacity', 0.4);
}
});
tippy_instances.set(c.getAttribute('data-geoid'), instance);
});
map
.append("g")
.selectAll("path.state")
.data(map_data.states)
.join("path")
.attr('class', 'state')
.attr('d', path)
.attr("fill", 'none')
.attr("stroke-width", 0.5)
.attr("stroke", "#fff")
.attr("stroke-linejoin", "round");
map
.append("g")
.selectAll("path.nation")
.data(map_data.nation)
.join("path")
.attr('class', 'nation')
.attr('d', path)
.attr("fill", 'none')
.attr("stroke-width", 0.5)
.attr("stroke", "#000")
.attr("stroke-linejoin", "round");
svg.call(
d3
.zoom()
.extent([[0, 0], [width, height]])
.translateExtent([[0, 0], [width, height]])
.scaleExtent([1, 4])
.duration(500)
.on('zoom', function(evt) {
map.attr("transform", evt.transform);
})
);
let div_node = div.node();
div_node.path = path;
return div_node;
}