Built with blockbuilder.org
Last active
May 22, 2017 20:50
-
-
Save leenoah1/8e66970c614f702ab7f9751c7097febd to your computer and use it in GitHub Desktop.
Anacostia Census Map w/Tooltip
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
| license: mit |
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
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <title>Anacostia Watershed Census</title> | |
| <body> | |
| <div class="info"></div> | |
| <script src="//d3js.org/d3.v4.min.js"></script> | |
| <script src="//d3js.org/topojson.v2.min.js"></script> | |
| <script> | |
| var width = 960, height = 500; | |
| var svg = d3.select('body').append('svg') | |
| .attr('width', width) | |
| .attr('height', height); | |
| // For d3 representation of various stateplanes, see: d3-stateplane | |
| // We'll set the scale and translate later, based on the data | |
| var projection = d3.geoConicConformal() | |
| .parallels([38 + 18 / 60, 39 + 27 / 60]) | |
| .rotate([77, -37 - 40 / 60]); | |
| var path = d3.geoPath() | |
| .projection(projection); | |
| d3.json("https://raw.githubusercontent.com/leenoah1/class_project/master/geop-wtshd.json", function(error, json) { | |
| if (error) throw error; | |
| // Convert topojson to geojson | |
| geojson = topojson.feature(json, json.objects.NAD83censuswtshd); | |
| // Set the projection's scale and translate based on the geojson | |
| projection.fitSize([960, 500], geojson); | |
| // Plot the individual counties | |
| svg.selectAll('path.tract') | |
| .data( geojson.features ) | |
| .enter().append('path') | |
| .attr('d', path) | |
| .attr('class', 'tract') | |
| .style('fill', 'none') | |
| .style('stroke', '#000') | |
| .style('stroke-opacity', '1') | |
| .on('mouseover', function(d, i) { | |
| console.log('mouseover:', i, d); | |
| d3.select(this).attr('fill', 'yellow'); | |
| d3.select(".info").html("<br>White: " + d.properties.White_NewP | |
| + "<br>Latino: " + d.properties.Latino_New | |
| + "<br>Black: " + d.properties.Black_NewP | |
| + "<br>Asian: " + d.properties.Asian_NewP | |
| + "<br>Other Race: " + d.properties.OtherRace_ | |
| + "<br>MoreThanOneRace: " + d.properties.More1Race_) | |
| }) | |
| d3.format(",d")(3.14159) | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment