diff --git a/examples/js/src/example-papaparsing/hybrid.js b/examples/js/src/example-papaparsing/hybrid.js index 57d2db5..c42113d 100644 --- a/examples/js/src/example-papaparsing/hybrid.js +++ b/examples/js/src/example-papaparsing/hybrid.js @@ -27,8 +27,7 @@ function startHybridSimulation() { let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull) .sampleIterations(ITERATIONS) .fullIterations(FULL_ITERATIONS) - .pivots(PIVOTS) - .numPivots(NUM_PIVOTS) + .numPivots(PIVOTS ? NUM_PIVOTS:-1) .interpFindTuneIts(INTERP_ENDING_ITS) .interpDistanceFn(distance) .on("sampleTick", ticked) @@ -36,7 +35,7 @@ function startHybridSimulation() { .on("startInterp", startedFull) .on("end", ended); - let sample = hybridSimulation.sample(); + let sample = hybridSimulation.subSet(); addNodesToDOM(sample); hybridSimulation.restart(); diff --git a/src/hybridSimulation.js b/src/hybridSimulation.js index 260efd3..8501f4d 100644 --- a/src/hybridSimulation.js +++ b/src/hybridSimulation.js @@ -29,8 +29,7 @@ export default function (sim, forceS, forceF) { SAMPLE_ITERATIONS = 300, FULL_ITERATIONS = 20, interpDistanceFn, - PIVOTS = false, - NUM_PIVOTS = 3, + NUM_PIVOTS = 0, INTERP_FINE_ITS = 20, sample = [], remainder = [], @@ -105,7 +104,6 @@ export default function (sim, forceS, forceF) { } function sampleEnded() { - event.call("startInterp"); simulation.stop(); simulation.force("Sample force", null); // Reset velocity of all nodes @@ -114,8 +112,10 @@ export default function (sim, forceS, forceF) { sample[i].vy=0; } + + event.call("startInterp"); let p1 = performance.now(); - if (PIVOTS) { + if (NUM_PIVOTS>=1) { interpolationPivots(sample, remainder, NUM_PIVOTS, interpDistanceFn, INTERP_FINE_ITS); } else { interpBruteForce(sample, remainder, interpDistanceFn, INTERP_FINE_ITS); @@ -130,7 +130,7 @@ export default function (sim, forceS, forceF) { .on("end", null) // The ending condition should be iterations count .nodes(nodes); - if (FULL_ITERATIONS==0 || forceF === undefined || forceF === null) { + if (FULL_ITERATIONS<1 || forceF === undefined || forceF === null) { event.call("end"); return; } @@ -152,10 +152,6 @@ export default function (sim, forceS, forceF) { return hybrid; }, - pivots: function (_) { - return arguments.length ? (PIVOTS = _, hybrid) : PIVOTS; - }, - numPivots: function (_) { return arguments.length ? (NUM_PIVOTS = +_, hybrid) : NUM_PIVOTS; }, @@ -168,10 +164,6 @@ export default function (sim, forceS, forceF) { return arguments.length ? (FULL_ITERATIONS = +_, hybrid) : FULL_ITERATIONS; }, - interpDistanceFn: function (_) { - return arguments.length ? (interpDistanceFn = +_, hybrid) : interpDistanceFn; - }, - interpFindTuneIts: function (_) { return arguments.length ? (INTERP_FINE_ITS = +_, hybrid) : INTERP_FINE_ITS; }, @@ -180,11 +172,11 @@ export default function (sim, forceS, forceF) { return arguments.length > 1 ? (event.on(name, _), hybrid) : event.on(name); }, - sample: function (_) { + subSet: function (_) { return arguments.length ? (sample = _, hybrid) : sample; }, - remainder: function (_) { + nonSubSet: function (_) { return arguments.length ? (remainder = _, hybrid) : remainder; },