Public
Edited
Aug 1, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
mean_sending_distance = d3.rollup(
points,
(v) => d3.mean(v, (d) => d.distance),
(d) => d.sending_school_id
)
Insert cell
receiving_school_ids = Array.from(
new Set(receiving_zoned.map((d) => d.ATTSCH_ID))
)
Insert cell
receiving_school_counts = Object.fromEntries(
receiving_school_ids.map((d) => [d, 0])
)
Insert cell
location_lookup = new Map(
receiving_locations.features.map((d) => [
d.properties.school_id,
d.geometry.coordinates
])
)
Insert cell
Insert cell
points = {
let all_points = [];
for (const feature of sending.features) {
const sending_points = dot_density(
{ type: "FeatureCollection", features: [feature] },
receiving_school_ids,
students_per_point,
random_points,
5,
index
).map((d) => ({
x: d.x,
y: d.y,
school_id: d.field,
sending_school_id: feature.properties.school_id,
distance: hav.distance(d.x, d.y, ...location_lookup.get(d.field))
}));
all_points = all_points.concat(sending_points);
}
return all_points;
}
Insert cell
index = {
const dex = new KDBush(random_points.length);

for (const [x, y] of random_points) {
dex.add(x, y);
}
dex.finish();
return dex;
}
Insert cell
random_points = points_under_18.features[0].geometry.coordinates
Insert cell
points_under_18 = FileAttachment("points_under_18@2.geojson").json()
Insert cell
sending = {
const sending = structuredClone(boundary);
for (const zoned_school of sending.features) {
const recipients = sending_lookup.get(zoned_school.properties.school_id);
zoned_school.properties = {
...zoned_school.properties,
...receiving_school_counts,
...Object.fromEntries(recipients)
};
}
return sending;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
students_per_point = 5
Insert cell
KDBush = require("kdbush")
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