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