Published
Edited
Mar 1, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
voronoiStateFeatures = topojson.feature(
voronoiStateTopojson,
voronoiStateTopojson.objects.states
)
Insert cell
colorList = {
const colors = d3.schemeCategory10;
const stateGeoms = voronoiStateTopojson.objects.states.geometries;
const colorList = stateGeoms.map(d => '');
const neighbors = topojson.neighbors(stateGeoms);
stateGeoms.forEach((d, i) => {
const color =
colors.find(
c =>
!neighbors[i].some(n => {
return colorList[n] === c;
})
) || colors[0];

colors.push(colors.shift());

colorList[i] = color;
});
return colorList;
}
Insert cell
countryShape = topojson.merge(
us,
us.objects.states.geometries.filter(d => d.id !== "02" && d.id !== "15")
)
Insert cell
voronoiStateTopojson = topojson.topology({ states: voronoiStates })
Insert cell
voronoiStates = {
const vs = stateAbbrs.map(s =>
topojson.merge(
voronoiTopojson,
voronoiTopojson.objects.voronoi.geometries.filter(
d => d.properties.site.properties.state == s
)
)
);
return {
type: "GeometryCollection",
geometries: vs.map(d => ((d.properties = {}), d))
};
// vs.forEach((_, i) => vs.color = stateAbbrs[i])
}
Insert cell
voronoiTopojson = topojson.topology({voronoi: voronoiGeojson})
Insert cell
voronoiGeojson = d3.geoVoronoi().polygons(data)
Insert cell
stateAbbrs = [...new Set(data.map(d => d.properties.state))]
Insert cell
data = d3.csvParse(await FileAttachment("airports.csv").text(), d => ({
type: "Feature",
properties: fixMap.has(d.name) ? { ...d, state: fixMap.get(d.name) } : d,
geometry: {
type: "Point",
coordinates: [+d.longitude, +d.latitude]
}
}))
Insert cell
fixMap = new Map([
['Fairchild AFB', 'WA'],
['Minot AFB', 'ND'],
['Grand Forks AFB', 'ND'],
['Ellsworth AFB', 'SD'],
['MC Clellan-Palomar Airport', 'CA'],
['Hilton Head', 'SC'],
['Marquette County Airport', 'MI'],
['University Park', 'PA']
])
Insert cell
projection = d3.geoAlbers().scale(1300).translate([487.5, 305])
Insert cell
Insert cell
us = FileAttachment("states-albers-10m.json").json()
Insert cell
topojson = require("topojson")
Insert cell
d3 = require.alias({"d3-array": "d3@6", "d3-delaunay": "d3@6", "d3-geo": "d3@6"})("d3@6", "d3-geo-voronoi@1")
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