Public
Edited
Sep 3, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
colorScale = ({
// percentThresholds: [0.25,0.30,0.35,0.40,0.45,0.50,0.55],
winnerMarginThresholds: [100,200,500,1500,3000],
zinkeColors: ['#fdd0a2','#fdae6b','#fd8d3c','#f16913','#d94801','#a63603',
// '#7f2704'
],
olszewskiColors: ['#c7e9c0','#a1d99b','#74c476','#41ab5d','#238b45','#006d2c',
// '#00441b'
],
})
Insert cell
legend = html`<svg font-family="Arial" font-size="14" width=1000 height=100>
<text font-size="12" x=0 y=14>Votes in county-level victory margin</text>
<g transform="translate(0,20)">
<text font-size="11" x=110 y=14><100</text>
${
colorScale.winnerMarginThresholds.map((d, i) => `<text font-size="11" x=${160+50*i} y=14>${d3.format(',.0f')(d)}+</text>`)
}
</g>
<g transform="translate(0,40)">
<text x=0 y=14>Ryan Zinke</text>
${
colorScale.zinkeColors.map((color, i) => {
return `<rect x=${100+50*i} y=0 height=18 width=50 fill="${color}"/>`
})
}
</g>
<g transform="translate(0,60)">
<text x=0 y=14>Al Olszewski</text>
${
colorScale.olszewskiColors.map((color, i) => {
return `<rect x=${100+50*i} y=0 height=18 width=50 fill="${color}"/>`
})
}
</g>
<g transform="translate(0,80)">
<text font-size=12 font-style="italic" x=0 y=14>GOP candidates Mary Todd, Matt Jette and Mitch Heuer didn't win any of the district's counties</text>
</g>
<svg>`
Insert cell
// color = status => {
// return {
// "Legal, not on ballot": '#b8e186',
// "Banned, not on ballot": '#e08214',
// "Proposed ban": 'url(#proposed_ban)',
// "Proposed local tax": 'url(#proposed_tax)',
// }[status] || '#666'
// }
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gopWestVotesByCounty.sort((a,b) => b.votePercent['Ryan Zinke'] - a.votePercent['Ryan Zinke']).map(d => ({county: d.county, zinke_margin: d.winnerMargin['Ryan Zinke'], ols_margin: d.winnerMargin['Al Olszewski'], }))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more