Skip to content

Instantly share code, notes, and snippets.

@russdb
Created August 9, 2018 04:58
Show Gist options
  • Save russdb/951ba0dcaed2508a95f808f02584f95e to your computer and use it in GitHub Desktop.
Save russdb/951ba0dcaed2508a95f808f02584f95e to your computer and use it in GitHub Desktop.
Symbol Map
license: gpl-3.0

The area of each circle in this symbol map is proportional to the population of the associated state.

forked from mbostock's block: Symbol Map

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.states {
fill: #ccc;
stroke: #fff;
}
.symbol {
fill: steelblue;
fill-opacity: .8;
stroke: #fff;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var radius = d3.scale.sqrt()
.domain([0, 1e6])
.range([0, 10]);
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
queue()
.defer(d3.json, "https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/us.json")
.defer(d3.json, "us-state-centroids.json")
.await(ready);
function ready(error, us, centroid) {
if (error) throw error;
svg.append("path")
.attr("class", "states")
.datum(topojson.feature(us, us.objects.states))
.attr("d", path);
svg.selectAll(".symbol")
.data(centroid.features.sort(function(a, b) { return b.properties.population - a.properties.population; }))
.enter().append("path")
.attr("class", "symbol")
.attr("d", path.pointRadius(function(d) { return radius(d.properties.population); }));
}
</script>
Display the source blob
Display the rendered blob
Raw
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