(function() { var bbox, ctm, height, rect, setTM, 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('dy', '0.35em').attr('transform', 'translate(480,250)'); setTM = function(element, m) { return element.transform.baseVal.initialize(element.ownerSVGElement.createSVGTransformFromMatrix(m)); }; bbox = text[0][0].getBBox(); ctm = text[0][0].getCTM(); rect = svg.insert('rect', 'text').attr('x', bbox.x).attr('y', bbox.y).attr('width', bbox.width).attr('height', bbox.height); setTM(rect[0][0], ctm); }).call(this);