Centering of d3 tree changes when specifying nodeSize

Viewed 3494

I'm using d3.v4 for this. When I have

var treemap = d3.tree().size([height, width])

the tree is nicely centred

enter image description here

but (because I want to specify the vertical spacing between nodes) when I change this to

var treemap = d3.tree().size([height, width]).nodeSize([40]);

the tree moves to the top left:

enter image description here

Does anyone know why this might be happening?

2 Answers

**Easiest way to do it is **

        document.getElementById("wkgrp").style.transform = "translate(100px, 350px)"

set transform on load as per requirement, so it can dynamically manage by svg.

Related