Please refer to gridmap-layout-usa for more information.
Created
January 12, 2016 04:13
-
-
Save kristw/2f628465e36f9821325d to your computer and use it in GitHub Desktop.
US Grid Map
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"> | |
<style> | |
body{ | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12px; | |
} | |
svg{ | |
margin-top: 5px; | |
/*border: 1px solid #ccc;*/ | |
} | |
text{ | |
font-weight: 300; | |
} | |
</style> | |
<body> | |
<p align="center"> | |
<svg></svg> | |
</div> | |
<script src="http://d3js.org/queue.v1.min.js"></script> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<!-- When import this way, the data is available as global variable "gridmapLayoutUsa" --> | |
<script src="https://rawgit.com/kristw/gridmap-layout-usa/master/dist/gridmap-layout-usa.min.js"></script> | |
<script> | |
var options = { | |
rectWidth: 45, | |
rectHeight: 45 | |
}; | |
// Define color scale | |
var color = d3.scale.quantize() | |
.domain([1, 20]) | |
.range(['#b2ddf0', '#92bcd8', '#769cbf', '#5d7da7', '#46608f', '#334577', '#232d5f']); | |
var svg = d3.select('svg') | |
.attr('width', 12 * options.rectWidth) | |
.attr('height', 8 * options.rectHeight); | |
var sEnter = svg.append('g') | |
.selectAll('g') | |
.data(gridmapLayoutUsa) | |
.enter().append('g') | |
.attr('transform', function(d){return 'translate('+(d.x*options.rectWidth)+','+(d.y*options.rectHeight)+')';}); | |
sEnter.append('rect') | |
.attr('width', options.rectWidth) | |
.attr('height', options.rectHeight) | |
.attr('vector-effect', 'non-scaling-stroke') | |
.style('opacity', 0.5) | |
.style('stroke', '#aaa') | |
.style('fill', function(d){return color(d.name.length);}); | |
sEnter.append('text') | |
.attr('x', options.rectWidth/2) | |
.attr('y', options.rectHeight/2 + 2) | |
.style('text-anchor', 'middle') | |
.text(function(d){return d.key;}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Master @kristw
I'm stealing your block for my infovisIntro class (http://infovis.co/infovisIntro), and I cannot iframe it because you are not requesting d3 and queue using https. I created a fork and fixed it on my version (https://gist.github.com/john-guerra/fb908fb28bbfeb20b108c90d80511bfa), but it seems there is no way to send pull requests here, hence this message.