Force directed graph in aligned format.

171 views
Skip to first unread message

abc

unread,
Jan 19, 2011, 1:36:27 AM1/19/11
to JavaScript InfoVis Toolkit
Hi Nicolás,

Could you help me in rendering Force Directed graph in a aligned
manner like a Tree or Inverted Tree.
I have seen the discussion forum

http://groups.google.com/group/javascript-information-visualization-toolkit/browse_thread/thread/68b1d6d674823d1c/b38cbcc4c07ddf06?lnk=gst&q=forced+directed#b38cbcc4c07ddf06

which is locating the similar issue. But no reply so far for this
post.
This is critical for me and seeking for your advice.

Thanks.

Jose Cardozo

unread,
Jan 19, 2011, 6:21:04 AM1/19/11
to JavaScript InfoVis Toolkit
Hi ABC, maybe I can help you. :-)

If you already have the positions of your nodes (like x and y), you
can use the
ForceDirected.Plot.NodeTypes.implement method, and force the final
position of your nodes, like this:

ForceDirected.Plot.NodeTypes.implement({
'your_node_type': {
'render': function(node, canvas) {
//Do the render job of your node, and then set the
final position of your node...
node.endPos.setc(fx, fy);
},
//optional
'contains': function(node, pos) {
var npos = node.pos.getc(true),
dim = node.getData('dim');
return this.nodeHelper.square.contains(npos, pos,
dim);
}
}
}

I do not review the code above, and I don't know for sure if help you,
but I think that gives you an idea.
Hope it helps.

Regards.


On 19 jan, 04:36, abc <sanoop.deva...@gmail.com> wrote:
> Hi Nicolás,
>
>   Could you help me in rendering Force Directed graph in a aligned
> manner like a Tree or Inverted Tree.
>   I have seen the discussion forum
>
> http://groups.google.com/group/javascript-information-visualization-t...

Jose Cardozo

unread,
Jan 19, 2011, 6:28:43 AM1/19/11
to JavaScript InfoVis Toolkit
One more thing... just to be more comprehensive...

the fx and fy variables can be obtained from the json structure, just
like this...

var jsonnode = {
"id": your_id,
"name": "your name",
"data": {
"$dim": 15,
"$type": "your_node_type",
"$width": 31,
"$height": 34,
"$f_x": your_forced_final_x_position,
"$f_y": your_forced_final_y_position,
"adjacencies": {"nodeTo": any_node.id ,
"nodeFrom":your_id, "data":{ "$color":"#557EAA"}}
}
};

In the render method, before the node.endPos.setc(fx, fy), you can
read the info like this:

fx = node.getData('f_x'), fy = node.getData('f_y'),

Regards.

abc

unread,
Jan 20, 2011, 2:56:08 AM1/20/11
to JavaScript InfoVis Toolkit
Hi Jose,

Thank you very much for the reply.
I have tried the solution you have suggested.
My graph is having around 11 nodes, but when i print the count(Global
JS variable i created and incremented) in
ForceDirected.Plot.NodeTypes.implement.render, its entering 1056
times.
Could not find the significance of this 1056 here.It might include the
distance from current node to other nodes as well, not sure though.
I could get proper fx, fy values in render but while plotting my graph
is getting very clumsy in spite of huge gap in fx, fy for different
nodes.

Thanks.

abc

unread,
Jan 20, 2011, 3:24:12 AM1/20/11
to JavaScript InfoVis Toolkit
Sorry Jose,

Its a mistake from side. This logic works well.

Thanks.
Reply all
Reply to author
Forward
0 new messages