From 88e7de05520f523e46f1963bad3cfbf07c615ecc Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 3 Jun 2012 14:53:12 +0200 Subject: [PATCH] restrict nodes to viewable area --- html/d3.layout.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/html/d3.layout.js b/html/d3.layout.js index 9bacdcb..b7e83ee 100644 --- a/html/d3.layout.js +++ b/html/d3.layout.js @@ -315,6 +315,11 @@ d3.layout.force = function() { } else { o.x -= (o.px - (o.px = o.x)) * friction; o.y -= (o.py - (o.py = o.y)) * friction; + if (o.x < 0) o.x = 10; + if (o.x > size[0]) o.x = size[0] - 10; + if (o.y < 0) o.y = 10; + if (o.y > size[1]) o.y = size[1] - 10; + } }