makeResultsTable = function(place, dd, mapSpecifier) {
let [demVotes, repVotes, totalVoters] = [+dd.DemVotes, +dd.RepVotes, +dd.TotalVoters]
let demoninator = demVotes + repVotes;
if(mapSpecifier != 'choropleth' & mapSpecifier != 'bubbles') {demoninator = totalVoters}
let outputHtml = `
<div id='sidebar'>
<h3>${place} Results</h3>
<table>
<thead>
<tr>
<th width="1%"></th>
<th width="30%" style="text-align: left;">Candidate</th>
<th style="vertical-align: middle;text-align: right;">Votes</th>
<th width= "40%"></th>
</tr>
</thead>
<tbody>
<tr style="max-width:20%">
<td><svg width="20" height="20" viewBox="0 0 20 20"><circle cx="50%" cy="50%" r="4" fill="${colors.rep + sideBarColOpacityHex}"></circle></svg></td>
<td>Republican</td>
<td style="text-align: right;">${d3.format(",")(repVotes)}</td>
<td><div class="bar-background" >
<span class="bar-span rep" style="width: ${100 * repVotes / demoninator}%"></span>
</div></td>
</tr>
<tr>
<td><svg width="20" height="20" viewBox="0 0 20 20"><circle cx="50%" cy="50%" r="4" fill="${colors.dem + sideBarColOpacityHex}"></circle></svg></td>
<td>Democrat</td>
<td style=";text-align: right;">${d3.format(",")(demVotes)}</td>
<td><div class="bar-background" >
<span class="bar-span dem" style="width: ${100 * demVotes / demoninator}%"></span>
</div></td>
</tr>`
if (mapSpecifier != 'choropleth' & mapSpecifier != 'bubbles' ) {
outputHtml += `<tr>
<td><svg width="20" height="20" viewBox="0 0 20 20"><circle cx="50%" cy="50%" r="4" fill=${mapSpecifier == "dots" ? "#fbf418": "#444"}></circle></svg></td>
<td>Est. Left to Count</td>
<td style="text-align: right;">~${d3.format(",.2r")(totalVoters - (demVotes + repVotes))}</td>
<td><div class="bar-background" >
<span class="bar-span" style="background:${mapSpecifier == "dots" ? "#fbf418": "#444"};width: ${100 * (totalVoters - (demVotes + repVotes)) / demoninator}%"></span>
</div></td>
</tr>
</tbody>
</table>`
} else {
outputHtml +=
` </tbody>
</table>
<div style="font-size: 12px;">Est. ${d3.format('.0%')((demVotes+ repVotes)/totalVoters)} votes in</div>`
}
outputHtml += `</div>
<style>
#sidebar td {
vertical-align: middle;
}
#sidebar .bar-background {
display: flex;
position: relative;
width: 100%;
height: 0.6rem;
}
#sidebar .bar-background::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-color: #ccc;
}
#sidebar .bar-span {
z-index:1;
height: 0.6rem;
position:relative;
}
#sidebar .dem {
background:${colors.dem + sideBarColOpacityHex};
}
#sidebar .rep {
background:${colors.rep + sideBarColOpacityHex};
}
</style>`
return outputHtml
}