Public
Edited
Jan 5, 2024
Fork of D3 world map
Insert cell
Insert cell
map = html`<svg viewBox="0 0 ${width} ${height}" style="display: block;">
<path d="${path(outline)}" fill="#fff"></path>
<path d="${path(graticule)}" stroke="#ccc" fill="none"></path>
<path d="${path(land)}"></path>
<path d="${path(borders)}" fill="none" stroke="#fff"></path>
<path d="${path(outline)}" fill="none" stroke="#000"></path>
${makeCircles()}
</svg>`
Insert cell
makeCircles = () => {
let output = locations.map(d => {
var xy = projection([d.lon, d.lat])
console.log({xy, d})
return `<circle cx="${xy[0]}" cy="${xy[1]}" r="5" fill="red" opacity=".8"></circle><text x="${xy[0]}" y="${xy[1]}" style="font-size:12px;text-anchor:end">${d['Country/Region']}</text>`
}).join('')
return output
}
Insert cell
r = d3.scaleSqrt().range([1, 50]).domain(d3.extent(locations, d => d['Value (Numeric)']))
Insert cell
Insert cell
centroids = FileAttachment("centroids.csv").csv()
Insert cell
projection = d3.geoEqualEarth()
Insert cell
Insert cell
path = d3.geoPath(projection)
Insert cell
height = {
const [[x0, y0], [x1, y1]] = d3.geoPath(projection.fitWidth(width, outline)).bounds(outline);
const dy = Math.ceil(y1 - y0), l = Math.min(Math.ceil(x1 - x0), dy);
projection.scale(projection.scale() * (l - 1) / l).precision(0.2);
return dy;
}
Insert cell
outline = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
borders = topojson.mesh(world, world.objects.countries, (a, b) => a !== b)
Insert cell
world = FileAttachment("countries-50m.json").json()
Insert cell
locations1 = FileAttachment("locations@1.json").json()
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