Created
January 27, 2016 01:45
This file contains 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 svg = d3.select('#example-1') | |
.append('svg') | |
.attr('width', 202) | |
.attr('height', 202); | |
var data = d3.range(10).map(function (d, i) { | |
return i; | |
}); | |
// draw a rect to act as an outline | |
svg.append('rect') | |
.style('fill', '#444') | |
.attr('width', 202) | |
.attr('height', 202); | |
svg.selectAll('g') | |
.data(data) | |
.enter() | |
.append('g') | |
.selectAll('rect') | |
.data(data) | |
.enter() | |
.append('rect') | |
.attr('x', function(d) { | |
return d * 20 + 1; | |
}) | |
.attr('y', function() { | |
var i = d3.select(this.parentNode).datum(); | |
return i * 20 + 1; | |
}) | |
.attr('width', 20) | |
.attr('height', 20) | |
.style('fill', function(d) { | |
var i = d3.select(this.parentNode).datum(); | |
if ((i + d) % 2 !== 0) { | |
return 'black'; | |
} | |
return 'white'; | |
}); |
This file contains 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"> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> | |
</head> | |
<body> | |
<div id="example-1"></div> | |
<script type="text/javascript" src="./app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment