Published
Edited
Oct 13, 2020
Insert cell
Insert cell
{
const context = DOM.context2d(width, height);
yield context.canvas;
const path = d3.geoPath(projection, context);
const source = await shapefile.open(
await FileAttachment("UScounties.shp").stream(),
null
);
// const source = await shapefile.open(await FileAttachment("constituencies.shp").stream(), null);
while (true) {
const result = await source.read();
if (result.done) break;
context.beginPath(), path(result.value), context.stroke();
}
}
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
projection = d3.geoAlbersUsa()
.scale(1272)
.translate([width / 2, height / 2])
Insert cell
width = 954
Insert cell
height = 600
Insert cell
d3 = require("d3-geo@1")
Insert cell
shapefile = require("shapefile@0.6")
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