I'm new to d3. I have created a collapsible tree to create an org chart which uses data from a database and mostly works great.
The problem is the svg is a fixed size.
I don't know how many nodes / levels will be in the org chart as it will be used on data / companies of varying sizes.
At the moment I have the svg fixed to a large size which works as a proof of concept.
I need to resize the svg to the width and height of the chart inside. Either setting the dimensions once to the maximum known size of the tree or adjusting the size of the svg when the tree is expanded / collapsed.
This is what I'm using with just a small amount of demo data:
This is where is is set initially but I want to make it dynamic:
var svg = d3.select("body").append("svg")
.attr("width", width + margin.right + margin.left)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
http://jsfiddle.net/urquhartps/c9WC9/1/
Many thanks