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:
Pitchaya Boonsarngsuk
2018-01-24 21:42:48 +00:00
parent 89bc947409
commit c96dd51d24
5 changed files with 20 additions and 18 deletions

View File

@@ -209,8 +209,8 @@
<input type="range" min="1" max="100" value="10" step="1" oninput="d3.select('#distanceRangeSliderOutput').text(value); SELECTED_DISTANCE=value;">
</label>
</div>
<input class="noParameters" type="radio" name="algorithm" onclick="d3.select('#startSimulation').on('click', startLinkSimulation)">Link
force in D3<br>
<input class="noParameters" type="radio" name="algorithm" onclick="d3.select('#startSimulation').on('click', startLinkSimulation); tweakedVerOfLink=false;">Link force in D3<br>
<input class="noParameters" type="radio" name="algorithm" onclick="d3.select('#startSimulation').on('click', startLinkSimulation); tweakedVerOfLink=true; ">Link force (tweaked)<br>
<input class="noParameters" type="radio" name="algorithm" onclick="d3.select('#startSimulation').on('click', startBarnesHutSimulation)">Barnes-Hut<br>
<input id="tSNEButton" type="radio" name="algorithm" onclick="d3.select('#startSimulation').on('click', starttSNE)">t-SNE<br>
<div id="tSNEParameters" class="parameters" style="display:none">

View File

@@ -42,7 +42,8 @@ var nodes, // as in Data points
selectedData,
clickedIndex = -1,
paused = false,
alreadyRanIterations;
alreadyRanIterations,
tweakedVerOfLink;
// Default parameters
var MULTIPLIER = 50,

View File

@@ -32,14 +32,15 @@ function startLinkSimulation() {
* The full pre-calculation will then occur once when the force is being
* initialized by the simulation.
*/
simulation.force(forceName,
d3.forceLinkOptimized()
.distance(function (n) {
let force = tweakedVerOfLink ? d3.forceLinkTweaked() : d3.forceLink();
force.distance(function (n) {
return distanceFunction(n.source, n.target, props, norm);
})
.links(links)
).alphaDecay(0)
//.velocityDecay(0.8)
.alpha(1)
.restart();
})
.links(links);
simulation.force(forceName,force)
.alphaDecay(0)
//.velocityDecay(0.8)
.alpha(1)
.restart();
}