I need my SVG in a webpage to dynamically resize based on window size, or to have multiple hardcoded widths and heights.
I am using the D3 library.
My problem is that it isn't just the SVG tag that needs a different canvas size, it is the children elements such as a rect
tag and g
tag that also need to resize or be completely re-rendered
How would this be done?
I realize I could listen to window resizing with
d3.select(window).on('resize', resize);
with my resize function doing all the logic, but exactly how and what width/heights to choose (or calculate) is beyond me
<div class="svg-container">
<svg width="960" height="500" preserveAspectRatio="xMidYMid" class="svg-content">
<defs>
<clipPath id="clip-upper">
<rect id="rect-clip-upper" width="960" height="305" x="-480" y="-305"> </rect>
</clipPath>
<clipPath id="clip-lower">
<rect id="rect-clip-lower" width="960" height="195" x="-480" y="0"></rect>
</clipPath>
</defs>
<g clip-path="url(#clip-upper)" transform="translate(480,305)"></g>
<g clip-path="url(#clip-lower)" transform="translate(480,305)"></g>
</svg>