d3-hierarchy icon indicating copy to clipboard operation
d3-hierarchy copied to clipboard

Layouts should not mutate data.

Open mbostock opened this issue 9 years ago • 1 comments

This will be a breaking change, but I think we really want hierarchy layouts to be immutable—to return a copy of the hierarchy with the layout’s computed coordinates applied, rather than setting the computed coordinates directly on the input hierarchy. Given that the semantics of node.copy are already defined, this should not be difficult to do. It shouldn’t be hard to implement resquarify, since it can read the input node._squarify and set the output node._squarify.

Probably this means that node.sum and node.sort should return copies of the hierarchy, too, making everything immutable.

mbostock avatar Oct 27 '16 21:10 mbostock

Just a note on this, we're doing layouts on 250,000 nodes. If this was immutable, it would add a lot of GC and memory overhead

jacobp100 avatar Aug 02 '17 11:08 jacobp100