Code Monkey home page Code Monkey logo

Comments (4)

arikan avatar arikan commented on July 28, 2024

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?

from vivagraphjs.

arikan avatar arikan commented on July 28, 2024

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

from vivagraphjs.

anvaka avatar anvaka commented on July 28, 2024

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);

from vivagraphjs.

arikan avatar arikan commented on July 28, 2024

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

from vivagraphjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.