Skip to content

Instantly share code, notes, and snippets.

@phoebebright
Created November 26, 2012 22:17
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 phoebebright/4151032 to your computer and use it in GitHub Desktop.
Save phoebebright/4151032 to your computer and use it in GitHub Desktop.
simple treema
{"description":"simple treema","endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.5001752848378613,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"editor_editor":{"coffee":false,"vim":false,"emacs":false,"width":600,"height":300,"hide":false}}
var data =[{"name": "dataset", "children":
[{"name" : "apples", "size": 50},
{"name" : "apples", "size": 50},
{"name" : "apples", "size": 50},
{"name" : "apples", "size": 50}]
}];
var width=300, height=300;
var treemap = d3.layout.treemap()
.children(function(d) { return d.children; })
.size([width,height])
.value(function(d) { return d.size; }) ;
var svg = d3.select("svg")
.attr("width", width)
.attr("height", height);
svg
.data(data)
.selectAll("rect")
.data(function(d){return treemap.nodes(d);})
.enter()
.append("rect")
.attr("fill", "red")
.attr("stroke", "black")
.call(cell)
.text(function(d) { return d.name; });
function cell(){
this
.attr("x",function(d){return d.x + "px";})
.attr("y",function(d){return d.y + "px";})
.attr("width",function(d){return d.dx - 1 + "px";})
.attr("height",function(d){return d.dy - 1 + "px";});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment