Published
Edited
Mar 1, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
saveableData = source
Insert cell
height = 600
Insert cell
mesh = d3
.geoVoronoi(data.map(({ longitude, latitude }) => [longitude, latitude]))
.cellMesh()
Insert cell
polygons = {
const polygons = voronoi.polygons(),
{ features } = polygons;
for (const [i, feature] of features.entries()) {
feature.properties.color =
(d3.max(neighbors[i], j => features[j].properties.color) + 1) | 0;
}
return polygons;
}
Insert cell
neighbors = voronoi.delaunay.neighbors
Insert cell
voronoi = d3.geoVoronoi(
shuffle(data.map(({ longitude, latitude }) => [longitude, latitude]))
)
Insert cell
shuffle = {
data;
return d3.shuffler(d3.randomLcg(0.9051667019185816));
}
Insert cell
colors = d3.schemeTableau10
Insert cell
data = d3.csvParseRows(source, ([name, longitude, latitude]) => ({
name,
longitude: +longitude,
latitude: +latitude
}))
Insert cell
cityData = {
const cityData = await d3.csv(
"https://data.cdc.gov/api/views/dxpw-cm5u/rows.csv",
({ PlaceName: city, Geolocation: loc, Population2010: pop }) => [
city,
+loc.replace(")", "").split(",")[1],
+loc.replace("(", "").split(",")[0],
+pop
]
);
return cityData.filter(d => d[3] > 500000).map(d => d.slice(0, 3));
}
Insert cell
projection = d3
.geoAlbers()
.scale(1280)
.translate([480, 300])
Insert cell
states = ({
type: "GeometryCollection",
geometries: us.objects.states.geometries.filter(
d => d.id !== "02" && d.id !== "15"
)
})
Insert cell
us = d3.json("https://cdn.jsdelivr.net/npm/us-atlas@1/us/10m.json")
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3", "d3-geo-voronoi@1")
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