You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
654 B
36 lines
654 B
export default function(x, y) { |
|
var nodes; |
|
|
|
if (x == null) x = 0; |
|
if (y == null) y = 0; |
|
|
|
function force() { |
|
var i, |
|
n = nodes.length, |
|
node, |
|
sx = 0, |
|
sy = 0; |
|
|
|
for (i = 0; i < n; ++i) { |
|
node = nodes[i], sx += node.x, sy += node.y; |
|
} |
|
|
|
for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) { |
|
node = nodes[i], node.x -= sx, node.y -= sy; |
|
} |
|
} |
|
|
|
force.initialize = function(_) { |
|
nodes = _; |
|
}; |
|
|
|
force.x = function(_) { |
|
return arguments.length ? (x = +_, force) : x; |
|
}; |
|
|
|
force.y = function(_) { |
|
return arguments.length ? (y = +_, force) : y; |
|
}; |
|
|
|
return force; |
|
}
|
|
|