From 36ccf5c8472e561ab60e6031ecfe8d069cc66b5e Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 6 Jun 2012 01:58:39 +0200 Subject: [PATCH] move restriction to viewport to force.js --- html/d3.layout.js | 5 ----- html/force.js | 13 +++++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/html/d3.layout.js b/html/d3.layout.js index b7e83ee..9bacdcb 100644 --- a/html/d3.layout.js +++ b/html/d3.layout.js @@ -315,11 +315,6 @@ 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; - } } diff --git a/html/force.js b/html/force.js index f8d3ba1..4db4f02 100644 --- a/html/force.js +++ b/html/force.js @@ -131,6 +131,19 @@ var force = d3.layout.force() .size([w, h]) force.on("tick", function() { + var size = force.size() + var nodes = force.nodes() + var n = nodes.length + for (i = 0; i < n; i++) { + var o = nodes[i] + if (!o.fixed) { + 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 + } + } + var link = vis.selectAll(".link") link.selectAll("line")