Add entry to select between normal and tweaked Link Force
- Tweaked link force should initialize and perform the calculation a tiny bit faster (maybe insignificant)
This commit is contained in:
10
src/link.js
10
src/link.js
@@ -4,10 +4,12 @@ import jiggle from "./jiggle";
|
||||
/**
|
||||
* Modified link force algorithm
|
||||
* - ignore alpha
|
||||
* - removed location prediction, and bias
|
||||
* - removed bias
|
||||
* - modified strength calculation
|
||||
* - 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
|
||||
*/
|
||||
|
||||
export default function(links) {
|
||||
@@ -26,8 +28,8 @@ export default function(links) {
|
||||
// jiggle so it wont divide / multiply by zero after this
|
||||
source = link.source;
|
||||
target = link.target;
|
||||
x = target.x - source.x || jiggle();
|
||||
y = target.y - source.y || jiggle();
|
||||
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;
|
||||
x *= l, y *= l;
|
||||
@@ -41,13 +43,11 @@ export default function(links) {
|
||||
|
||||
function initialize() {
|
||||
if (!nodes) return;
|
||||
console.log("CUSTOM LINK FORCE");
|
||||
dataSizeFactor = 0.5/(nodes.length-1);
|
||||
initializeDistance();
|
||||
}
|
||||
|
||||
function initializeDistance() {
|
||||
console.log("INIT DISTANCE", links.length);
|
||||
if (!nodes) return;
|
||||
|
||||
for (var i = 0, n = links.length; i < n; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user