Published
Edited
Jun 1, 2020
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
markdown = {
const md = await require('markdown-it@10.0.0/dist/markdown-it.js');
return new md();
}
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
Rx = require("https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.6.0-forward-compat.5/Rx.min.js")
Insert cell
d3array = require("d3-array@^2.2")
Insert cell
Insert cell
Insert cell
schools = d3.csvParse(schoolCSV)
Insert cell
Insert cell
us = FileAttachment("states-albers-10m.json").json()
Insert cell
Insert cell
format = d => `${d}`
Insert cell
Insert cell
data = d3array.group(schools, d => d.State)
Insert cell
stateNames = Array.from(data.keys())
Insert cell
numSchool = {
let numSchools = {}
for (let i = 0; i < us.objects.states.geometries.length; i++) {
numSchools[us.objects.states.geometries[i].properties.name] = 0
}
for (let i = 0; i < stateNames.length; i++)
{
let num = data.get(stateNames[i]).length
numSchools[stateNames[i]] = num
}
return numSchools
}
Insert cell
schoolList = {
let schoolList = {}
for (let i = 0; i < us.objects.states.geometries.length; i++) {
schoolList[us.objects.states.geometries[i].properties.name] = "No schools yet - message us to add your school!"
}
for (let i = 0; i < stateNames.length; i++)
{
let scs = data.get(stateNames[i])
let st = ""
for (let j = 0; j < scs.length; j++)
{
st = st + scs[j].School
if (j < scs.length - 1) {
st = st + ", "
}
}
schoolList[stateNames[i]] = st
}
return schoolList
}
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