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