I am building a tree structure showing the Facebook user and his/her Facebook friends using D3.js. The root is the user and the child nodes are the friends. I have a fixed width in my UI and the problem is the child nodes will overlap to each other.
var nodes = tree.nodes(root).reverse(),
links = tree.links(nodes);
nodes.forEach(function(d) { d.y = d.depth * 130; });
var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("value", function(d){
return d.id; })
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")"; });
var defs = node.append("defs").attr("id", "imgdefs");
var imgPattern = defs.append("pattern")
.attr("id", "img")
.attr("height", 50)
.attr("width", 50)
.attr("x", "0")
.attr("y", "0");
imgPattern.append("image")
.attr("height", 60)
.attr("width", 60)
.attr("xlink:href", function(d) { return d.img; });
nodeEnter.append("circle")
.attr("r", 30)
.style("stroke","white")
.style("stroke-width", 4)
.attr("fill", "url(#img)");
I would like to display 10 friends per row/depth for the child nodes. Any help or suggestions please. Thank you!
Here is my jsfiddle: CODE HERE