Unlisted
Edited
Nov 2, 2023
Insert cell
Insert cell
updateMap = {
// Highlight the circles on the map that we just selected
d3.select(viewof map).selectAll("circle")
.filter(d => {return tree.map(d => d.name).includes(+d.OBJECTID)})
.transition()
.attr("opacity", 1)
.attr("r", 20)

// Return the unselected circles on the map to their original state
d3.select(viewof map).selectAll("circle")
.filter(d => {return !tree.map(d => d.name).includes(+d.OBJECTID)})
.transition()
.attr("opacity", .5)
.attr("r", 5);

// Set the labels (school names) and colors for the terminal nodes
const chart = d3.select(viewof mychart);
chart.selectAll("text").filter(d => d.depth == 3).text(d => schoolNames.get(d.data.name.toString()));
chart.selectAll("circle").filter(d => d.depth == 3).transition().attr("fill", "crimson");
}
Insert cell
map
Insert cell
Insert cell
Insert cell
Insert cell
import {viewof chart as tree} with {width as width} from "77ce9578be89bb86"
Insert cell
Insert cell
schoolNames = {
// Create a map from OBJECTID to Name -- used for labels
const mymap = new Map();
schools.forEach(d => { mymap.set(d.OBJECTID, d.Name) });
return mymap;
}
Insert cell
schools // We do a little filtering so these should be only the universities
Insert cell
viewof schools = Inputs.table(schools_csv, {
value: schools_csv.filter(d => d.Name.includes("iversity")),
multiple: true
})
Insert cell
schools_csv = FileAttachment("Maine_Schools_GeoLibrary.csv").csv()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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