8
I am having some trouble trying to re-create
I've attempted to add the features of http://bl.ocks.org/950642 to http://mbostock.github.com/d3/talk/20111116/force-collapsible.html
and tried to do:
node.enter().append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name });
However that results in the circles disappearing and all the text is clumped in the top left corner.
Any ideas what I might be doing wrong? Here is my JS:
here is a jsfiddle: for some reason it isn't working though here because of the .json file I think...
var width = 960,
height = 500,
node,
link,
root;
var force = d3.layout.force()
.on("tick", tick)
.charge(function(d) { return d._children ? -d.size / 100 : -30; })
.linkDistance(function(d) { return d.target._children ? 80 : 30; })
.size([width, height]);
var vis = d3.select("#chart").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("../data/flare.json", function(json) {
root = json;
root.fixed = true;
root.x = width / 2;
root.y = height / 2;
update();
});
function update() {
var nodes = flatten(root),
links = d3.layout.tree().links(nodes);
// Restart the force layout.
force
.nodes(nodes)
.links(links)
.start();
// Update the links…
link = vis.selectAll("line.link")
.data(links, function(d) { return d.target.id; });
// Enter any new links.
link.enter().insert("line", ".node")
.attr("class", "link")
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2",