Add alpha back to link, just in case

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-26 13:09:14 +00:00
parent c96dd51d24
commit 665b5a89a6

View File

@@ -3,15 +3,10 @@ import jiggle from "./jiggle";
/**
* Modified link force algorithm
* - ignore alpha
* - removed bias
* - modified strength calculation
* - simplify calculations for parameters locked for spring model
* - removed other unused functions
* Making it more suitable for the spring model.
* This should initialize and perform calculation a bit faster, and also
* use a bit less memory
* Alpha should be constant 1 for accurate simulation
*/
export default function(links) {
var dataSizeFactor,
distance = constant(30),
@@ -21,9 +16,11 @@ export default function(links) {
if (links == null) links = [];
function force() {
for (var k = 0, n = links.length; k < iterations; ++k) { // Each iteration in a tick
for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) { // For each link
function force(alpha) {
// Each iteration in a tick
for (var k = 0, n = links.length; k < iterations; ++k) {
// For each link
for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
link = links[i];
// jiggle so it wont divide / multiply by zero after this
source = link.source;
@@ -31,7 +28,7 @@ export default function(links) {
x = target.x + target.vx - source.x - source.vx || jiggle();
y = target.y + target.vy - source.y - source.vy || jiggle();
l = Math.sqrt(x * x + y * y);
l = (l - distances[i]) / l * dataSizeFactor;
l = (l - distances[i]) / l * dataSizeFactor * alpha;
x *= l, y *= l;
target.vx -= x;
target.vy -= y;
@@ -49,7 +46,6 @@ export default function(links) {
function initializeDistance() {
if (!nodes) return;
for (var i = 0, n = links.length; i < n; ++i) {
distances[i] = +distance(links[i], i, links);
}