I put together a demo of this desired behavior a few days ago. Take a look here - http://bl.ocks.org/4444770
Basically, you listen to the size of the window, apply a proportional transform to the g element, which wraps all the SVG elements, and adjusts the size of the parent SVG. Call this code in pageload and in the resize window, where "container" is the div containing the SVG:
d3.select("g").attr("transform", "scale(" + $("#container").width()/900 + ")"); $("svg").height($("#container").width()*0.618);
This is a good method if your SVG is placed in a div.
Another way is to use the SVG viewBox, as shown here by Mike Bostock - http://bl.ocks.org/harlantwood/raw/6900108/ . This method is best if you add SVG to the body, and I'm sure there is a way to use this method when placing SVG inside a div, but I could not find a solution and thus created the above to work around.
source share