Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the position of some nodes, not all. #14

Closed
bloodwall opened this issue Oct 10, 2012 · 4 comments
Closed

Fixing the position of some nodes, not all. #14

bloodwall opened this issue Oct 10, 2012 · 4 comments

Comments

@bloodwall
Copy link

Hello, Great job for VivaGraphJS.

I know that can be fixed the position of all nodes but can be fixed only two and leave others free?

Best regards.

@arikan
Copy link

arikan commented Dec 28, 2012

First, you can declare which nodes to fix in your node data.

var graph = Viva.Graph.graph();

graph.addNode('anvaka', ['anvaka', '91bad8ceeec43ae303790f8fe238164b', false]);
graph.addNode('indexzero', ['indexzero', 'd43e8ea63b61e7669ded5b9d3c2e980f', false]);
graph.addNode('arikan', ['arikan','099ea30c960be231cb236eaad86d6428', true]);

// make sure you have the layout object.
var layout = Viva.Graph.Layout.forceDirected(graph);

We want to set custom node placement callback for layout, but this part does not seem to work with forceDirected layout object?

layout.placeNode(function(node) {
   if (node.data[2] == true){  
        return {x : 0, y: 0}; // fix in the center
   }
});
var renderer = Viva.Graph.View.renderer(graph, {
         layout : layout  // use the custom layout
});
renderer.run();

Maybe the VivaGraphJS API has something on setting a certain node's x y position while using forceDirected layout, couldn't find yet?

@arikan
Copy link

arikan commented Jan 4, 2013

Any idea how to fix a certain node's x y position while using forceDirected layout?

@anvaka
Copy link
Owner

anvaka commented Jan 5, 2013

Sure! Just use isPinned property of node object:

E.g.

var arikan = graph.addNode('arikan', ['arikan','099ea30c960be231cb236eaad86d6428', true]);
arikan.isPinned = true; // Now this node will not be moved by the layout algorithm.

Alternatively, when your node data is an object (not an array) you can also declare isPinned property there. E.g.

var user = {
  id: 'arikan',
  hash: '099ea30c960be231cb236eaad86d6428',
  isPinned: true // the node is now pinned and will not be moved
}
graph.addNode(user.id, user);

@arikan
Copy link

arikan commented Jan 6, 2013

Oh didn't see that method, thanks a lot! Also node data hash version is a great default. Thanks!

@anvaka anvaka closed this as completed Feb 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants