I am using d3.js to dynamically set up a nested svg, i.e. an inner svg nested inside an enclosing svg. A d3.behavior.zoom() listens for zoom events on the outer svg and does the transformations needed.
All works fine except for the Internet Explorer (IE 11) which seems to have an issue with transformations involving inner svgs. Both Firefox and Chrome behave as expected clipping the inner svg to the viewport of the outer svg. In Internet Explorer, however, zooming in correctly applies transformations but seems to ignore the dimensions of the enclosing svg. The contents of the inner svg will eventually be displayed outside of the outer svg and above other body elements. The viewport of the outer svg seems to have no clipping effect on the inner svg.
I have set up a JSFiddle demonstrating the behaviour.
var zoom = d3.behavior.zoom()
.on("zoom", function () {
container.attr("transform",
"translate(" + d3.event.translate + ") " +
"scale(" + d3.event.scale + ")");
});
var container = d3.select("body")
.append("svg")
.attr("id", "svgcontainer")
.attr("width", 300)
.attr("height", 300)
.style("background-color", "#aaaaee")
.call(zoom)
.append("g");
var svg = container.append("svg")
.attr("width", 200)
.attr("height", 200)
.attr("x", 50)
.attr("y", 50);
svg.append("svg:circle")
.style("fill", "none")
.style("stroke", "red")
.style("stroke-width", "2px")
.attr("cx", 100)
.attr("cy", 100)
.attr("r", 50);
Am I missing something? Is there any cross-browser workaround?