How to set focal node in D3.js radiation pattern?

I have a data set that determines the number of nodes that will be used in graphics with power mode. Seem to be...

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 can I tell force.layout in the d3.js library to use "Node 1" id = "N1" as the main root or focal node?

+4
source share
2 answers

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.

+3
source

I'm not sure what you mean by focal or root node. If you want to fix a specific node in a specific place (for example, in the center), you can set its fixed attribute to true. For more information, see Fix a Node Position in a D3 Force-Directed Layout , as well as Moving Fixed Nodes in D3 .

I don’t think your force directed radial graph shows that d3 implicitly uses the first node in the node list as the β€œroot” node. node 1 in your example always gravitates toward the center as a consequence of the network structure. If you put node 1 later in an array of nodes, then its behavior will be the same.

+3
source

Source: https://habr.com/ru/post/1416032/


All Articles