javascript - How do I set the focal node in a D3.js Force Directed Graph? -
i have data set defines number of nodes use in force directed graph. looks like...
var nodeset = [ {id: "n1", name: "node 1", type: "type 1", hlink: "http://www.if4it.com"}, {id: "n2", name: "node 2", type: "type 3", hlink: "http://www.if4it.com/glossary.html"}, {id: "n3", name: "node 3", type: "type 4", hlink: "http://www.if4it.com/resources.html"}, {id: "n4", name: "node 4", type: "type 5", hlink: "http://www.if4it.com/taxonomy.html"}, {id: "n5", name: "node 5", type: "type 1", hlink: "http://www.if4it.com/disciplines.html"} ]; how tell force.layout in d3.js library use "node 1" of id = "n1" primary root or focal node?
if want root node can have root property in object , set true, treat node separately. can set root center. here how did (d3 + prototype - @ time - switching d3+jquery+underscore):
getcenter: function() { var center = { x : this.width / 2, y : this.height / 2 }; return center; } //later in init method: var first = { id : id, name : name, x : this.getcenter().x, y : this.getcenter().y, root : true, //other properties }; //later in redraw() or other methods might employ... //try find root node later in code using like: var rootnode = this.nodes.detect(function(node) { return node.root; }); //do root node after have detected it... if (rootnode) { rootnode.x = rootnode.px = this.getcenter().x; rootnode.y = rootnode.py = this.getcenter().y; //some other stuff... } this how have done it. it's not clear me links in example... little bit puzzled. notice, force directed layout or more complicated animations need use d3+something else (prototype, jquery, underscore) simple methods detect or include or other similar ruby style methods.
Comments
Post a Comment