I\'m using d3 to draw a UML diagram and would like to wrap text within the shapes drawn with d3. I\'ve gotten as far as the code below and can\'t find a solution to make the
It's not ideal, but @Pablo.Navarro's answer led me to the following.
var svg = d3.select('#svg')
.append('svg')
.attr('width', 500)
.attr('height', 200);
var radius = 60,
x = 150,
y = 100,
side = 2 * radius * Math.cos(Math.PI / 4),
dx = radius - side / 2;
var global = svg.append('g')
.attr('transform', 'translate(' + [ dx, dx ] + ')');
global.append('circle')
.attr('cx', x)
.attr('cy', y)
.attr('r', radius);
global.append('foreignObject')
.attr('x', x - (side/2))
.attr('y', y - (side/2))
.attr('width', side)
.attr('height', side)
.attr('color', 'red')
.append('xhtml:p')
.text('Text meant to fit within circle')
.attr('style', 'text-align:center;padding:2px;margin:2px;');
