function make_result_map(trial) {
let biden_count = 0;
let trump_count = 0;
trial.forEach(function(o) {
let r = o.result;
if (r == 'Trump') {
trump_count = trump_count + o.votes;
} else {
biden_count = biden_count + o.votes;
}
});
result_cnt.runs++;
if (biden_count > trump_count) {
result_cnt.biden++;
} else {
result_cnt.trump++;
}
let div = d3
.create('div')
.attr('class', 'result_container')
.style("width", `${map_width}px`)
.style("height", `${30 + height}px`)
.style('overflow', 'hidden');
let result_display = div
.append('div')
.style("width", `${map_width}px`)
.style('height', '30px')
.style('text-align', 'center')
.html(
`Biden: ${biden_count}, Trump: ${trump_count} <br /> Percentage of Biden wins: ${
result_cnt.biden
} /
${result_cnt.runs} = ${d3.format('0.2f')(
(100 * result_cnt.biden) / result_cnt.runs
)}%`
);
let svg = div
.append('svg')
.style('overflow', 'hidden')
.attr("viewBox", [0, 0, map_width, height]);
let path = d3.geoPath().projection(proj);
let map = svg.append('g');
map
.selectAll("path")
.data(states.features)
.join("path")
.attr('class', 'state')
.attr('d', path)
.style("fill", function(d) {
let abbr = d.properties.fips;
let dd = trial.filter(o => o.abbr == abbr);
let p;
if (dd.length > 0 && dd[0].result == "Biden") {
p = 1;
} else {
p = 0;
}
return d3.interpolateRdBu(p);
})
.style('fill-opacity', 0.7)
.attr('data-state', function(d, i) {
let abbr = d.properties.fips;
return abbr;
})
.attr("stroke-width", '1.5px')
.attr("stroke", "#ddd")
.attr("stroke-linejoin", "round");
d3.selectAll('.result_container').remove();
d3.select(result_map).append(() => div.node());
}