-
Notifications
You must be signed in to change notification settings - Fork 423
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
Comments
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? |
Any idea how to fix a certain node's x y position while using forceDirected layout? |
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 var user = {
id: 'arikan',
hash: '099ea30c960be231cb236eaad86d6428',
isPinned: true // the node is now pinned and will not be moved
}
graph.addNode(user.id, user); |
Oh didn't see that method, thanks a lot! Also node data hash version is a great default. Thanks! |
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.
The text was updated successfully, but these errors were encountered: