Public
Edited
Oct 21, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
senateResultsRaw.filter(d => ['r_out_of_cycle','d_out_of_cycle'].includes(d.status)).map(d => d.district.replace('SD ',''))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// houseDistricts = renderedHouseCartogramDims.districts.features.map(d => ({district: d.properties.district, status: "pending"}))
Insert cell
// senateDistricts = renderedSenateCartogramDims.districts.features.map(d => {
// const lastRace = d.properties.legislativeElections.sort((a,b) => b.year - a.year)[0]
// const inCycle2022 = lastRace.year === '2018'
// const incumbentParty = lastRace.winnerParty
// return {
// district: d.properties.district,
// status: inCycle2022 ? "pending" : `${lastRace.winnerParty.toLowerCase()}_out_of_cycle`,
// }
// })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// candidates = {
// const raw = await FileAttachment("2022-general-legislative-candidates.csv").csv()
// const cleaned = raw.map(d => {
// let chamber, district
// const number = +d.Office.replace('Senate District ','').replace('House District ','')
// if (d.Office.includes('Senate District')) {
// chamber = 'senate'
// district = 'SD ' + number
// }
// if (d.Office.includes('House District')) {
// chamber = 'house'
// district = 'HD ' + number
// }
// return {
// name: d.Name,
// party: d.Party,
// chamber,
// number,
// district,
// }
// })
// return cleaned
// }
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
format = ({
n: d3.format(',.0f'),
p: d3.format('.0%')
})
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more