Public
Edited
Jan 3, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
topology = {
const response = await fetch(
`https://raw.githubusercontent.com/smartnews-smri/japan-topography/main/data/municipality/topojson/s0010/${topologyId}.json`
);
return response.json();
}
Insert cell
geometry = topojson.feature(topology, topology.objects[topologyId])
Insert cell
projection = d3.geoMercator().fitExtent(
[
[0, 0],
[width, height]
],
geometry
)
Insert cell
Insert cell
Insert cell
populationByCode = d3.index(population, (d) => d.region_code)
Insert cell
Insert cell
rescale = d3
.scaleLinear()
.domain([0, d3.max(population.map((d) => d[populationType]))])
.range([0.001, 10 ** (2 * (1 - exaggeration / 100))])
Insert cell
carto = topogram
.cartogram()
.projection(projection)
.properties((d) => ({
...d.properties,
...populationByCode.get(d.properties["N03_007"])
}))
.value((d) => {
const code = d.properties["N03_007"];
const val = rescale(populationByCode.get(code)?.[populationType] ?? 0);
return val;
})
Insert cell
populationByCode
Insert cell
cartogramFeatures = carto(
topology,
topology.objects[topologyId].geometries
).features.map((d) => {
const geometry = d.geometry;
geometry.coordinates =
geometry.type === "MultiPolygon"
? geometry.coordinates.map((poly) =>
poly.map((ring) => ring.map(projection.invert))
)
: geometry.coordinates.map((ring) => ring.map(projection.invert));
return d;
})
Insert cell
Insert cell
Insert cell
Insert cell
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