Published
Edited
Jun 29, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
selected_list = define_list(dendro_list, viz_list)
Insert cell
function define_list(dendro_list, viz_list){
let selected_list
console.log('list_type', list_type)
if (list_type === 'row-dendro'){
selected_list = dendro_list
}
else if (list_type === 'matrix-cell'){
selected_list = viz_list
} else {
// default to all visible genes
selected_list = viz_list
}
return selected_list
}
Insert cell
list_type = Generators.observe(notify => {

const mousemove = () => notify(cgm.params.tooltip.tooltip_type);
viewof cgm.addEventListener("click", mousemove);
notify(cgm.params.tooltip.tooltip_type);
return () => viewof cgm.removeEventListener("mousemove", mousemove);
})
Insert cell
viz_list = Generators.observe(notify => {
const mouse_click = () => notify(cgm.params.labels.visible_labels.row);
viewof cgm.addEventListener("click", mouse_click);
notify(cgm.params.labels.visible_labels.row);
return () => viewof cgm.removeEventListener("mousemove", mouse_click);
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// scale_opacity = d3.scaleSymlog()
scale_opacity = d3.scaleLinear()
.domain([0, 0.5])
.range([0, 1]);
Insert cell
scale_opacity(20)
Insert cell
startDate = "2020-03-01"
// startDate = "2020-02-01"
Insert cell
endDate = "2020-06-28"
Insert cell
new_totals = totals.map(x => {
let inst_county = x.county
let inst_date = x.date
if ('county' in x){

// let inst_diff = data_diff_dict[x.county][x.date]
// x.new = parseInt(inst_diff)

let inst_wave = data_wave_dict[x.county][x.date]
x.wave = parseFloat(inst_wave)
// console.log(inst_wave)
}
return x
})
Insert cell
Insert cell
// data_diff_dict = {
// let data_diff_dict = {}
// data_diff.forEach(x => data_diff_dict[x['']] = x)
// return data_diff_dict
// }
Insert cell
data_wave_dict = {
let data_wave_dict = {}
data_wave.forEach(x => data_wave_dict[x['']] = x)
return data_wave_dict
}
Insert cell
// shapes with populations and cases
totals = shapesWithPopulations.map(obj => {
let cases = nycFips.includes(obj.id) ? data[index].filter(c => c.county === 'New York City')[0]
: data[index][data[index].map(c => c.fips).indexOf(obj.id)] || {}
return ({...obj, ...cases})
})
Insert cell
dates = data.map(d => d[0].date).map(d => new Date(`${d}T20:00Z`))
Insert cell
nycFips = ["36061", "36047", "36081", "36005", "36085"]
Insert cell
excludeTerritories = new Set(["Guam", "Puerto Rico", "Virgin Islands"])
Insert cell
include_counties = new Set(selected_list)
Insert cell
pops = Object.assign(new Map(d3.zip(...await Promise.all([11].map(fetchPopulation))).map(([[id2018, population2018]]) => { return [id2018, population2018];
})), {title: "Population by County ID"})
Insert cell
countyShapes = topojson.feature(us, us.objects.counties).features.sort((a,b) => +a.id - +b.id)
Insert cell
shapesWithPopulations = countyShapes.map(s => ({...s, population: pops.get(s.id)}))
Insert cell
rawData = d3.csvParse(
await (await fetch(
"https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"
)).text()
)
Insert cell
totals[3140]
Insert cell
Insert cell
// //
// data_diff = d3.csvParse(
// await (await fetch(
// "https://raw.githubusercontent.com/cornhundred/covid-19-heatmap/master/data/data_diff.csv"
// )).text()
// )
Insert cell
//
data_wave = d3.csvParse(
await (await fetch(
"https://raw.githubusercontent.com/cornhundred/covid-19-heatmap/master/data/data_mid.csv"
)).text()
)
Insert cell
data = d3
.nest()
.key(d => d.date)
.entries(rawData.filter(d => !excludeTerritories.has(d.state)))
.map(d => d.values)
.filter(d => d[0].date >= startDate)
.filter(d => d[0].date <= endDate)
Insert cell
us = d3.json("https://unpkg.com/us-atlas@3/counties-albers-10m.json")
Insert cell
topojson = require("topojson-client@3")
Insert cell
mutable index = 0;
Insert cell
{
mutable index = dates.indexOf(day);
}
Insert cell
function fetchPopulation(date) {
return d3.json("https://api.census.gov/data/2018/pep/population?get=POP&for=county:*&DATE_CODE=" + date).then(rows => rows.slice(1).sort((a, b) => d3.ascending(a[2], b[2]) || d3.ascending(a[3], b[3])).map(([population,, state, county]) => [state + county, +population]));
}
Insert cell
import {radio} from "@jashkenas/inputs"
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
import {Scrubber} from "@mbostock/scrubber"
Insert cell
Insert cell
// import {map, pops, totals, variable, nycFips} from '17e290f7eb004d0d'
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