Files
d3-spring-model/examples/js/algos/hybrid.js
Pitchaya Boonsarngsuk 6df7e225ba Move example JS files
2018-03-13 01:07:40 +00:00

49 lines
1.2 KiB
JavaScript

/**
* 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);
}
}