Hybrid change config reading mechanism.
This commit is contained in:
@@ -9,17 +9,17 @@ export default function (nodes, config) {
|
|||||||
|
|
||||||
var hybrid,
|
var hybrid,
|
||||||
fullSimulation,
|
fullSimulation,
|
||||||
SAMPLE_ITERATIONS = config.hasOwnProperty("iteration") ? config.iteration : 300,
|
SAMPLE_ITERATIONS = readConf(config, "iteration", 300),
|
||||||
neighbourSize = config.hasOwnProperty("neighbourSize") ? config.neighbourSize : 6,
|
neighbourSize = readConf(config, "neighbourSize", 6),
|
||||||
sampleSize = config.hasOwnProperty("sampleSize") ? config.sampleSize : 3,
|
sampleSize = readConf(config, "sampleSize", 3),
|
||||||
distanceRange = config.hasOwnProperty("distanceRange") ? config.distanceRange : 10,
|
distanceRange = readConf(config, "distanceRange", 10),
|
||||||
FULL_ITERATIONS = config.hasOwnProperty("fullIterations") ? config.fullIterations : 20,
|
FULL_ITERATIONS = readConf(config, "fullIterations", 20),
|
||||||
FullneighbourSize = config.hasOwnProperty("fullNeighbourSize") ? config.fullNeighbourSize : 6,
|
FullneighbourSize = readConf(config, "fullNeighbourSize", neighbourSize),
|
||||||
FullsampleSize = config.hasOwnProperty("fullSampleSize") ? config.fullSampleSize : 3,
|
FullsampleSize = readConf(config, "fullSampleSize", sampleSize),
|
||||||
FulldistanceRange = config.hasOwnProperty("fullDistanceRange") ? config.fullDistanceRange : 10,
|
FulldistanceRange = readConf(config, "fullDistanceRange", distanceRange),
|
||||||
distanceFn = config.hasOwnProperty("distanceFn") ? config.distanceFn : constant(300),
|
distanceFn = readConf(config, "distanceFn", constant(300)),
|
||||||
PIVOTS = config.hasOwnProperty("pivots") ? config.pivots : false,
|
PIVOTS = readConf(config, "pivots", false),
|
||||||
NUMPIVOTS = config.hasOwnProperty("numPivots") ? config.numPivots : 3,
|
NUMPIVOTS = readConf(config, "numPivots", 3),
|
||||||
event = d3.dispatch("sampleTick", "fullTick", "startFull", "end");
|
event = d3.dispatch("sampleTick", "fullTick", "startFull", "end");
|
||||||
|
|
||||||
var sets = takeSampleFrom(nodes, Math.sqrt(nodes.length));
|
var sets = takeSampleFrom(nodes, Math.sqrt(nodes.length));
|
||||||
@@ -150,30 +150,8 @@ export default function (nodes, config) {
|
|||||||
return fullSimulation.force("neighbourSampling").stress();
|
return fullSimulation.force("neighbourSampling").stress();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readConf(config, prop, default){
|
||||||
function sampleFromNodes(nodes, size) {
|
return config.hasOwnProperty(prop) ? config.prop : default,
|
||||||
let randElements = [],
|
|
||||||
max = nodes.length;
|
|
||||||
|
|
||||||
for (var i = 0; i < size; ++i) {
|
|
||||||
var rand = nodes[Math.floor((Math.random() * max))];
|
|
||||||
// If the rand is already in random list or in exclude list
|
|
||||||
// ignore it and get a new value.
|
|
||||||
while (randElements.includes(rand)) {
|
|
||||||
rand = nodes[Math.floor((Math.random() * max))];
|
|
||||||
}
|
|
||||||
randElements.push(rand);
|
|
||||||
}
|
|
||||||
|
|
||||||
var remainder = nodes.filter(function (node) {
|
|
||||||
return !randElements.includes(node);
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
sample: randElements,
|
|
||||||
remainder: remainder
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user