1

Is there any way by which I can specify minimum distance between nodes/edges in force directed graph?

I have some graphs in which one node is connected to hundreds of other nodes directly and in such cases it is really difficult to select a specific edge or node since edges and nodes are so close that onMouseEnter , onClick etc. events are not fired the way user expects it to be.

e.g. If nodeA and nodeB are really close, when I hover the nodeA and expect it to get highlighted , the nodeB is highlighted since event is fired for nodeB. Same is the case for edges when they are too close to each other. Basically it really gets confusing for the user to know which node/edge exactly is being hovered or selected.

I know we can specify the edge length. That can solve this problem to some extent but it does not help when you have hundreds of nodes and edges. And I can not set the edge length more than the height of canvas.

It would be very useful if we can specify some minimum distance between nodes/edges.

Does anyone know how can it be done?

Pratik Patel
  • 1,305
  • 1
  • 17
  • 44

1 Answers1

1

As the InfoVis/TheJit API Documentation, there's the .eachNode() function that allows you to loop through all nodes and retrieve their data.

$jit.Graph.Util.eachNode( graph, function( node ) {  
   console.log( node );
} );  
// or:
graph.eachNode( function( node ) {  
    console.log( node );
} );

As I haven't worked with InfoVis/TheJit for over a year and currently have no project set up, I don't know if you can retrieve the position with Graph.Node.getPos(). Anyway, if you figured this step out, you'd have to write an object/array/matrix that will hold the position. In case some el is to close to another el, you'd use Graph.Node.setPos() to relocate it.

kaiser
  • 21,817
  • 17
  • 90
  • 110
  • That is a good idea. May be I will try it out. But I was looking for something from infovis API that can do this. I would not prefer to enter into setting positions of nodes by myself. – Pratik Patel Apr 11 '13 at 09:23
  • @PratikPatel In fact this **is** what the API provides. And if I remember right, it uses `px` values, so it shouldn't be too hard. The only thing that I imagine to be "not that easy" is all the actual math behind it as every node would have to consider each other nodes x/y vals. At least `Graph.Node.getPos()` provides all the tools needed to build an array where you can do the math. – kaiser Apr 11 '13 at 09:41
  • What you have suggested seems to be the only option. – Pratik Patel May 05 '13 at 05:46