Built with blockbuilder.org
Last active
December 20, 2017 05:18
-
-
Save romsson/8772b6e630f97df800f9b5ec6033222f to your computer and use it in GitHub Desktop.
random rects size and position (grids)
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
license: mit |
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> | |
<meta charset="utf-8"> | |
<body> | |
<script src="http://d3js.org/d3.v4.js"></script> | |
<script src="http://romsson.github.io/d3-gridding/build/d3-gridding.js"></script> | |
<script> | |
var width = 600, | |
height = 400; | |
var gridding = d3.gridding() | |
.size([width, height]) | |
.valueWidth("w") | |
.valueHeight("h") | |
.mode("coordinate"); | |
// Distribution from https://bl.ocks.org/mbostock/4248145 | |
var randomX = d3.randomNormal(width / 2, 80), | |
randomY = d3.randomNormal(height / 2, 80), | |
data = d3.range(2000).map(function() { | |
return {w: randomX()/10000, h: randomY()/10000}; | |
}); | |
var griddingData = gridding(data); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.selectAll(".square") | |
.data(griddingData) | |
.enter().append("rect") | |
.style("fill", "none") | |
.style("stroke", "black") | |
.attr("width", function(d) { return d.width; }) | |
.attr("height", function(d) { return d.height; }) | |
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment