Force directed graph...nodes are going beyond frame

161 views
Skip to first unread message

Zameer

unread,
May 29, 2012, 8:08:09 PM5/29/12
to javascript-information...@googlegroups.com
Hi All,
         I'm using force directed graph into my project, but nodes are going beyond frame border. Is there any way to keep nodes within frame border.

Thanks in advance,
Zameer

Hannie

unread,
May 30, 2012, 5:05:30 PM5/30/12
to javascript-information...@googlegroups.com
You can adjust the layout variable for w2 and h2 in jit.js: e.g.

//arrange positions to fit the canvas
    var t = opt.t, w2 = opt.width / 2 - 100, h2 = opt.height / 2 - 100;     //modified for all nodes visible
    graph.eachNode(function(u) {
      $.each(property, function(p) {
        var disp = u.disp[p];
        var norm = disp.norm() || 1;
        var p = u.getPos(p);
        p.$add($C(disp.x * min(Math.abs(disp.x), t) / norm,
            disp.y * min(Math.abs(disp.y), t) / norm));
        p.x = min(w2, max(-w2, p.x));
        p.y = min(h2, max(-h2, p.y));
      });
    });

It looks very nice in my UI.

Hannie

Zameer Ansari

unread,
Jun 1, 2012, 4:07:13 AM6/1/12
to javascript-information...@googlegroups.com
Wow....this is wonderful.
You made my day.

Thank you so much.
-Zameer

--
You received this message because you are subscribed to the Google Groups "JavaScript InfoVis Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/javascript-information-visualization-toolkit/-/TbfWvn5Ven0J.

To post to this group, send email to javascript-information...@googlegroups.com.
To unsubscribe from this group, send email to javascript-information-visua...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javascript-information-visualization-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages