d3/d3-hierarchy

Suggestion: pack() layouts with deterministic outputs

jessihamel opened this issue · 5 comments

Currently the circle packing layouts calculated by pack() are not deterministic. (Possibly because of the Math.random() call in shuffle)? It would be helpful if we had an option to ensure consistent outputs given the same input data.

Simple example showing two different outputs with the same data:
Screen Shot 2022-02-24 at 4 54 40 PM

Fil commented

Can you share the actual numbers used? I made this notebook (from Mike's pack-o-matic) to try and reproduce
https://observablehq.com/@fil/pack-189

Yes, we should make it deterministic. We can use a LCG like we did for d3-force.

d3/d3-force@1e3db41

Can you share the actual numbers used? I made this notebook (from Mike's pack-o-matic) to try and reproduce https://observablehq.com/@fil/pack-189

Yes, here is an notebook that should reproduce it. https://observablehq.com/d/6df5cd39d11c9dfa

(Apologies that I didn't show the leaf nodes in the original screenshots, I realize now that was probably confusing.)

Screen Shot 2022-02-27 at 4 27 05 PM

@Fil thank you for the fix! Please push the new version to npm.

UPD: Oops, I missed mentioning the reviewer of the related pull request @mbostock. Please push the new version to npm

FYI I published the forked package. It doesn't have any changes except package name change and patch version. https://www.npmjs.com/package/d3-hierarchy-with-deterministic-pack

I hope everything is OK with the authors