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 constant from "./constant";
|
||||||
import interpolation from "./interpolation";
|
import interpolation from "./interpolation";
|
||||||
import interpolationPivots from "./interpolationPivots";
|
import interpolationPivots from "./interpolationPivots";
|
||||||
|
import neighbourSamplingDistance from "./neighbourSamplingDistance";
|
||||||
|
|
||||||
export default function (nodes) {
|
export default function (nodes, config) {
|
||||||
|
|
||||||
var hybrid,
|
var hybrid,
|
||||||
fullSimulation,
|
fullSimulation,
|
||||||
distance = constant(300),
|
SAMPLE_ITERATIONS = config.hasOwnProperty("iteration") ? config.iteration : 300,
|
||||||
MULTIPLIER = 50,
|
neighbourSize = config.hasOwnProperty("neighbourSize") ? config.neighbourSize : 6,
|
||||||
PIVOTS = false,
|
sampleSize = config.hasOwnProperty("sampleSize") ? config.sampleSize : 3,
|
||||||
NUMPIVOTS = 3,
|
distanceRange = config.hasOwnProperty("distanceRange") ? config.distanceRange : 10,
|
||||||
SAMPLE_ITERATIONS = 300,
|
FULL_ITERATIONS = config.hasOwnProperty("fullIterations") ? config.fullIterations : 20,
|
||||||
FULL_ITERATIONS = 20,
|
FullneighbourSize = config.hasOwnProperty("fullNeighbourSize") ? config.fullNeighbourSize : 6,
|
||||||
neighbourSize = 6,
|
FullsampleSize = config.hasOwnProperty("fullSampleSize") ? config.fullSampleSize : 3,
|
||||||
sampleSize = 3,
|
FulldistanceRange = config.hasOwnProperty("fullDistanceRange") ? config.fullDistanceRange : 10,
|
||||||
event = d3Dispatch.dispatch("sampleTick", "fullTick", "startFull", "end");
|
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 sets = sampleFromNodes(nodes, nodes.length, Math.sqrt(nodes.length));
|
||||||
var sample = sets.sample;
|
var sample = sets.sample;
|
||||||
var remainder = sets.remainder;
|
var remainder = sets.remainder;
|
||||||
var interpSubset = sampleFromNodes(sample, sample.length, Math.sqrt(sample.length)).sample;
|
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));
|
.alphaDecay(1 - Math.pow(0.001, 1 / SAMPLE_ITERATIONS));
|
||||||
|
|
||||||
sampleSimulation
|
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 () {
|
.on("tick", function () {
|
||||||
event.call("sampleTick", sampleSimulation);
|
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() {
|
function ended() {
|
||||||
if (PIVOTS) {
|
if (PIVOTS) {
|
||||||
@@ -151,4 +156,4 @@ function sampleFromNodes(nodes, max, size) {
|
|||||||
sample: randElements,
|
sample: randElements,
|
||||||
remainder: remainder
|
remainder: remainder
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user