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:
@@ -209,8 +209,8 @@
|
|||||||
<input type="range" min="1" max="100" value="10" step="1" oninput="d3.select('#distanceRangeSliderOutput').text(value); SELECTED_DISTANCE=value;">
|
<input type="range" min="1" max="100" value="10" step="1" oninput="d3.select('#distanceRangeSliderOutput').text(value); SELECTED_DISTANCE=value;">
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<input class="noParameters" type="radio" name="algorithm" onclick="d3.select('#startSimulation').on('click', startLinkSimulation)">Link
|
<input class="noParameters" type="radio" name="algorithm" onclick="d3.select('#startSimulation').on('click', startLinkSimulation); tweakedVerOfLink=false;">Link force in D3<br>
|
||||||
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 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>
|
<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">
|
<div id="tSNEParameters" class="parameters" style="display:none">
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ var nodes, // as in Data points
|
|||||||
selectedData,
|
selectedData,
|
||||||
clickedIndex = -1,
|
clickedIndex = -1,
|
||||||
paused = false,
|
paused = false,
|
||||||
alreadyRanIterations;
|
alreadyRanIterations,
|
||||||
|
tweakedVerOfLink;
|
||||||
|
|
||||||
// Default parameters
|
// Default parameters
|
||||||
var MULTIPLIER = 50,
|
var MULTIPLIER = 50,
|
||||||
|
|||||||
@@ -32,14 +32,15 @@ function startLinkSimulation() {
|
|||||||
* The full pre-calculation will then occur once when the force is being
|
* The full pre-calculation will then occur once when the force is being
|
||||||
* initialized by the simulation.
|
* initialized by the simulation.
|
||||||
*/
|
*/
|
||||||
simulation.force(forceName,
|
let force = tweakedVerOfLink ? d3.forceLinkTweaked() : d3.forceLink();
|
||||||
d3.forceLinkOptimized()
|
force.distance(function (n) {
|
||||||
.distance(function (n) {
|
|
||||||
return distanceFunction(n.source, n.target, props, norm);
|
return distanceFunction(n.source, n.target, props, norm);
|
||||||
})
|
})
|
||||||
.links(links)
|
.links(links);
|
||||||
).alphaDecay(0)
|
|
||||||
//.velocityDecay(0.8)
|
simulation.force(forceName,force)
|
||||||
.alpha(1)
|
.alphaDecay(0)
|
||||||
.restart();
|
//.velocityDecay(0.8)
|
||||||
|
.alpha(1)
|
||||||
|
.restart();
|
||||||
}
|
}
|
||||||
|
|||||||
2
index.js
2
index.js
@@ -13,7 +13,7 @@ export { default as forceBarnesHut}
|
|||||||
export { default as tSNE}
|
export { default as tSNE}
|
||||||
from "./src/t-sne";
|
from "./src/t-sne";
|
||||||
|
|
||||||
export { default as forceLinkOptimized}
|
export { default as forceLinkTweaked}
|
||||||
from "./src/link";
|
from "./src/link";
|
||||||
|
|
||||||
export { default as hybridSimulation}
|
export { default as hybridSimulation}
|
||||||
|
|||||||
10
src/link.js
10
src/link.js
@@ -4,10 +4,12 @@ import jiggle from "./jiggle";
|
|||||||
/**
|
/**
|
||||||
* Modified link force algorithm
|
* Modified link force algorithm
|
||||||
* - ignore alpha
|
* - ignore alpha
|
||||||
* - removed location prediction, and bias
|
* - removed bias
|
||||||
* - modified strength calculation
|
* - modified strength calculation
|
||||||
* - removed other unused functions
|
* - removed other unused functions
|
||||||
* Making it more suitable for the spring model.
|
* 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) {
|
export default function(links) {
|
||||||
@@ -26,8 +28,8 @@ export default function(links) {
|
|||||||
// 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;
|
||||||
target = link.target;
|
target = link.target;
|
||||||
x = target.x - source.x || jiggle();
|
x = target.x + target.vx - source.x - source.vx || jiggle();
|
||||||
y = target.y - source.y || 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;
|
||||||
x *= l, y *= l;
|
x *= l, y *= l;
|
||||||
@@ -41,13 +43,11 @@ export default function(links) {
|
|||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
if (!nodes) return;
|
if (!nodes) return;
|
||||||
console.log("CUSTOM LINK FORCE");
|
|
||||||
dataSizeFactor = 0.5/(nodes.length-1);
|
dataSizeFactor = 0.5/(nodes.length-1);
|
||||||
initializeDistance();
|
initializeDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeDistance() {
|
function initializeDistance() {
|
||||||
console.log("INIT DISTANCE", links.length);
|
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user