Published
Edited
Nov 6, 2021
12 stars
Insert cell
Insert cell
{
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("background", "beige");
const projection = d3
.geoMercator()
.translate([width / 2, height / 1.71])
.scale(width / 6.356)
.rotate([-100, 0])
.clipExtent([
[4, 4],
[width - 4, height - 4]
]);

const path = d3.geoPath(projection);

svg
.append("g")
.selectAll("path")
.data(world.features)
.join("path")
.attr("d", path)
.style("fill", (d) =>
["USSR", "Far Eastern SSR", "Mongolia"].includes(d.properties.NAME)
? "#CD543C" /*"red"*/
: "white"
)
.style("fill-opacity", 0.75)
.style("stroke", "black")
.style("stroke-width", 1.3)
.append("title")
.text((d) => d.properties.NAME);

// border
svg
.append("g")
.append("path")
.datum({ type: "Sphere" })
.attr("d", path)
.attr("stroke", "black")
.attr("stroke-width", 8)
.attr("fill", "none");
svg
.append("g")
.append("path")
.datum({ type: "Sphere" })
.attr("d", path)
.attr("stroke", "white")
.attr("stroke-width", 3)
.attr("fill", "none");

return svg.node();
}
Insert cell
shp = FileAttachment("1938.zip").zip()
Insert cell
world = shapefile.read(
await shp.file(shp.filenames.find((d) => d.endsWith(".shp"))).stream(),
await shp.file(shp.filenames.find((d) => d.endsWith(".dbf"))).stream()
)
Insert cell
height = Math.floor(width / 1.6)
Insert cell
shapefile = require("shapefile")
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