Built with blockbuilder.org
Last active
March 11, 2019 17:39
-
-
Save jrzief/3c03ccf9ed93edeba99d65719803a6d7 to your computer and use it in GitHub Desktop.
NJ Central Region
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> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<style> | |
body{ | |
-webkit-font-smoothing: antialiased; | |
font-family: Roboto,sans-serif; | |
width:960px; | |
margin:50px auto; | |
} | |
.state-td{ | |
background: rgb(230, 230, 230); | |
border: 2px solid white; | |
text-align: center; | |
} | |
.SE{background:#FFEA00;} | |
.NE{background:#CE93D8;} | |
.MW{background:#FF9E80;} | |
.SW{background:#4CAF50;} | |
</style> | |
</head> | |
<body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<table id="st-grid" style="width:600px; margin:0 auto;height:400px;table-layout:fixed;border-collapse:collapse;"><tbody></tbody></table> | |
<script> | |
var muniLoc =[ | |
[ , , "Hillsborough", "Franklin" , , , , ] | |
,[ , ,"Montgomery", ,"New Brunswick", , , ] | |
,[ ,"Hopewell Boro","Hopewell Township","Pennington","Princeton","Plainsboro", "Jamsburg", ] | |
,[ "Trenton","Ewing","Lawrence","West Windsor","Cranberry","Monroe", , ] | |
,[ , ,"Hamilton","Robbinsville","Hightstown", , , ] | |
]; | |
var USRegions ={ | |
'NW':['Trenton', 'Ewing', 'Lawrence', 'Princeton', 'Pennington', 'Hopewell Boro', 'Hopewell Township'] | |
,'SW':['Hamilton', 'Hightstown', 'West Windsor', 'Robbinsville', 'Plainsboro','Cranberry'] | |
,'NE':['Hillsborough', 'Montgomery', 'New Brunswick', 'Franklin'] | |
,'SE':['Monroe', 'Jamsburg'] | |
}; | |
var stateToRegion ={}; | |
d3.keys(USRegions).forEach(function(r){ | |
USRegions[r].forEach(function(st){ stateToRegion[st]=r; }) | |
}); | |
d3.select("#st-grid").select("tbody") | |
.selectAll("tr").data(muniLoc).enter().append("tr") | |
.selectAll("td").data(function(d){ return d;}).enter().append("td") | |
.attr("class",function(d){ return d==undefined? "blank-td" : "state-td " +stateToRegion[d];}) | |
.text(function(d){ return d}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment