(function() { var bbox, height, svg, text, width; width = 960; height = 500; /* create the SVG */ svg = d3.select('body').append('svg').attr('width', width).attr('height', height); text = svg.append('text').text('Hello world!').attr('x', 480).attr('y', 250).attr('dy', '0.35em'); bbox = text[0][0].getBBox(); svg.insert('rect', 'text').attr('x', bbox.x).attr('y', bbox.y).attr('width', bbox.width).attr('height', bbox.height); }).call(this);