Compare commits
7 Commits
pivotHitRa
...
withConsol
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6182a5fc26 | ||
|
|
adf8126d86 | ||
|
|
0d148b555f | ||
|
|
5ee568b1cb | ||
|
|
054ff7312e | ||
|
|
6813be06df | ||
|
|
b88d3c9bfa |
@@ -143,7 +143,7 @@ If *threshold* is specified, sets a threshold and returns this force. When the a
|
||||
|
||||
If *handler* is specified, sets a handler function which will be called at the end of each iteration if the average velocity changes of the system goes below the [threshold](#neighbourSampling_stableVelocity), and returns this force. To remove the handler, change it to null. If *threshold* is not specified, returns the current value, which defaults to null.
|
||||
|
||||
### Hybrid Layout Simulation - TO WRITE
|
||||
### Hybrid Layout Simulation
|
||||
|
||||
The hybrid layout algorithm reduces the computation power usage even further by performing neighbour and sampling algorithm on only $\sqrt{n}$ sample subset of the data, and interpolating the rest in. Neighbour and sampling algorithm may also be ran again over the full dataset after the interpolation to refine the layout. This algorithm is only recommended for visualizing larger dataset.
|
||||
|
||||
@@ -151,9 +151,9 @@ The hybrid layout algorithm reduces the computation power usage even further by
|
||||
|
||||
Creates a new hybrid layout simulation default parameters. The simulation will takeover control of [d3.forceSimulation](https://github.com/d3/d3-force#forceSimulation) provided (*simulation* parameter). *forceSample* and *forceFull* are pre-configured [d3.forceNeighbourSampling](#forceNeighbourSampling) forces to be run over the $\sqrt{n}$ samples and full dataset respectively. While unsupported, other D3 forces such as [d3.forceLinkFullyConnected](forceLinkFullyConnected) may also work.
|
||||
|
||||
*forceSample* may have [stableVelocity](neighbourSampling_stableVelocity) configured to end the simulation and begin the interpolation phase early, but any [handler](neighbourSampling_onStableVelo) functions will be replaced be hybridSimulation's own internal function.
|
||||
*forceSample* and *forceFull* may have [stableVelocity](neighbourSampling_stableVelocity) configured to end the simulation and begin the interpolation phase early, but any [handler](neighbourSampling_onStableVelo) functions will be replaced be hybridSimulation's own internal function.
|
||||
|
||||
*forceSample* may be absent, null, or undefined to skip the final refinement.
|
||||
*forceFull* may also be absent, null, or undefined to skip the final refinement.
|
||||
|
||||
*simulation* should have already been loaded with nodes. If there are any changes in the list of nodes, the simulation have to be re-set using the [.simulation](#hybrid_simulation) method.
|
||||
|
||||
@@ -175,7 +175,7 @@ If *force* is specified, sets the neighbour and sampling force to run on the $\s
|
||||
|
||||
<a name="hybrid_forceFull" href="#hybrid_forceFull">#</a> *hybrid*.**forceFull**([*force*])
|
||||
|
||||
If *force* is specified, sets the neighbour and sampling force to run on the whole dataset after interpolation and returns this layout simulation. If set to null, the process will be skipped. If *force* is not specified, returns the current force object.
|
||||
If *force* is specified, sets the neighbour and sampling force to run on the whole dataset after interpolation and returns this layout simulation. The same limitation applies: [stableVelocity](neighbourSampling_stableVelocity) may be configured to end the simulation and begin the interpolation phase early, but any [handler](neighbourSampling_onStableVelo) functions will be replaced be hybridSimulation's own internal function. If set to null, the process will be skipped. If *force* is not specified, returns the current force object.
|
||||
|
||||
<a name="hybrid_sampleIterations" href="#hybrid_sampleIterations">#</a> *hybrid*.**sampleIterations**([*iterations*])
|
||||
|
||||
|
||||
@@ -200,7 +200,11 @@ function ticked() {
|
||||
.attr("cy", function (d) {
|
||||
return d.y*MULTIPLIER;
|
||||
});
|
||||
}
|
||||
}/*
|
||||
if(alreadyRanIterations%10 != 1) stresses.push("");
|
||||
else stresses.push(d3.calculateStress(nodes, function (n, m) {
|
||||
return distanceFunction(n, m, props, norm);
|
||||
}));*/
|
||||
// Emit the distribution data to allow the drawing of the bar graph
|
||||
if (springForce) {
|
||||
intercom.emit("passedData", simulation.force(forceName).distributionData());
|
||||
@@ -214,7 +218,7 @@ function ended() {
|
||||
simulation.stop();
|
||||
simulation.force(forceName, null);
|
||||
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
|
||||
.attr("cx", function (d) {
|
||||
return d.x*MULTIPLIER;
|
||||
@@ -222,7 +226,7 @@ function ended() {
|
||||
.attr("cy", function (d) {
|
||||
return d.y*MULTIPLIER;
|
||||
});
|
||||
}
|
||||
//}
|
||||
|
||||
if (p1 !== 0) {
|
||||
// Performance time measurement
|
||||
@@ -236,6 +240,9 @@ function ended() {
|
||||
p1 = 0;
|
||||
p2 = 0;
|
||||
}
|
||||
console.log("Post stress", d3.calculateStress(nodes, function (n, m) {
|
||||
return distanceFunction(n, m, props, norm);
|
||||
}));
|
||||
}
|
||||
|
||||
function brushEnded() {
|
||||
|
||||
@@ -16,12 +16,13 @@ function startHybridSimulation() {
|
||||
let forceSample = d3.forceNeighbourSampling()
|
||||
.neighbourSize(NEIGHBOUR_SIZE)
|
||||
.sampleSize(SAMPLE_SIZE)
|
||||
.stableVelocity(0)
|
||||
.stableVelocity(0.43)
|
||||
.distance(distance)
|
||||
|
||||
let forceFull = d3.forceNeighbourSampling()
|
||||
.neighbourSize(FULL_NEIGHBOUR_SIZE)
|
||||
.sampleSize(FULL_SAMPLE_SIZE)
|
||||
.stableVelocity(0.6)
|
||||
.distance(distance)
|
||||
|
||||
let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull)
|
||||
|
||||
@@ -15,7 +15,7 @@ function startLinkSimulation() {
|
||||
.distance(function (n, m) {
|
||||
return distanceFunction(n, m, props, norm);
|
||||
})
|
||||
.stableVelocity(0.000001) //TODO
|
||||
.stableVelocity(0) //TODO
|
||||
.onStableVelo(ended);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -40,7 +40,8 @@ export default function (sim, forceS, forceF) {
|
||||
initAlready = false,
|
||||
nodes,
|
||||
alreadyRanIterations,
|
||||
hybrid;
|
||||
hybrid,
|
||||
p0 = performance.now(), p1, p2, p3;
|
||||
|
||||
if(simulation != undefined) initSimulation();
|
||||
if(forceS != undefined || forceF != undefined) initForces();
|
||||
@@ -63,6 +64,10 @@ export default function (sim, forceS, forceF) {
|
||||
forceSample.onStableVelo(sampleEnded);
|
||||
}
|
||||
|
||||
if (forceFull.onStableVelo) {
|
||||
forceFull.onStableVelo(fullEnded);
|
||||
}
|
||||
|
||||
// Set default value for interpDistanceFn if not been specified yet
|
||||
if(interpDistanceFn === undefined) {
|
||||
if(forceFull.distance == 'function')
|
||||
@@ -96,14 +101,25 @@ export default function (sim, forceS, forceF) {
|
||||
function fullTick() {
|
||||
event.call("fullTick");
|
||||
if(++alreadyRanIterations >= FULL_ITERATIONS){
|
||||
simulation.stop();
|
||||
initAlready = false;
|
||||
simulation.force("Full force", null);
|
||||
event.call("end");
|
||||
fullEnded();
|
||||
}
|
||||
}
|
||||
|
||||
function fullEnded() {
|
||||
p3 = performance.now();
|
||||
simulation.stop();
|
||||
initAlready = false;
|
||||
simulation.force("Full force", null);
|
||||
console.log("Phase 1 takes", p1-p0);
|
||||
console.log("Phase 2 takes", p2-p1);
|
||||
console.log("Phase 3 takes", p3-p2);
|
||||
console.log("Total", p3-p0);
|
||||
console.log("Phase 3 iterations", alreadyRanIterations);
|
||||
event.call("end");
|
||||
}
|
||||
|
||||
function sampleEnded() {
|
||||
p1 = performance.now();
|
||||
simulation.stop();
|
||||
simulation.force("Sample force", null);
|
||||
// Reset velocity of all nodes
|
||||
@@ -118,6 +134,7 @@ export default function (sim, forceS, forceF) {
|
||||
} else {
|
||||
interpBruteForce(sample, remainder, interpDistanceFn, INTERP_FINE_ITS);
|
||||
}
|
||||
p2 = performance.now();
|
||||
|
||||
event.call("fullTick");
|
||||
alreadyRanIterations = 0;
|
||||
|
||||
@@ -54,7 +54,7 @@ export default function() {
|
||||
node = nodes[i];
|
||||
velocityDiff += Math.abs(Math.hypot(node.vx-node.oldvx, node.vy-node.oldvy));
|
||||
}
|
||||
velocityDiff /= n*(n-1);
|
||||
velocityDiff /= n;
|
||||
latestVelocityDiff = velocityDiff;
|
||||
|
||||
if(velocityDiff<stableVelocity){
|
||||
|
||||
@@ -60,12 +60,13 @@ export default function () {
|
||||
node = nodes[i];
|
||||
velocityDiff += Math.abs(Math.hypot(node.vx-node.oldvx, node.vy-node.oldvy));
|
||||
}
|
||||
velocityDiff /= n*(neighbourSize+sampleSize);
|
||||
velocityDiff /= n;
|
||||
latestVelocityDiff = velocityDiff;
|
||||
|
||||
if(velocityDiff<stableVelocity){
|
||||
stableVeloHandler();
|
||||
}
|
||||
else console.log(velocityDiff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user