Published
Edited
Jun 11, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof republican = color({
title: "Republican color",
value: "#cc3d3d"
})
Insert cell
viewof democratic = color({
title: "Democratic color",
value: "#1d81c5"
})
Insert cell
viewof maxArrowLength = slider({
value: 40,
step: 1,
min: 1,
max: 100,
title: "Maximum arrow length"
})
Insert cell
changescale = d3
// .scaleSqrt()
.scaleLinear()
.domain([govminchange, govmaxchange])
.range([1, 2])
Insert cell
widthscale = d3
// .scaleSqrt()
.scaleLinear()
.domain([govminwidth, govmaxwidth])
.range([1, 5])
Insert cell
govminwidth = Math.min(...govsizes)
Insert cell
govminchange = Math.min(...govchanges)
Insert cell
govmaxwidth = Math.max(...govsizes)
Insert cell
govmaxchange = Math.max(...govchanges)
Insert cell
govraw = FileAttachment("presidential_change_2000_2020.json").json()
Insert cell
govsizes = govraw.map((d) => d.total_votes)
Insert cell
govchanges = govraw.map((d) => d.diff_2000_2020)
Insert cell
selectedCities = cityList.filter(d => cities.includes(d.name))
Insert cell
viewof cities = checkbox({
title: "Cities",
options: cityList.map(d => d.name).sort(),
value: cityList.map(d => d.name)
})
Insert cell
cityList = [
{
name: "Los Angeles",
type: 'city',
coordinates: [-118.243683, 34.052235],
},
{
name: "San Fransisco",
type: "city",
coordinates: [-122.431297, 37.773972],
},
{
name: "Bakersfield",
type: "city",
coordinates: [-119.043732, 35.493528],
y: "-3",
anchor: "begin"
},
{
name: "Sacramento",
type: "city",
y: "-4",
x:'5',
coordinates: [-121.478851, 38.575764]
},
{
name: "Redding",
type: "city",
coordinates: [-122.4327698, 40.5743177]
},
{
name: "San Diego",
type: "city",
coordinates: [-117.161087, 32.715736]
},
]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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