Skip to content

Instantly share code, notes, and snippets.

@pdbartsch
Last active March 29, 2023 18:06
Show Gist options
  • Save pdbartsch/49dad5efa95d3a8134e7 to your computer and use it in GitHub Desktop.
Save pdbartsch/49dad5efa95d3a8134e7 to your computer and use it in GitHub Desktop.
North America d3
data/*
*.zip
*.gzip
*.bu
*.paul
*.*~
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background-color: #e0f3f8;
}
.subunit.USB { fill: #d73027; }
.subunit.USK { fill: #fc8d59; }
.subunit.USH { fill: #ffffbf; }
.subunit.CAN { fill: #4575b4; }
.subunit.MEX { fill: #fee090; }
.subunit-boundary {
fill: none;
stroke: white;
stroke-width: 3;
stroke-linejoin: round;
}
.subunit-label {
fill: #404040;
fill-opacity: 1;
font-size: 20px;
font-weight: 600;
text-anchor: middle;
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 1160;
var projection = d3.geo.mercator()
.center([100, 50])
.scale(240)
.rotate([-180,0]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("nam.json", function(error, nam) {
var subunits = topojson.feature(nam, nam.objects.subunits)
/* ,places = topojson.feature(nam, nam.objects.places) */
;
svg.selectAll(".subunit")
.data(subunits.features)
.enter().append("path")
.attr("class", function(d) { return "subunit " + d.id; })
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(nam, nam.objects.subunits, function(a, b) { return a !== b; }))
.attr("d", path)
.attr("class", "subunit-boundary");
svg.selectAll(".subunit-label")
.data(subunits.features)
.enter().append("text")
.attr("class", function(d) { return "subunit-label " + d.id; })
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("dy", ".35em")
.text(function(d) { return d.properties.name; });
svg.append("path")
.datum(places)
.attr("d", path)
.attr("class", "place");
/*
svg.selectAll(".place-label")
.data(places.features)
.enter().append("text")
.attr("class", "place-label")
.attr("transform", function(d) { return "translate(" + projection(d.geometry.coordinates) + ")"; })
.attr("x", function(d) { return d.geometry.coordinates[0] > -1 ? 6 : -6; })
.attr("dy", ".35em")
.style("text-anchor", function(d) { return d.geometry.coordinates[0] > -1 ? "start" : "end"; })
.text(function(d) { return d.properties.name; });
*/
});
</script>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment