Published
Edited
Oct 9, 2020
1 fork
Importers
26 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
lineSize = 6
Insert cell
demOrientation = "6/8"
Insert cell
Insert cell
blue = "#002868"

Insert cell
red = "#bf0a30"
Insert cell
demRamp = [
// textures
// .paths()
// .d("crosses")
// .size(lineSize * 0.75)
// .lighter()
// .thicker(),
textures
.lines()
.stroke(blue)
.orientation(demOrientation)
.size(lineSize),
textures
.lines()
.stroke(blue)
.orientation(demOrientation)
.size(lineSize)
.heavier(1),
textures
.lines()
.stroke(blue)
.orientation(demOrientation)
.size(lineSize)
.heavier(2),
textures
.lines()
.stroke(blue)
.orientation(demOrientation)
.size(lineSize)
.heavier(3)
]
Insert cell
Insert cell
repRamp = [
// textures
// .paths()
// .d("crosses")
// .size(lineSize * 0.75)
// .lighter()
// .thicker(),
textures
.lines()
.stroke(red)
.orientation(repOrientation)
.size(lineSize),
textures
.lines()
.stroke(red)
.orientation(repOrientation)
.size(lineSize)
.heavier(1),
textures
.lines()
.stroke(red)
.orientation(repOrientation)
.size(lineSize)
.heavier(2),
textures
.lines()
.stroke(red)
.orientation(repOrientation)
.size(lineSize)
.heavier(3)
]
Insert cell
ramp2 = [
textures
.lines()
.size(lineSize)
.lighter(),
textures.lines().size(lineSize),
textures
.lines()
.size(lineSize)
.heavier(1),
textures
.lines()
.size(lineSize)
.heavier(2),
textures
.lines()
.size(lineSize)
.heavier(3)
]
// ramp2 = [
// textures
// .lines()
// .size(18)
// .lighter(),
// textures
// .lines()
// .size(12)
// .lighter(),
// textures
// .lines()
// .size(7)
// .lighter(),
// textures
// .lines()
// .size(5)
// .lighter(),
// textures.lines().size(5),
// textures.lines().heavier(3),
// textures.lines().heavier(4)
// ]
// ramp2 = [
// textures
// .lines()
// .size(18)
// .lighter(),
// textures.lines().size(5),
// textures.lines().heavier(3)
// ]
Insert cell
ramp2.map(t => t.url())
Insert cell
legendSize = 50
Insert cell
Insert cell
Insert cell
processed = countyElectionResults.map(d => {
return {
...d,
combined_fips: d.combined_fips,
relative_diff: +d.diff / +d.total_votes,
dem: +d.votes_dem,
rep: +d.votes_gop,
total: +d.total_votes,
winner: +d.votes_dem > +d.votes_gop ? "dem" : "rep"
};
})
Insert cell
countyElectionResults
Insert cell
processed.filter(d => d.winner == "dem")
Insert cell
data2 = new Map(processed.map(d => [d.combined_fips, d]))
Insert cell
diffExtent = d3.extent(countyElectionResults, d => +d.diff / +d.total_votes)
Insert cell
// q = d3.scaleQuantize([1, 10], ramp2)
q = d3.scaleQuantize(diffExtent, ramp2)
Insert cell
// q = d3.scaleQuantize([1, 10], ramp2)
qDem = d3.scaleQuantize(diffExtent, demRamp)
Insert cell
// q = d3.scaleQuantize([1, 10], ramp2)
qRep = d3.scaleQuantize(diffExtent, repRamp)
Insert cell
qLegend = d3.scaleQuantize(diffExtent, d3.range(0, 10))
Insert cell
ramp = [
makePattern(svg`<defs><pattern x="0" y="0" width="0" height="0" patternUnits="userSpaceOnUse">
</pattern></defs>`),
makePattern(svg`<defs><pattern x="0" y="0" width="1" height="4" patternUnits="userSpaceOnUse">
<line x1="0" y1="1" x2="1" y2="1" stroke="currentColor" stroke-width="1" />
</pattern></defs>`),
makePattern(svg`<defs><pattern x="0" y="0" width="1" height="4" patternUnits="userSpaceOnUse">
<line x1="0" y1="1" x2="1" y2="1" stroke="currentColor" stroke-width="2" />
</pattern></defs>`),
makePattern(svg`<defs><pattern x="0" y="0" width="1" height="4" patternUnits="userSpaceOnUse">
<line x1="0" y1="1" x2="1" y2="1" stroke="currentColor" stroke-width="4" />
</pattern></defs>`),
makePattern(svg`<defs><pattern x="0" y="0" width="4" height="4" patternUnits="userSpaceOnUse">
<rect fill="currentColor" width="4" height="4" />
</pattern></defs>`)
]
Insert cell
makePattern = defs => {
let id = DOM.uid();
defs.querySelector('pattern').id = id.id;
defs.toString = () => id.toString();
return defs;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { countyElectionResults } from '@codingwithfire/where-are-votes-at-risk'
Insert cell
textures = require("textures")
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