Modify stop condition in the example

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-26 17:29:33 +00:00
parent 97d8b71963
commit 9d6b3e066b
5 changed files with 27 additions and 12 deletions

View File

@@ -157,6 +157,12 @@
<input type="range" min="1" max="100" value="3" step="1" oninput="d3.select('#hlsampleSizeSliderOutput').text(value); SAMPLE_SIZE=value;"> <input type="range" min="1" max="100" value="3" step="1" oninput="d3.select('#hlsampleSizeSliderOutput').text(value); SAMPLE_SIZE=value;">
</label> </label>
<br/> <br/>
<label title="InterpEndingIts">
Interpolation: Micro-adjustment Its
<output id="hlInterpEdningSliderOutput">20</output><br/>
<input type="range" min="1" max="50" value="20" step="1" oninput="d3.select('#hlInterpEdningSliderOutput').text(value); INTERP_ENDING_ITS=value;">
</label>
<br/>
<label title="Number of iterations done at the end"> <label title="Number of iterations done at the end">
Full: Iterations Full: Iterations
<output id="fullIterationsSliderOutput">20</output><br/> <output id="fullIterationsSliderOutput">20</output><br/>

View File

@@ -43,7 +43,8 @@ var nodes, // as in Data points
clickedIndex = -1, clickedIndex = -1,
paused = false, paused = false,
alreadyRanIterations, alreadyRanIterations,
tweakedVerOfLink; tweakedVerOfLink,
manualStop = false;
// Default parameters // Default parameters
var MULTIPLIER = 50, var MULTIPLIER = 50,
@@ -58,7 +59,8 @@ var MULTIPLIER = 50,
NODE_SIZE = 10, NODE_SIZE = 10,
COLOR_ATTRIBUTE = "", COLOR_ATTRIBUTE = "",
FULL_NEIGHBOUR_SIZE = 6, FULL_NEIGHBOUR_SIZE = 6,
FULL_SAMPLE_SIZE = 3; FULL_SAMPLE_SIZE = 3,
INTERP_ENDING_ITS = 20;
// Create a color scheme for a range of numbers. // Create a color scheme for a range of numbers.
var color = d3.scaleOrdinal(d3.schemeCategory10); var color = d3.scaleOrdinal(d3.schemeCategory10);
@@ -135,8 +137,6 @@ function processData(data, error) {
// Pass the nodes to the D3 force simulation. // Pass the nodes to the D3 force simulation.
simulation simulation
.nodes(nodes) .nodes(nodes)
.on("tick", ticked)
.on("end", ended)
.stop(); .stop();
}; };
@@ -202,13 +202,14 @@ function ticked() {
if (springForce) { if (springForce) {
intercom.emit("passedData", simulation.force(forceName).distributionData()); intercom.emit("passedData", simulation.force(forceName).distributionData());
} }
if(alreadyRanIterations == ITERATIONS) { if(manualStop && alreadyRanIterations == ITERATIONS) {
ended(); ended();
} }
} }
function ended() { function ended() {
simulation.stop(); simulation.stop();
simulation.force(forceName, null);
console.log("ended"); console.log("ended");
if (rendering !== true) { // Never drawn anything before? Now it's time. if (rendering !== true) { // Never drawn anything before? Now it's time.
node node
@@ -382,7 +383,7 @@ function updateDistanceRange() {
function pauseUnPause() { function pauseUnPause() {
if (simulation) { if (simulation) {
if (paused) { if (paused) {
simulation.force(forceName).distanceRange(SELECTED_DISTANCE); simulation.force(forceName);
simulation.restart(); simulation.restart();
d3.select("#pauseButton").text("Pause"); d3.select("#pauseButton").text("Pause");
paused = false; paused = false;

View File

@@ -5,6 +5,7 @@ function startHybridSimulation() {
console.log("startHybridSimulation"); console.log("startHybridSimulation");
springForce = false; springForce = false;
d3.selectAll(".nodes").remove(); d3.selectAll(".nodes").remove();
manualStop = false;
simulation.stop(); simulation.stop();
p1 = performance.now(); p1 = performance.now();

View File

@@ -5,6 +5,7 @@ function startLinkSimulation() {
console.log("startLinkSimulation") console.log("startLinkSimulation")
springForce = false; springForce = false;
alreadyRanIterations = 0; alreadyRanIterations = 0;
manualStop = true;
simulation.stop(); simulation.stop();
p1 = performance.now(); p1 = performance.now();
let links = []; let links = [];
@@ -37,10 +38,13 @@ function startLinkSimulation() {
return distanceFunction(n.source, n.target, props, norm); return distanceFunction(n.source, n.target, props, norm);
}) })
.links(links); .links(links);
simulation.force(forceName,force) simulation
.alphaDecay(0) .alphaDecay(0)
//.velocityDecay(0.8) .alpha(1)
.alpha(1) .on("tick", ticked)
.restart(); .on("end", ended)
//.velocityDecay(0.8)
.force(forceName,force)
.restart();
} }

View File

@@ -5,6 +5,7 @@ function startNeighbourSamplingSimulation() {
console.log("startNeighbourSamplingSimulation"); console.log("startNeighbourSamplingSimulation");
//springForce = true; //springForce = true;
alreadyRanIterations = 0; alreadyRanIterations = 0;
manualStop = true;
simulation.stop(); simulation.stop();
p1 = performance.now(); p1 = performance.now();
@@ -20,6 +21,8 @@ function startNeighbourSamplingSimulation() {
simulation simulation
.alphaDecay(0) .alphaDecay(0)
.alpha(1) .alpha(1)
.on("tick", ticked)
.on("end", ended)
.force(forceName, force); .force(forceName, force);
// Restart the simulation. // Restart the simulation.
console.log(simulation.force(forceName).neighbourSize(), simulation.force(forceName).sampleSize()); console.log(simulation.force(forceName).neighbourSize(), simulation.force(forceName).sampleSize());