แก้ coding style ภาค 3
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import {dispatch} from "d3-dispatch";
|
import {dispatch} from 'd3-dispatch';
|
||||||
import constant from "./constant";
|
import constant from './constant';
|
||||||
import interpBruteForce from "./interpolation/interpBruteForce";
|
import interpBruteForce from './interpolation/interpBruteForce';
|
||||||
import interpolationPivots from "./interpolation/interpolationPivots";
|
import interpolationPivots from './interpolation/interpolationPivots';
|
||||||
import {takeSampleFrom} from "./interpolation/helpers";
|
import {takeSampleFrom} from './interpolation/helpers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of Chalmers, Morrison, and Ross' 2002 hybrid layout
|
* An implementation of Chalmers, Morrison, and Ross' 2002 hybrid layout
|
||||||
@@ -36,7 +36,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
simulation = sim,
|
simulation = sim,
|
||||||
forceSample = forceS,
|
forceSample = forceS,
|
||||||
forceFull = forceF,
|
forceFull = forceF,
|
||||||
event = d3.dispatch("sampleTick", "fullTick", "startInterp", "end"),
|
event = d3.dispatch('sampleTick', 'fullTick', 'startInterp', 'end'),
|
||||||
initAlready = false,
|
initAlready = false,
|
||||||
nodes,
|
nodes,
|
||||||
alreadyRanIterations,
|
alreadyRanIterations,
|
||||||
@@ -50,11 +50,11 @@ export default function (sim, forceS, forceF) {
|
|||||||
initAlready = true;
|
initAlready = true;
|
||||||
alreadyRanIterations = 0;
|
alreadyRanIterations = 0;
|
||||||
simulation
|
simulation
|
||||||
.on("tick", sampleTick)
|
.on('tick', sampleTick)
|
||||||
.on("end", sampleEnded)
|
.on('end', sampleEnded)
|
||||||
.nodes(sample)
|
.nodes(sample)
|
||||||
.force("Sample force", forceSample);
|
.force('Sample force', forceSample);
|
||||||
console.log("Initialized Simulation for Hybrid");
|
console.log('Initialized Simulation for Hybrid');
|
||||||
}
|
}
|
||||||
|
|
||||||
function initForces () {
|
function initForces () {
|
||||||
@@ -80,7 +80,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
simulation
|
simulation
|
||||||
.stop()
|
.stop()
|
||||||
.alphaDecay(0)
|
.alphaDecay(0)
|
||||||
.alpha(1)
|
.alpha(1);
|
||||||
|
|
||||||
let sets = takeSampleFrom(nodes, Math.sqrt(nodes.length));
|
let sets = takeSampleFrom(nodes, Math.sqrt(nodes.length));
|
||||||
sample = sets.sample;
|
sample = sets.sample;
|
||||||
@@ -89,7 +89,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
|
|
||||||
// Sample simulation ticked 1 frame, keep track of number of iterations here.
|
// Sample simulation ticked 1 frame, keep track of number of iterations here.
|
||||||
function sampleTick () {
|
function sampleTick () {
|
||||||
event.call("sampleTick");
|
event.call('sampleTick');
|
||||||
if (alreadyRanIterations++ >= SAMPLE_ITERATIONS) {
|
if (alreadyRanIterations++ >= SAMPLE_ITERATIONS) {
|
||||||
sampleEnded();
|
sampleEnded();
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
|
|
||||||
// Full simulation ticked 1 frame, keep track of number of iterations here.
|
// Full simulation ticked 1 frame, keep track of number of iterations here.
|
||||||
function fullTick () {
|
function fullTick () {
|
||||||
event.call("fullTick");
|
event.call('fullTick');
|
||||||
if (alreadyRanIterations++ >= FULL_ITERATIONS) {
|
if (alreadyRanIterations++ >= FULL_ITERATIONS) {
|
||||||
fullEnded();
|
fullEnded();
|
||||||
}
|
}
|
||||||
@@ -106,40 +106,40 @@ export default function (sim, forceS, forceF) {
|
|||||||
function fullEnded () {
|
function fullEnded () {
|
||||||
simulation.stop();
|
simulation.stop();
|
||||||
initAlready = false;
|
initAlready = false;
|
||||||
simulation.force("Full force", null);
|
simulation.force('Full force', null);
|
||||||
event.call("end");
|
event.call('end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sampleEnded () {
|
function sampleEnded () {
|
||||||
simulation.stop();
|
simulation.stop();
|
||||||
simulation.force("Sample force", null);
|
simulation.force('Sample force', null);
|
||||||
// Reset velocity of all nodes
|
// Reset velocity of all nodes
|
||||||
for (let i = sample.length - 1; i >= 0; i--) {
|
for (let i = sample.length - 1; i >= 0; i--) {
|
||||||
sample[i].vx = 0;
|
sample[i].vx = 0;
|
||||||
sample[i].vy = 0;
|
sample[i].vy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.call("startInterp");
|
event.call('startInterp');
|
||||||
if (NUM_PIVOTS >= 1) {
|
if (NUM_PIVOTS >= 1) {
|
||||||
interpolationPivots(sample, remainder, NUM_PIVOTS, interpDistanceFn, INTERP_FINE_ITS);
|
interpolationPivots(sample, remainder, NUM_PIVOTS, interpDistanceFn, INTERP_FINE_ITS);
|
||||||
} else {
|
} else {
|
||||||
interpBruteForce(sample, remainder, interpDistanceFn, INTERP_FINE_ITS);
|
interpBruteForce(sample, remainder, interpDistanceFn, INTERP_FINE_ITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.call("fullTick");
|
event.call('fullTick');
|
||||||
alreadyRanIterations = 0;
|
alreadyRanIterations = 0;
|
||||||
simulation
|
simulation
|
||||||
.on("tick", null)
|
.on('tick', null)
|
||||||
.on("end", null) // The ending condition should be iterations count
|
.on('end', null) // The ending condition should be iterations count
|
||||||
.nodes(nodes);
|
.nodes(nodes);
|
||||||
|
|
||||||
if (FULL_ITERATIONS < 1 || forceF === undefined || forceF === null) {
|
if (FULL_ITERATIONS < 1 || forceF === undefined || forceF === null) {
|
||||||
event.call("end");
|
event.call('end');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
simulation
|
simulation
|
||||||
.on("tick", fullTick)
|
.on('tick', fullTick)
|
||||||
.force("Full force", forceFull)
|
.force('Full force', forceFull)
|
||||||
.restart();
|
.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
interpDistanceFn: function (_) {
|
interpDistanceFn: function (_) {
|
||||||
return arguments.length ? (interpDistanceFn = typeof _ === "function" ? _ : constant(+_), hybrid) : interpDistanceFn;
|
return arguments.length ? (interpDistanceFn = typeof _ === 'function' ? _ : constant(+_), hybrid) : interpDistanceFn;
|
||||||
},
|
},
|
||||||
|
|
||||||
simulation: function (_) {
|
simulation: function (_) {
|
||||||
@@ -197,7 +197,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
|
|
||||||
forceFull: function (_) {
|
forceFull: function (_) {
|
||||||
return arguments.length ? (forceFull = _, initForces(), hybrid) : forceFull;
|
return arguments.length ? (forceFull = _, initForces(), hybrid) : forceFull;
|
||||||
},
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {takeSampleFrom} from "./helpers";
|
import {takeSampleFrom} from './helpers';
|
||||||
import {placeNearToNearestNeighbour} from "./interpCommon";
|
import {placeNearToNearestNeighbour} from './interpCommon';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform interpolation where the "parent" node is found by brute-force.
|
* Perform interpolation where the "parent" node is found by brute-force.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {pointOnCircle, sumDistError} from "./helpers";
|
import {pointOnCircle, sumDistError} from './helpers';
|
||||||
import jiggle from "../jiggle";
|
import jiggle from '../jiggle';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phase 2 and 3 of each node to be interpolated.
|
* Phase 2 and 3 of each node to be interpolated.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {takeSampleFrom} from "./helpers";
|
import {takeSampleFrom} from './helpers';
|
||||||
import {placeNearToNearestNeighbour} from "./interpCommon";
|
import {placeNearToNearestNeighbour} from './interpCommon';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform interpolation where the "parent" node is is estimated by pivot-based searching.
|
* Perform interpolation where the "parent" node is is estimated by pivot-based searching.
|
||||||
@@ -77,7 +77,6 @@ export default function(sampleSet, remainderSet, numPivots, distanceFn, endingIt
|
|||||||
}
|
}
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
let sampleSubset = takeSampleFrom(sampleSet, Math.sqrt(sampleSet.length)).sample;
|
let sampleSubset = takeSampleFrom(sampleSet, Math.sqrt(sampleSet.length)).sample;
|
||||||
// Plot each of the remainder nodes
|
// Plot each of the remainder nodes
|
||||||
for (let i = remainderSet.length - 1; i >= 0; i--) {
|
for (let i = remainderSet.length - 1; i >= 0; i--) {
|
||||||
|
|||||||
Reference in New Issue
Block a user