Public
Edited
Dec 11, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
borderCoords = kyrgyzstan.geometry.coordinates.flat()
.map(d => ({
lat: d[0],
lng: d[1],
x: projection(d)[0],
y: projection(d)[1]
}))
Insert cell
borderRays = {
function toUnit(v1) {
const [x, y] = v1;
const length = Math.sqrt(x * x + y * y);
return [x/length, y/length];
}
function getUnitNormal(v1, v2) {
const dx = v2[0] - v1[0];
const dy = v2[1] - v1[1];
const norm = [dy, -dx];
return toUnit(norm);
}
const hullSegments = [];
const hullCoords = kyrgyzstan.geometry.coordinates[0];
for (let i = 0; i < hullCoords.length-1; i++) {
const [coord, nextCoord] = [hullCoords[i], hullCoords[i+1]];
hullSegments.push({
coords: [coord, nextCoord],
normal: getUnitNormal(coord, nextCoord)
});
}
const hullSegmentPairs = [];
for (let i = 0; i < hullSegments.length; i++) {
const j = (i == hullSegments.length) ? 0 : i+1;
const [segment, nextSegment] = [hullSegments[i], hullSegments[j]];
hullSegmentPairs.push({
segments: [segment, nextSegment]
});
}
return hullSegmentPairs
}
Insert cell
Insert cell
Insert cell
Insert cell
topojson.feature(world, world.objects.world_countries_data)
Insert cell
{
const coords = kyrgyzstan.geometry.coordinates.flat();
return [
_.min(coords, 0)[0],
_.min(coords, 1)[1],
_.max(coords, 0)[0],
_.max(coords, 1)[1]
]
}
Insert cell
Insert cell
Insert cell
Insert cell
delaunay = d3.Delaunay.from(borderCoords, d => d.x, d => d.y)
Insert cell
delaunay.points
Insert cell
Insert cell
Insert cell
Insert cell
voronoi = d3.Delaunay.from(borderCoords, d => d.x, d => d.y).voronoi([
0,
0,
width,
height
])
Insert cell
cities
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@6", "d3-geo-projection@2", "d3-geo-voronoi")
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