move restriction to viewport to force.js
This commit is contained in:
parent
865d2f9124
commit
36ccf5c847
|
@ -315,11 +315,6 @@ d3.layout.force = function() {
|
||||||
} else {
|
} else {
|
||||||
o.x -= (o.px - (o.px = o.x)) * friction;
|
o.x -= (o.px - (o.px = o.x)) * friction;
|
||||||
o.y -= (o.py - (o.py = o.y)) * 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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,19 @@ var force = d3.layout.force()
|
||||||
.size([w, h])
|
.size([w, h])
|
||||||
|
|
||||||
force.on("tick", function() {
|
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")
|
var link = vis.selectAll(".link")
|
||||||
|
|
||||||
link.selectAll("line")
|
link.selectAll("line")
|
||||||
|
|
Loading…
Reference in a new issue