Built with blockbuilder.org
Last active
January 6, 2018 18:34
-
-
Save romsson/c595d62d19b5452eaf6ee6f776417797 to your computer and use it in GitHub Desktop.
fold by two (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"> | |
<style> | |
body { | |
font-family: Helvetica; | |
font-size: 10px; | |
} | |
rect { | |
fill: none; | |
stroke: black; | |
stroke-width: 1; | |
} | |
</style> | |
<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 max_depth = 15; | |
var gridding = d3.gridding(); | |
var data = d3.range(2); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g"); | |
function draw(params, data, level = 0) { | |
gridding.params(params); | |
var griddingData = gridding(data); | |
svg.selectAll(".square_" + level) | |
.data(griddingData) | |
.enter() | |
.append("rect") | |
.attr("class", ".square_" + level) | |
.attr("width", function(d) { return d.width; }) | |
.attr("height", function(d) { return d.height; }) | |
.attr("transform", function(d) { | |
return "translate(" + d.x + "," + d.y + ")"; | |
}); | |
// A0, A1, A2, .. | |
//svg.selectAll(".index_" + level) | |
// .data(griddingData) | |
// .enter().append("text") | |
// .attr("class", "index_" + level) | |
// .style('text-anchor', 'middle') | |
// .style('dominant-baseline', 'central') | |
// .attr("transform", function(d) { | |
// return "translate(" + d.cx + "," + d.cy + ")"; | |
// }) | |
// .text(function(d, i) { | |
// if(i === 1 && level < 9) | |
// return "A" + level; | |
// }); | |
var d = griddingData[0]; | |
if(level < max_depth) { | |
draw({ | |
size: [d.width, d.height], | |
offset: [d.x, d.y], | |
mode: level % 2 === 0 ? "horizontal": "vertical" | |
}, data, level + 1); | |
} | |
} | |
draw({ | |
size: [width, height], | |
offset: [0, 0], | |
mode: "vertical" | |
}, data); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment