Published
Edited
Aug 16, 2022
6 stars
Insert cell
Insert cell
france = {
const france_url =
"https://www.data.gouv.fr/fr/datasets/r/483b263b-98f7-4610-8b12-63e4630760de";
return fetch(france_url).then((x) => x.json());
}
Insert cell
Insert cell
departements = {
const depts = power_welsh(france, france.objects.a_dep2021_2154);

// Coordinates use the EPSG:2154 projection (Lambert 93)
// They must be retroprojected back to latitude/longitude in order to use d3.geoCentroid
depts.forEach(function (d, i) {
if (d.geometry.type === "Polygon") {
d.geometry.coordinates = d.geometry.coordinates.map((ring) =>
ring.map((x) => epsg_2154.inverse(x))
);
} else if (d.geometry.type === "MultiPolygon") {
d.geometry.coordinates = d.geometry.coordinates.map((polygon) =>
polygon.map((ring) => ring.map((x) => epsg_2154.inverse(x)))
);
}
});
return depts;
}
Insert cell
Insert cell
Insert cell
// colors still invalid since the table has not so many colors
d3.max(villes.map((x) => x.properties.color))
Insert cell
Insert cell
Insert cell
power_welsh = function (topo, objects) {
const com = topojson.feature(topo, objects).features;
com.forEach((d) => (d.properties.color = null));

const neighbors = topojson.neighbors(objects.geometries);

const neighbors_indices_sorted = function (neighbors) {
const neighbors_indices = neighbors.map((d, i) => ({ fid: i, v: d }));
return d3.sort(neighbors_indices, (d) => d.v.length);
};

function welsh(id_col) {
let n = 0;
for (const d of neighbors_indices_sorted(neighbors)) {
if (com[d.fid].properties.color === null) {
if (d.v.every((j) => com[j].properties.color !== id_col)) {
com[d.fid].properties.color = id_col;
} else n++;
}
}
return n;
}
let id_col = 0;
while (welsh(id_col)) {
++id_col;
}
//return id_col;
return com;
}

Insert cell
// Plot.carto is an experimental plugin for Observable Plot
import { Plot } from "@fil/plot-carto-0-5"
Insert cell
import { Select } from "@observablehq/inputs"
Insert cell
Insert cell
Insert cell
Insert cell
height = 0.6 * width
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