If you only need the root node, you can have the root property in your object and set its value to true, than treat the node separately. You can also set this root in the center. Here's how we did it (d3 + Prototype - at that time - now switching to d3 + jQuery + underscore):
getCenter: function() { var center = { x : this.width / 2, y : this.height / 2 }; return center; } //later do something like this in your init method: var first = { id : id, name : name, x : this.getCenter().x, y : this.getCenter().y, root : true, //other properties }; //later in your redraw() or other methods you might employ... //try to find the root node later in the code using something like: var rootNode = this.nodes.detect(function(node) { return node.root; }); //do something to the root node after you have detected it... if (rootNode) { rootNode.x = rootNode.px = this.getCenter().x; rootNode.y = rootNode.py = this.getCenter().y; //some other stuff... }
Here's how we did it. However, it is not clear to me which links in your example ... A little puzzled. As you noticed, for forceful directional layouts or more complex animations, you almost always need to use D3 + something else (Prototype, jQuery, underscore) for simple methods such as detection or inclusion or other similar Ruby style methods.
source share