diff --git a/.changeset/khaki-pugs-hammer.md b/.changeset/khaki-pugs-hammer.md new file mode 100644 index 000000000..948dc5c34 --- /dev/null +++ b/.changeset/khaki-pugs-hammer.md @@ -0,0 +1,5 @@ +--- +'layerchart': patch +--- + +fix(force-simulation): Fixed a bug that would sometimes keep a simulation running, when its inputs change, even if `alpha < alphaMin` diff --git a/packages/layerchart/src/lib/components/ForceSimulation.svelte b/packages/layerchart/src/lib/components/ForceSimulation.svelte index 1787ef4d0..8aabbd574 100644 --- a/packages/layerchart/src/lib/components/ForceSimulation.svelte +++ b/packages/layerchart/src/lib/components/ForceSimulation.svelte @@ -258,12 +258,8 @@ // pass it to the internal d3 simulation object: pushAlphaToSimulation(alpha); - // Only resume the simulation as long as `alpha` - // is above the cut-off threshold of `alphaMin`, - // otherwise our simulation will never terminate: - if (simulation.alpha() >= simulation.alphaMin()) { - runOrResumeSimulation(); - } + // Then we attempt to resume the simulation: + runOrResumeSimulation(); } ); @@ -404,6 +400,13 @@ return; } + if (simulation.alpha() < simulation.alphaMin()) { + // Only resume the simulation as long as `alpha` + // is above the cut-off threshold of `alphaMin`, + // otherwise our simulation will never terminate: + return; + } + onStart(); simulation.restart();