Skip to content

Instantly share code, notes, and snippets.

Last active September 6, 2021 20:26
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Swiss Cantons
license: gpl-3.0
Display the source blob
Display the rendered blob
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
.canton {
fill: #bbb;
.canton-boundary {
fill: none;
stroke: #fff;
stroke-linejoin: round;
text {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 10px;
text-anchor: middle;
<script src="//"></script>
<script src="//"></script>
var width = 960,
height = 600;
var projection = d3.geo.albers()
.rotate([0, 0])
.center([8.3, 46.8])
.translate([width / 2, height / 2])
var path = d3.geo.path()
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("readme-swiss.json", function(error, swiss) {
if (error) throw error;
var cantons = topojson.feature(swiss, swiss.objects.cantons);
.attr("class", "canton")
.attr("d", path);
.datum(topojson.mesh(swiss, swiss.objects.cantons, function(a, b) { return a !== b; }))
.attr("class", "canton-boundary")
.attr("d", path);
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("dy", ".35em")
.text(function(d) { return; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment