Merge branch 'less-confusing-force-start' into 3.3.7

This commit is contained in:
Mike Bostock 2013-10-09 08:08:27 -07:00
Родитель 261940aa54 c9e0b67948
Коммит ddff8719dd
3 изменённых файлов: 17 добавлений и 24 удалений

13
d3.js поставляемый
Просмотреть файл

@ -6000,7 +6000,7 @@ d3 = function() {
return force;
};
force.start = function() {
var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
for (i = 0; i < n; ++i) {
(o = nodes[i]).index = i;
o.weight = 0;
@ -6026,13 +6026,8 @@ d3 = function() {
charges = [];
if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
function position(dimension, size) {
var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
return Math.random() * size;
}
function neighbor() {
if (!neighbors) {
neighbors = [];
neighbors = new Array(n);
for (j = 0; j < n; ++j) {
neighbors[j] = [];
}
@ -6042,7 +6037,9 @@ d3 = function() {
neighbors[o.target.index].push(o.source);
}
}
return neighbors[i];
var candidates = neighbors[i], j = -1, m = candidates.length, x;
while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
return Math.random() * size;
}
return force.resume();
};

4
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -198,7 +198,6 @@ d3.layout.force = function() {
force.start = function() {
var i,
j,
n = nodes.length,
m = links.length,
w = size[0],
@ -239,20 +238,12 @@ d3.layout.force = function() {
if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i);
else for (i = 0; i < n; ++i) charges[i] = charge;
// initialize node position based on first neighbor
// inherit node position from first neighbor with defined position
// or if no such neighbors, initialize node position randomly
// initialize neighbors lazily to avoid overhead when not needed
function position(dimension, size) {
var neighbors = neighbor(i),
j = -1,
m = neighbors.length,
x;
while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
return Math.random() * size;
}
// initialize neighbors lazily
function neighbor() {
if (!neighbors) {
neighbors = [];
neighbors = new Array(n);
for (j = 0; j < n; ++j) {
neighbors[j] = [];
}
@ -262,7 +253,12 @@ d3.layout.force = function() {
neighbors[o.target.index].push(o.source);
}
}
return neighbors[i];
var candidates = neighbors[i],
j = -1,
m = candidates.length,
x;
while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
return Math.random() * size;
}
return force.resume();