Skip to content

Instantly share code, notes, and snippets.

@dnseminara
Created June 18, 2014 19:18
Show Gist options
  • Save dnseminara/1e9b8154afe7f5597862 to your computer and use it in GitHub Desktop.
Save dnseminara/1e9b8154afe7f5597862 to your computer and use it in GitHub Desktop.
Public Transportation in Major Metropolitan Statistical Areas
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.states {
fill: #99CCFF;
stroke: #fff;
}
.symbol {
fill: #FFCC33;
fill-opacity: .7;
stroke: #666666;
}
.symbol:hover {
fill: #CC9900;
fill-opacity: .9;
stroke: #000000;
}
.d3-tip {
line-height: 1;
font-weight: bold;
padding: 6px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
border-radius: 2px;
max-width: 250px;
text-align: center;
}
.d3-tip:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: rgba(0, 0, 0, 0.8);
content: "\25BC";
position: absolute;
text-align: center;
}
.d3-tip.n:after {
margin: -1px 0 0 0;
top: 100%;
left: 0;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script>
var width = 960,
height = 600;
var radius = d3.scale.sqrt()
.domain([0, 750])
.range([0, 12]);
var tip = d3.tip().attr('class', 'd3-tip').html(function(d) { return d.properties.NAMELSAD.replace(" Metro Area", "") + ": " + (d.properties.metro)/100 + "%"; });
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
queue()
.defer(d3.json, "us.json")
.defer(d3.json, "msa.json")
.await(ready);
function ready(error, us, msa) {
svg.append("path")
.attr("class", "states")
.datum(topojson.feature(us, us.objects.us_states))
.attr("d", path);
svg.call(tip)
svg.selectAll(".symbol")
.data(msa.features.sort(function(a, b) { return b.properties.metro - a.properties.metro; }))
.enter().append("path")
.attr("class", "symbol")
.attr("d", path.pointRadius(function(d) { return radius(d.properties.metro); }))
.on("mouseover", tip.show)
.on("mouseout", tip.hide)
}
</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.
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