Hybrid: change setup to configuration json, 1st phase working
This commit is contained in:
@@ -2,42 +2,47 @@ import { dispatch } from "d3-dispatch";
|
||||
import constant from "./constant";
|
||||
import interpolation from "./interpolation";
|
||||
import interpolationPivots from "./interpolationPivots";
|
||||
import neighbourSamplingDistance from "./neighbourSamplingDistance";
|
||||
|
||||
export default function (nodes) {
|
||||
export default function (nodes, config) {
|
||||
|
||||
var hybrid,
|
||||
fullSimulation,
|
||||
distance = constant(300),
|
||||
MULTIPLIER = 50,
|
||||
PIVOTS = false,
|
||||
NUMPIVOTS = 3,
|
||||
SAMPLE_ITERATIONS = 300,
|
||||
FULL_ITERATIONS = 20,
|
||||
neighbourSize = 6,
|
||||
sampleSize = 3,
|
||||
event = d3Dispatch.dispatch("sampleTick", "fullTick", "startFull", "end");
|
||||
SAMPLE_ITERATIONS = config.hasOwnProperty("iteration") ? config.iteration : 300,
|
||||
neighbourSize = config.hasOwnProperty("neighbourSize") ? config.neighbourSize : 6,
|
||||
sampleSize = config.hasOwnProperty("sampleSize") ? config.sampleSize : 3,
|
||||
distanceRange = config.hasOwnProperty("distanceRange") ? config.distanceRange : 10,
|
||||
FULL_ITERATIONS = config.hasOwnProperty("fullIterations") ? config.fullIterations : 20,
|
||||
FullneighbourSize = config.hasOwnProperty("fullNeighbourSize") ? config.fullNeighbourSize : 6,
|
||||
FullsampleSize = config.hasOwnProperty("fullSampleSize") ? config.fullSampleSize : 3,
|
||||
FulldistanceRange = config.hasOwnProperty("fullDistanceRange") ? config.fullDistanceRange : 10,
|
||||
MULTIPLIER = config.hasOwnProperty("multiplier") ? config.multiplier : 50,
|
||||
distance = config.hasOwnProperty("distance") ? config.distance : constant(300),
|
||||
PIVOTS = config.hasOwnProperty("pivots") ? config.pivots : false,
|
||||
NUMPIVOTS = config.hasOwnProperty("numPivots") ? config.numPivots : 3,
|
||||
event = d3.dispatch("sampleTick", "fullTick", "startFull", "end");
|
||||
|
||||
var sets = sampleFromNodes(nodes, nodes.length, Math.sqrt(nodes.length));
|
||||
var sample = sets.sample;
|
||||
var remainder = sets.remainder;
|
||||
var interpSubset = sampleFromNodes(sample, sample.length, Math.sqrt(sample.length)).sample;
|
||||
|
||||
var sampleSimulation = d3.forceSimulation()
|
||||
var sampleSimulation = d3.forceSimulation(sample)
|
||||
.alphaDecay(1 - Math.pow(0.001, 1 / SAMPLE_ITERATIONS));
|
||||
|
||||
sampleSimulation
|
||||
.force("neighbourSampling", d3.forceNeighbourSampling()
|
||||
.distance(function (s, t) {
|
||||
return distance(s, t, props, norm) * MULTIPLIER;
|
||||
})
|
||||
.neighbourSize(neighbourSize)
|
||||
.sampleSize(sampleSize))
|
||||
.nodes(sample)
|
||||
.on("tick", function () {
|
||||
event.call("sampleTick", sampleSimulation);
|
||||
})
|
||||
.on("end", ended);
|
||||
|
||||
.on("end", ended)
|
||||
.force("neighbourSampling", neighbourSamplingDistance()
|
||||
.neighbourSize(neighbourSize)
|
||||
.sampleSize(sampleSize)
|
||||
.distance(distance)
|
||||
.multiplier(MULTIPLIER)
|
||||
)
|
||||
.stop()
|
||||
.alpha(1).restart();
|
||||
|
||||
function ended() {
|
||||
if (PIVOTS) {
|
||||
@@ -151,4 +156,4 @@ function sampleFromNodes(nodes, max, size) {
|
||||
sample: randElements,
|
||||
remainder: remainder
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user