Published
Edited
Dec 14, 2020
4 forks
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
CityBureauZIPList = fetch(
"https://city-bureau-covid-prod.s3.us-east-2.amazonaws.com/zip-list.json"
).then(resp => resp.json())
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
maxDateQuery = {
const query = `
query getZIPMaxDates {
zipcode_testing_results_change(distinct_on: [date], order_by: [{date: desc}], limit: 2) {
date
}
}
`;

return graphql({
query,
operation: "getZIPMaxDates"
}).then(({ zipcode_testing_results_change }) =>
zipcode_testing_results_change.map(({ date }) => date)
);
}
Insert cell
// TODO: Do we need ZIPs without Census Data?
ILZIPGeoData = ILZIPData.filter(({ census }) => census).map(
({ census: { geom: geometry, county, ...census }, ...properties }) => ({
type: "Feature",
properties: { ...properties, county, census },
geometry
})
)
Insert cell
Insert cell
Insert cell
ILZIPQueryResults = {
const query = `
query getZIPHistorical {
zipcode_testing_results_change(distinct_on: [zipcode], order_by: [{zipcode: desc}, {date: desc}], where:{date:{_gte:"${threeDaysAgo}"}}) {
date
zipcode
confirmed_cases
confirmed_cases_change
confirmed_cases_change_pct
total_tested
total_tested_change
total_tested_change_pct
pct_population_moe
below_moe_threshold
cases_per_capita
cases_per_1000
${ageFields.join("\n")}
${genderFields.join("\n")}
${raceFields.join("\n")}
census {
geom
population
age
race
county
}
}
}
`;

return graphql({
query,
operation: "getZIPHistorical"
}).then(({ zipcode_testing_results_change }) => ({
zipcode_testing_results_change
}));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
demographicFieldTypes = ["confirmed_cases", "total_tested"]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
IllinoisCovidZIPHistoricalObject = Object.fromEntries(NestedHistoricalArray)
Insert cell
IllinoisCovidZIPFlatHistoricalArray = NestedHistoricalArray.reduce((acc, d) => {
try {
acc = acc.concat(flattenZIPData(d[1]));
} catch {}
return acc;
}, [])
Insert cell
Insert cell
ZIPOverride = searchParams.get("zipcode")
Insert cell
searchParams = new URLSearchParams(location.search)
Insert cell
Insert cell
Insert cell
cdnRoot = "https://d38afsumxukqre.cloudfront.net/"
Insert cell
Insert cell
Insert cell
STORAGE_KEY = "TCRCovidMapSelectedZIP"
Insert cell
Insert cell
Insert cell
translations = ({
en: {
selectorPrefix: "As of <b>{date}</b>, ZIP code",
selectorSuffix: "had",
selectors: {
label: "{zip} in {county} County",
cases: "cases"
},
legend: {
title: "Total cases"
},
maphelp: {
line1: "Want to see another ZIP code?",
line2: "<i>touch_app</i> Click on the map to explore"
},
countbox: {
total: "{cases} total confirmed cases",
per1k: "{per1k} cases per 1,000 people",
change: "Up {pct} (+{change} cases) from {date}.",
tests: "{tests} tests completed",
lessthan6: "Less than 6",
lessthan1: "less than 1%"
},
infobox: {
prisons:
"<i>error</i> Infections among incarcerated populations are not fully represented in this data, including Cook County Jail (60608) and Stateville Correctional Center (60403), and possibly other ZIP codes.",
threshold:
"<i>cancel</i> ZIP codes with fewer than six cases are not shown. The Illinois Department of Health says exposure should be an assumed threat everywhere in the state.",
cumulative:
"<i>add_circle</i> Case counts are cumulative, which means they include people who have died and those who have recovered."
},
resourcebox: {
icon: "<i>contact_support</i>",
link:
"Need help dealing with the crisis? <a>Find resources in {zip} from City Bureau's Chicago COVID Resource Finder</a>."
},
tables: {
title: "COVID-19 in {zip} by race and age",
racelabel: "Race",
agelabel: "Age",
caselabel: "Cases",
testedlabel: "Tests",
populationlabel: "Population",
races: {
Black: "Black",
White: "White",
Asian: "Asian",
Hispanic: "Hispanic",
Other: "Other",
"Left Blank": "Left blank",
"NH/PI*": "Native Hawaiian/Pacific Islander",
"AI/AN**": "American Indian/Alaska Native",
black: "Black",
white: "White",
asian: "Asian",
hispanic: "Hispanic",
other: "Other",
leftblank: "Left blank",
nhpi: "Native Hawaiian/Pacific Islander",
aian: "American Indian/Alaska Native"
}
},
charts: {
title: "How {zip} compares to other ZIP codes in Illinois",
max: "Max: {value} ({zip})",
percapita: "Cases per 1,000",
total: "Total cases",
axis: "ZIP codes with comparable population estimates"
},
countygraf:
"{zip} is in {place} and has an estimated population of {pop} (±{moe}) according to the most recently available data from the US Census/American Community Survey. {place_start} has {place_cases} confirmed cases and {place_deaths} deaths to date. There have been {state_cases} confirmed cases and {state_deaths} deaths statewide in Illinois to date.",
download: {
buttontext: "Download the data",
description:
"Get the latest available numbers on confirmed coronavirus cases, testing totals, and counts by demographic in Illinois ZIP codes."
},
downloadHistorical: {
buttontext: "Download historical data",
description:
"See the daily tally of newly confirmed coronavirus cases and tests over time for each ZIP code, to date."
},
correction1:
"Correction (2020-04-15): A previous version of this tool mis-identified suburban Cook County as all of Cook County.",
covidsource:
"COVID-19 data source: Illinois Department of Public Health. Some data has yet to be provided by commercial laboratories (including counties). IDPH is working with commercial labs to obtain the necessary data. All numbers displayed are provisional and subject to change. ZIP code is ZIP code of residence, which may not be location of exposure.",
censussource:
"Geographic and population data source: US Census/American Community Survey. Per-capita figures are not calculated for ZIP codes with population margin of error greater than ± 10%. This map and figures display US Census ZIP Code Tabulation Areas (ZCTAs). The boundaries of ZCTAs may vary slightly from from postal ZIP codes."
},
es: {
selectorPrefix: "A partir del <b>{date}</b>, código postal",
selectorSuffix: "tenía",
selectors: {
label: "{zip} en el condado de {county}",
cases: "casos"
},
legend: {
title: "Casos en total"
},
maphelp: {
line1: "¿Quieres ver otro código postal?",
line2: "<i>touch_app</i> Haga clic en el mapa para explorar."
},
countbox: {
total: "{cases} total de casos confirmados",
per1k: "{per1k} casos por 1,000 personas",
change: "Un aumento de {pct} (+{change} casos) a partir del {date}.",
tests: "{tests} pruebas completadas",
lessthan6: "Menos de 6",
lessthan1: "menos de 1%"
},
infobox: {
prisons:
"<i>error</i> Las infecciones entre las poblaciones encarceladas no están totalmente representadas en estos datos, incluida la Cárcel del Condado de Cook (60608) y el Centro Correccional de Stateville (60403), y posiblemente otros códigos postales.",
threshold:
"<i>cancel</i> No se muestran los códigos postales con menos de seis casos. El Departamento de Salud de Illinois dice que la exposición debería ser una amenaza asumida en todo el estado.",
cumulative:
"<i>add_circle</i> Los recuentos de casos son acumulativos, lo que significa que incluyen personas que han muerto y aquellas que se han recuperado."
},
resourcebox: {
icon: "<i>contact_support</i>",
link:
"¿Necesita ayuda? <a>Encuentre recursos en {zip} del Chicago COVID Resource Finder de City Bureau</a>."
},
tables: {
title: "COVID-19 en {zip} por raza y edad",
racelabel: "Raza",
agelabel: "Edad",
caselabel: "Casos",
testedlabel: "Probado",
populationlabel: "Población",
races: {
Black: "Afroamericano",
White: "Blanco",
Asian: "Asiático",
Hispanic: "Hispano",
Other: "Otro",
"Left Blank": "Dejado en blanco",
"NH/PI*": "Nativo hawaiano/isleño del Pacífico",
"AI/AN**": "Indoamericano/nativo de Alaska",
black: "Afroamericano",
white: "Blanco",
asian: "Asiático",
hispanic: "Hispano",
other: "Otro",
leftblank: "Dejado en blanco",
nhpi: "Nativo hawaiano/isleño del Pacífico",
aian: "Indoamericano/nativo de Alaska"
}
},
charts: {
title: "Cómo {zip} se compara con otros códigos postales en Illinois",
max: "Max: {value} ({zip})",
percapita: "Casos por 1,000",
total: "Casos en total",
axis: "Códigos postales con estimaciones de población comparables"
},
countygraf:
"{zip} está en {place} y tiene una población estimada de {pop} (± {moe}) de acuerdo con los datos más recientes disponibles de la Encuesta del Censo de los Estados Unidos. {place_start} tiene {place_cases} casos confirmados y {place_deaths} muertes hasta la fecha. Han habido {state_cases} casos confirmados y {state_deaths} muertes en todo el estado en Illinois hasta la fecha.",
download: {
buttontext: "Descargar los datos",
description:
"Obtén los números recientes por demografía en los códigos postales de Illinois, de los casos confirmados de coronavirus, total de pruebas y conteos."
},
downloadHistorical: {
buttontext: "Descarga los datos comprobados",
description:
"Está al tanto del recuento diario a la fecha y por código postal, de los casos de coronavirus y pruebas recién confirmados."
},
correction1:
"Corrección (15-04-2020): una versión anterior de esta herramienta identificó erróneamente el Condado de Cook suburbano como todo el Condado de Cook.",
covidsource:
"Fuente de datos COVID-19: Departamento de Salud Pública de Illinois. Algunos datos aún no han sido proporcionados por laboratorios comerciales (incluidos los condados). IDPH está trabajando con laboratorios comerciales para obtener los datos necesarios. Todos los números que se muestran son provisionales y están sujetos a cambios. El código postal es el código postal de residencia, que puede no ser el lugar de exposición.",
censussource:
"Fuente de datos geográficos y de población: Censo de EE.UU. Las cifras per cápita no se calculan para los códigos postales con un margen de error de la población superior a ± 10%. Este mapa y las figuras muestran las áreas de tabulación del código postal del censo de EE. UU. Los límites de los ZCTA pueden variar ligeramente de los códigos postales."
}
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { legend } from "@d3/color-legend"
Insert cell
import { select } from "@jashkenas/inputs"
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