map = {
let map = d3
.create("svg")
.attr("width", map_width)
.attr("height", map_height);
let group = map
.append("g")
.selectAll('path')
.data(districts.features)
.enter()
.append('path')
.attr('d', geoGenerator)
.style('stroke', 'white')
.style('stroke-width', '1px')
.style('fill', color)
.attr('title', function(d) {
let elected = d.properties.election_data.filter(
d => d.elected_flag == 'Y'
)[0];
return `
${d.properties.name}, ${d.properties.province}
<br />
${elected.candidate}, ${elected.party}`;
})
.on('mouseenter', function() {
map.selectAll('path').attr('opacity', 0.3);
d3.select(this).attr('opacity', 1);
})
.on('mouseleave', function() {
map.selectAll('path').attr('opacity', 1);
});
group.nodes().forEach(d => tippy(d, { followCursor: true }));
return map.node();
}