Move example JS files
This commit is contained in:
48
examples/js/algos/hybrid.js
Normal file
48
examples/js/algos/hybrid.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Initialize the hybrid layout algorithm and start simulation.
|
||||
*/
|
||||
function startHybridSimulation() {
|
||||
console.log("startHybridSimulation");
|
||||
springForce = false;
|
||||
d3.selectAll(".nodes").remove();
|
||||
manualStop = false;
|
||||
simulation.stop();
|
||||
p1 = performance.now();
|
||||
|
||||
function distance (s, t) {
|
||||
return distanceFunction(s, t, props, norm);
|
||||
}
|
||||
|
||||
let forceSample = d3.forceNeighbourSampling()
|
||||
.neighbourSize(NEIGHBOUR_SIZE)
|
||||
.sampleSize(SAMPLE_SIZE)
|
||||
.stableVelocity(0)
|
||||
.distance(distance)
|
||||
|
||||
let forceFull = d3.forceNeighbourSampling()
|
||||
.neighbourSize(FULL_NEIGHBOUR_SIZE)
|
||||
.sampleSize(FULL_SAMPLE_SIZE)
|
||||
.distance(distance)
|
||||
|
||||
let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull)
|
||||
.sampleIterations(ITERATIONS)
|
||||
.fullIterations(FULL_ITERATIONS)
|
||||
.numPivots(PIVOTS ? NUM_PIVOTS:-1)
|
||||
.interpFindTuneIts(INTERP_ENDING_ITS)
|
||||
.interpDistanceFn(distance)
|
||||
.on("sampleTick", ticked)
|
||||
.on("fullTick", ticked)
|
||||
.on("startInterp", startedFull)
|
||||
.on("end", ended);
|
||||
|
||||
let sample = hybridSimulation.subSet();
|
||||
addNodesToDOM(sample);
|
||||
|
||||
hybridSimulation.restart();
|
||||
|
||||
function startedFull() {
|
||||
console.log("startedFull");
|
||||
d3.selectAll(".nodes").remove();
|
||||
addNodesToDOM(nodes);
|
||||
}
|
||||
}
|
||||
59
examples/js/algos/linkForce.js
Normal file
59
examples/js/algos/linkForce.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Initialize the link force algorithm and start simulation.
|
||||
*/
|
||||
function startLinkSimulation() {
|
||||
console.log("startLinkSimulation")
|
||||
springForce = false;
|
||||
alreadyRanIterations = 0;
|
||||
manualStop = true;
|
||||
simulation.stop();
|
||||
p1 = performance.now();
|
||||
let links = [], force;
|
||||
|
||||
if (tweakedVerOfLink) {
|
||||
force = d3.forceLinkFullyConnected()
|
||||
.distance(function (n, m) {
|
||||
return distanceFunction(n, m, props, norm);
|
||||
})
|
||||
.stableVelocity(0) //TODO
|
||||
.onStableVelo(ended);
|
||||
}
|
||||
else {
|
||||
for (i = nodes.length-1; i >= 1; i--) {
|
||||
for (j = i-1; j >= 0; j--) {
|
||||
links.push({
|
||||
source: nodes[i],
|
||||
target: nodes[j],
|
||||
});
|
||||
}
|
||||
}
|
||||
force = d3.forceLink()
|
||||
.distance(function (n) {
|
||||
return distanceFunction(n.source, n.target, props, norm);
|
||||
})
|
||||
.links(links);
|
||||
}
|
||||
|
||||
/* Add force
|
||||
* Please add the distance function, links, and set simulation nodes
|
||||
* before feeding the force to the simulation.
|
||||
*
|
||||
* On setting the distance fn or being initialized by the simulation, the
|
||||
* force will pre-calculate high-dimensional distances of every link and
|
||||
* store that as cache.
|
||||
* Adding distance fn and links before being initialize by the simulation
|
||||
* means that the first pre-calculation will calculate noting as there was
|
||||
* no nodes list.
|
||||
* The full pre-calculation will then occur once when the force is being
|
||||
* initialized by the simulation where nodes list is given.
|
||||
*/
|
||||
|
||||
simulation
|
||||
.alphaDecay(0)
|
||||
.alpha(1)
|
||||
.on("tick", ticked)
|
||||
.on("end", ended)
|
||||
//.velocityDecay(0.8)
|
||||
.force(forceName,force)
|
||||
.restart();
|
||||
}
|
||||
29
examples/js/algos/neighbourSampling.js
Normal file
29
examples/js/algos/neighbourSampling.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Initialize the Chalmers' 1996 algorithm and start simulation.
|
||||
*/
|
||||
function startNeighbourSamplingSimulation() {
|
||||
console.log("startNeighbourSamplingSimulation");
|
||||
//springForce = true;
|
||||
alreadyRanIterations = 0;
|
||||
manualStop = true;
|
||||
simulation.stop();
|
||||
p1 = performance.now();
|
||||
|
||||
let force = d3.forceNeighbourSampling()
|
||||
.neighbourSize(NEIGHBOUR_SIZE)
|
||||
.sampleSize(SAMPLE_SIZE)
|
||||
.distance(function (s, t) {
|
||||
return distanceFunction(s, t, props, norm);
|
||||
})
|
||||
.stableVelocity(0.000001) //TODO
|
||||
.onStableVelo(ended);
|
||||
|
||||
simulation
|
||||
.alphaDecay(0)
|
||||
.alpha(1)
|
||||
.on("tick", ticked)
|
||||
.on("end", ended)
|
||||
.force(forceName, force);
|
||||
// Restart the simulation.
|
||||
simulation.restart();
|
||||
}
|
||||
44
examples/js/algos/otherAlgo.js
Normal file
44
examples/js/algos/otherAlgo.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Initialize the t-SNE algorithm and start simulation.
|
||||
*/
|
||||
function starttSNE() {
|
||||
springForce = false;
|
||||
simulation.stop();
|
||||
p1 = performance.now();
|
||||
|
||||
simulation
|
||||
.alphaDecay(1 - Math.pow(0.001, 1 / ITERATIONS))
|
||||
.force(forceName, d3.tSNE()
|
||||
// Set the parameter for the algorithm (optional).
|
||||
.perplexity(PERPLEXITY)
|
||||
.learningRate(LEARNING_RATE)
|
||||
// The distance function that will be used to calculate distances
|
||||
// between nodes.
|
||||
.distance(function (s, t) {
|
||||
return distanceFunction(s, t, props, norm);
|
||||
}));
|
||||
// Restart the simulation.
|
||||
console.log(simulation.force(forceName).perplexity(), simulation.force(forceName).learningRate());
|
||||
simulation.alpha(1).restart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Barnes-Hut algorithm and start simulation.
|
||||
*/
|
||||
function startBarnesHutSimulation() {
|
||||
console.log("startBarnesHutSimulation")
|
||||
alreadyRanIterations = 0;
|
||||
manualStop = false;
|
||||
springForce = false;
|
||||
p1 = performance.now();
|
||||
|
||||
simulation.alphaDecay(1 - Math.pow(0.001, 1 / ITERATIONS))
|
||||
.on("tick", ticked)
|
||||
.on("end", ended)
|
||||
.force(forceName, d3.forceBarnesHut()
|
||||
// The distance function that will be used to calculate distances
|
||||
// between nodes.
|
||||
.distance(function(s, t) { return distanceFunction(s, t, props, norm); }));
|
||||
// Restart the simulation.
|
||||
simulation.alpha(1).restart();
|
||||
}
|
||||
Reference in New Issue
Block a user