From 57ee21f8ec91106288c98f16885ae97b2228bffc Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Mon, 30 Oct 2017 03:14:08 +0100 Subject: [PATCH] [BUGFIX] Use less force after init --- lib/forcegraph.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index beda51c..1d4cf67 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -15,6 +15,7 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', var dictNodes = {}; var intLinks = []; var movetoTimer; + var initial = 1.8; var NODE_RADIUS_DRAG = 10; var NODE_RADIUS_SELECT = 15; @@ -24,7 +25,7 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', var ZOOM_MIN = 1 / 8; var ZOOM_MAX = 3; - var FORCE_ALPHA = 0.3; + var FORCE_ALPHA = 0.01; draw.setTransform(transform); @@ -148,7 +149,7 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', .force('y', d3Force.forceY().strength(0.02)) .force('collide', d3Force.forceCollide()) .on('tick', redraw) - .alphaDecay(0.015); + .alphaDecay(0.025); var drag = d3Drag.drag() .subject(function () { @@ -207,7 +208,9 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', e.o = d; return e; - }).filter(function (e) { return e.o.is_online;}); + }).filter(function (e) { + return e.o.is_online; + }); intLinks = data.links.filter(function (d) { return dictNodes[d.source.node_id].o.is_online && dictNodes[d.target.node_id].o.is_online; @@ -224,7 +227,11 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', force.nodes(intNodes); forceLink.links(intLinks); - force.alpha(1).restart(); + force.alpha(initial).velocityDecay(0.15).restart(); + if (initial === 1.8) { + initial = 0.5; + } + resizeCanvas(); };