Skip to content

Instantly share code, notes, and snippets.

@pstuffa
Last active May 29, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pstuffa/387b29732d20b06e45dab93256ecc89b to your computer and use it in GitHub Desktop.
Save pstuffa/387b29732d20b06e45dab93256ecc89b to your computer and use it in GitHub Desktop.
Treemaps Test
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body {
margin:0;
/* position:fixed; */
top:0;
right:0;
bottom:0;
left:0;
}
.parent {
background-color: #f4f4f4;
border: 1px solid #000;
width: 100px;
max-width: 100px
height: 100px;
display: inline-table;
margin: 2px;
}
.child {
background-color: #d3d3d3;
width: 10px;
height: 10px;
border: 1px solid #afafaf;
padding: 2px;
margin: 2px;
display: inline-table;
}
</style>
</head>
<body>
<script>
var n = 30,
width = window.innerWidth,
height = window.innerHeight;
var parents = d3.select("body").selectAll(".parent")
.data(d3.range(n).map(Object))
.enter().append("div")
.attr("class", "parent")
.each(function() {
var thisParent = d3.select(this);
var children = thisParent.selectAll(".child")
.data(d3.range(Math.ceil(Math.random()*n)).map(Object))
.enter().append("div")
.attr("class", "child");
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment