View this code at http://livecoding.io/5004429
Created
February 21, 2013 12:35
-
-
Save dwtkns/5004429 to your computer and use it in GitHub Desktop.
created by http://livecoding.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"libraries": [ | |
"d3" | |
], | |
"mode": "javascript", | |
"layout": "fullscreen mode (vertical)", | |
"resolution": "reset" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font: 11px sans-serif; | |
} | |
svg { border: solid 1px #CCC; } | |
.states { | |
fill: #DDD; | |
stroke: #CCC; | |
} | |
.boroughs { | |
fill: #AAA; | |
stroke: #666; | |
} | |
.borough:hover { | |
fill:#999; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<svg></svg> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var width = 1000; | |
var height = 900; | |
// Set the width and height of the SVG | |
var svg = d3.select('svg') | |
.style("width",width) | |
.style("height",height); | |
// Make a couple of groups in the SVG to hold our two different types of map data (state outlines and borough outlines). | |
var state_map = svg.append("g").attr("class","states"); | |
var borough_map = svg.append("g").attr("class","boroughs"); | |
var maptext = svg.append("g") | |
.attr("class","textGroup") | |
.append("text") | |
.attr("class","label").text("hey"); | |
// Start our map projection | |
var nyc_projection = d3.geo.mercator(); | |
// Set some variables to center it over NYC | |
nyc_projection.center([-74.25,40.925]) | |
.scale(436077) | |
.translate([0,0]); | |
// Start a "path generator" using the map projection above | |
var nyc_path = d3.geo.path().projection(nyc_projection); | |
borough_map.selectAll("path") | |
.data(livecoding.json.features) | |
.enter().append("path") | |
.attr("d", nyc_path) | |
.attr("class", "borough") | |
borough_map.selectAll("path") | |
.on("click",function(d) { | |
d3.select(".label") | |
.attr("transform", "translate(" + nyc_path.centroid(d) + ")") | |
.style("text-anchor", "middle") | |
.text(d.properties.BoroName); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment