(function() { var bbox, height, inner_svg, svg, txt, width; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; svg.attr({ viewBox: "" + (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); svg.append('rect').attr({ x: -380, y: -200, width: 760, height: 400 }); inner_svg = svg.append('svg').attr({ x: -380, y: -200, width: 760, height: 400, preserveAspectRatio: 'none' }); txt = inner_svg.append('text').text('Hello Ground!'); bbox = txt.node().getBBox(); inner_svg.attr({ viewBox: "" + bbox.x + " " + bbox.y + " " + bbox.width + " " + bbox.height }); }).call(this);