For the German election we wanted to use a cartogram of election districts but didn't find anything good, so we created our own. Here's a little nerd thread how the final algorithm worked 🤓 🧵 #gis #cartogram #election #datavis #cartography
As input for the cartogram we use a pre-projected TopoJSON basemap of election districts with baked-in centroids (inner points). We used Mapshaper to generate the file.
Then we used a Delaunay tessellation of the district centroids. This later helps the districts to stay close to their geographical neighbors.
Due to Germany's convex outer shape we removed edges longer than a certain threshold and ended up with this final "network" of nodes and links.

Before running the network layout simulation on this, we marked all the outer districts as fixed. This allows the final layout to stay "in shape" of the country as a whole, which is important for readers to recognize their country.

We used the TopoJSON arcs to automatically find these districts.

Some of these fixed districts turned out to be too close to each other, so we defined a few exceptions for border districts we want to be free, and also a few custom positions that prevent the nodes to "leave" the country.
To compute the final layout we use a force simulation with 3 forces: one of them keeps neighboring districts together while another pushes districts away from each other if they are too close. Coloring the nodes helped to identify problems during the process.