Merge branch 'master' into withConsoleLog
This commit is contained in:
@@ -15,6 +15,7 @@ export default function() {
|
|||||||
nodes,
|
nodes,
|
||||||
stableVelocity = 0,
|
stableVelocity = 0,
|
||||||
stableVeloHandler = null,
|
stableVeloHandler = null,
|
||||||
|
latestVelocityDiff = 0,
|
||||||
iterations = 1;
|
iterations = 1;
|
||||||
|
|
||||||
function force(alpha) {
|
function force(alpha) {
|
||||||
@@ -54,6 +55,7 @@ export default function() {
|
|||||||
velocityDiff += Math.abs(Math.hypot(node.vx-node.oldvx, node.vy-node.oldvy));
|
velocityDiff += Math.abs(Math.hypot(node.vx-node.oldvx, node.vy-node.oldvy));
|
||||||
}
|
}
|
||||||
velocityDiff /= n*(n-1);
|
velocityDiff /= n*(n-1);
|
||||||
|
latestVelocityDiff = velocityDiff;
|
||||||
|
|
||||||
if(velocityDiff<stableVelocity){
|
if(velocityDiff<stableVelocity){
|
||||||
stableVeloHandler();
|
stableVeloHandler();
|
||||||
@@ -91,6 +93,10 @@ export default function() {
|
|||||||
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
|
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
force.latestAccel = function () {
|
||||||
|
return latestVelocityDiff;
|
||||||
|
};
|
||||||
|
|
||||||
force.onStableVelo = function (_) {
|
force.onStableVelo = function (_) {
|
||||||
return arguments.length ? (stableVeloHandler = _, force) : stableVeloHandler;
|
return arguments.length ? (stableVeloHandler = _, force) : stableVeloHandler;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
export function getStress(nodes, distance) {
|
export function getStress(nodes, distance) {
|
||||||
let sumDiffSq = 0
|
let sumDiffSq = 0
|
||||||
let sumHighDistSq = 0;
|
let sumLowDDistSq = 0;
|
||||||
for (let j = nodes.length-1; j >= 1; j++) {
|
for (let j = nodes.length-1; j >= 1; j--) {
|
||||||
for (let i = 0; i < j; i++) {
|
for (let i = 0; i < j; i++) {
|
||||||
let source = nodes[i], target = nodes[j];
|
let source = nodes[i], target = nodes[j];
|
||||||
let lowDDist = Math.hypot(target.x - source.x, target.y - source.y);
|
let lowDDist = Math.hypot(target.x - source.x, target.y - source.y);
|
||||||
|
|||||||
Reference in New Issue
Block a user