Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For force layout, you can set the 'fixed' property of a node to true in order to prevent it from being affected by the simulation. After that, you should be able to set it's position manually. You might choose to do this in a function call:</p> <pre><code>function pinNode(node) { node.fixed = true; } function unpinNode(node) { node.fixed = false; } </code></pre> <p><strike>I believe you could get a node to the upper left corner with a call like this: <code>pinNode(node, 0, 0)</code></strike>. As long as the node has its fixed property set to true, it should remain unaffected by the sim. You might find this snippet from the documentation helpful; it describes how the fixed property is affected by force.drag:</p> <blockquote> <p>Bind a behavior to nodes to allow interactive dragging, either using the mouse or touch. Use this in conjunction with the call operator on the nodes; for example, say node.call(force.drag) on initialization. The drag event sets the fixed attribute of nodes on mouseover, such that as soon as the mouse is over a node, it stops moving. Fixing on mouseover, rather than on mousedown, makes it easier to catch moving nodes. When a mousedown event is received, and on each subsequent mousemove until mouseup, the node center is set to the current mouse position. In addition, each mousemove triggers a resume of the force layout, reheating the simulation. If you want dragged nodes to remain fixed after dragging, set the fixed attribute to true on dragstart, as in the sticky force layout example.</p> </blockquote> <p><a href="https://github.com/mbostock/d3/wiki/Force-Layout#wiki-drag" rel="nofollow">force.drag</a></p> <p>Also see here: <a href="https://github.com/mbostock/d3/wiki/Force-Layout#wiki-nodes" rel="nofollow">force layout nodes</a></p> <p>If you want to use a function for link distance, include it when you create the force layout:</p> <pre><code>var force = d3.layout.force() .size(width, height) .linkStrength(0.5) // how much can link distance be overridedn by the simulation .linkDistance(function() {return /* some evaluation */;}); // ... // You might need to defer the calculation of linkDistance until later, // such as in update(), since nodes might not have the properties // that you need to check until that point: function update() { force .nodes(nodes) .links(links) .linkDistance(function(link) { // The function gets called for each link in the simulation. // Each link will be connected to two nodes, source and target, // which may be useful in determining link distance. if (link.source.someProperty || link.target.somePropery) { return /* something */; } else { return /* something else */; } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload