Skip to content

Instantly share code, notes, and snippets.

@bdilday
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdilday/7d1ffcc722752d26cc03 to your computer and use it in GitHub Desktop.
Save bdilday/7d1ffcc722752d26cc03 to your computer and use it in GitHub Desktop.

mean (red) and total (black) rWAR by birth-state.

<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>mean and total rWAR by birth-state</title>
</head>
<style>
.land {
fill: #ddd;
}
.border {
fill: none;
stroke: #fff;
stroke-linejoin: round;
stroke-linecap: round;
}
.bubble {
stroke: #fff;
}
</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 = 600;
var path = d3.geo.path()
.projection(null);
var radius = d3.scale.sqrt()
.domain([0, 1000])
.range([0, 15]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("https://gist.githubusercontent.com/bdilday/7d1ffcc722752d26cc03/raw/9b30ed9b476eff35f15e5f39240b4954008727b9/us_war.json", function(error, us) {
//d3.json("us_war.json", function(error, us) {
if (error) return console.error(error);
console.log(us);
svg.append("path")
.datum(topojson.feature(us, us.objects.us_40))
.attr("class", "land")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.us_40, function(a, b) { return a !== b; }))
.attr("class", "border border--state")
.attr("d", path);
svg.append("g")
.attr("class", "bubble")
.selectAll("circle")
.data(topojson.feature(us, us.objects.us_40).features)
.enter()
.append("circle")
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("r", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? radius(d.properties["war"]) : radius(100*d.properties["mwar"]) ; } )
.attr("fill", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? "black" : "red" ;})
.attr("opacity", 0.8)
;
svg.append("g")
.attr("class", "bubble")
.selectAll("circle")
.data(topojson.feature(us, us.objects.us_40).features)
.enter()
.append("circle")
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("r", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? radius(100*d.properties["mwar"]) : radius(d.properties["war"]) ; } )
.attr("fill", function(d) { return d.properties["war"] > 100*d.properties["mwar"] ? "red" : "black" ;})
.attr("opacity", 0.3)
;
});
</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