Link: optimize so that no link {} is used, less than half the ram used

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-30 20:10:46 +00:00
parent 7ca8b2bbc3
commit 409777bc14
2 changed files with 29 additions and 22 deletions

View File

@@ -8,17 +8,28 @@ function startLinkSimulation() {
manualStop = true;
simulation.stop();
p1 = performance.now();
let links = [];
let links = [], force;
// Initialize link array.
nodes = simulation.nodes();
for (i = nodes.length-1; i >= 1; i--) {
for (j = i-1; j >= 0; j--) {
links.push({
source: nodes[i],
target: nodes[j],
});
if (tweakedVerOfLink) {
force = d3.forceLinkTweaked()
.distance(function (n) {
return distanceFunction(n.source, n.target, props, norm);
});
}
else {
for (i = nodes.length-1; i >= 1; i--) {
for (j = i-1; j >= 0; j--) {
links.push({
source: nodes[i],
target: nodes[j],
});
}
}
force = d3.forceLink()
.distance(function (n) {
return distanceFunction(n.source, n.target, props, norm);
})
.links(links);
}
/* Add force
@@ -33,11 +44,6 @@ function startLinkSimulation() {
* The full pre-calculation will then occur once when the force is being
* initialized by the simulation.
*/
let force = tweakedVerOfLink ? d3.forceLinkTweaked() : d3.forceLink();
force.distance(function (n) {
return distanceFunction(n.source, n.target, props, norm);
})
.links(links);
simulation
.alphaDecay(0)