Published
Edited
Oct 25, 2020
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
highlightEarly = highlights.early.map(d => normalizeEarly(d))
Insert cell
highlightDayOf = highlights.dayOf.map(d => normalizeDayOf(d))
Insert cell
maxEarlyRatio = _.ceil(d3.max(showData, d => d.earlyRatio), -1)
Insert cell
medianEarlyRatio = d3.median(showData, d => d.earlyRatio)
Insert cell
meanEarlyRatio = d3.mean(showData, d => d.earlyRatio)
Insert cell
maxDayOfRatio = _.ceil(d3.max(showData, d => d.dayOfRatio), -1)
Insert cell
medianDayOfRatio = d3.median(showData, d => d.dayOfRatio)
Insert cell
Insert cell
maxTimes = _.ceil(d3.max(showData, d => d.times))
Insert cell
meanTimes = d3.mean(showData, d => d.times)
Insert cell
medianTimes = d3.median(showData, d => d.times)
Insert cell
minPOC = d3.min(showData, d => d.poc)
Insert cell
medianPOC = d3.median(showData, d => d.poc)
Insert cell
maxPOC = d3.max(showData, d => d.poc)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
colors = new Object({
gray: '#AEA2B1',
black: '#2D1832',
highlight: '#FFED6B',
})
Insert cell
colorScale = chroma.scale(["#ff8464", "#41c6fa"].map(color => chroma(color).saturate(2))).mode('lch')
Insert cell
alternateColorScale = chroma.scale(["#ffeaf9", "#1b0050"].map(color => chroma(color).saturate(0))).mode('lch')
Insert cell
linearGradient = (selection, id, colors, x1, x2, y1, y2) => {
selection.append('defs')
.append('linearGradient')
.attr('id', id)
.attr('gradientUnits', 'userSpaceOnUse')
.attr('x1', x1).attr('x2', x2)
.attr('y1', y1).attr('y2', y2)
.selectAll('stop')
.data(colors).join('stop')
.attr('offset', (d, i) => `${Math.floor(i * 100 / (colors.length - 1))}%`)
.attr('stop-color', d => d.color)
.attr('stop-opacity', d => d.opacity > -1 ? d.opacity : 1)
}
Insert cell
normalizeEarly = d3.scaleLinear().range([0, maxEarlyRatio])
Insert cell
normalizeDayOf = d3.scaleLinear().range([0, maxDayOfRatio])
Insert cell
Insert cell
Insert cell
d3 = require('d3')
Insert cell
_ = require('lodash')
Insert cell
chroma = require('chroma-js')
Insert cell
years = [2016, 2018]
Insert cell
data = new Object({
counties: {
2018: cleanData(await FileAttachment("countiesData2018@1.csv").csv()),
2016: cleanData(await FileAttachment("countiesData2016@2.csv").csv()),
},
states: {
2018: cleanData(await FileAttachment("statesData2018@2.csv").csv()),
2016: cleanData(await FileAttachment("countiesData2016@3.csv").csv()),
}
})
Insert cell
cleanData = (data) => {
_.each(data, d => {
_.each([
'early', 'dayOf', 'earlyRatio', 'dayOfRatio',
'dayOfPoll', 'earlyPoll', 'earlyDuration',
'income', 'inequality', 'poc',
], key => {
d[key] = +d[key] || 0
})
d.times = d.dayOfRatio / d.earlyRatio
})
return _.filter(data, d => d.earlyDuration && d.earlyRatio)
}
Insert cell
countiesData = data.counties[year]
Insert cell
statesData = data.states[year]
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
import {scrollSVG} from '@sxywu/utility-functions'
Insert cell
import {form} from "@mbostock/form-input"
Insert cell
import {select, autoSelect} from "@jashkenas/inputs"
Insert cell
import {rangeSlider} from '@mootari/range-slider'
Insert cell
import {inputsGroup} from '@bumbeishvili/input-groups'
Insert cell
style = html`
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@900&family=Work+Sans:wght@400;500;700;900&display=swap" rel="stylesheet">

<style>
body, select, option {
font-family: 'Work Sans', sans-serif;
line-height: 1.5;
}

h1, h2 {
font-family: 'Playfair Display', serif;
}

select {
padding: 2px 5px;
font-size: 16px;
max-height: 100px;
min-width: 300px;
}

.highlight {
display: inline-block;
background-color: ${colors.highlight};
padding: 0px 10px;
margin-top: 5px;
border-radius: 5px;
}
</style>
`
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