Skip to content

Instantly share code, notes, and snippets.

@mapsam
Last active December 28, 2015 22:39
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 mapsam/7573263 to your computer and use it in GitHub Desktop.
Save mapsam/7573263 to your computer and use it in GitHub Desktop.
Charmingly Inaccurate: States
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.
<!DOCTYPE html>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style>
.states {
fill: #6BA0B5;
stroke: #fff;
stroke-width:1px;
}
.states:hover {
fill:#00C78C;
}
</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 = 500;
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
var projection = d3.geo.albersUsa()
.scale(1000)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
d3.json('charmstates.json', function(error, us) {
svg.selectAll('.states')
.data(topojson.feature(us, us.objects.admin1_poly).features)
.enter()
.append('path')
.attr('class', 'states')
.attr('d', path);
});
</script>
</body>
</html>
October 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment