我正在使用d3绘制UML图,并希望将文本包装在用d3绘制的形状中.我已经得到了下面的代码,并找不到解决方案,使文本"适合"我的形状(见下图).
var svg = d3.select('#svg')
.append('svg')
.attr('width', 500)
.attr('height', 200);
var global = svg.append('g');
global.append('circle')
.attr('cx', 150)
.attr('cy', 100)
.attr('r', 50);
global.append('text')
.attr('x', 150)
.attr('y', 100)
.attr('height', 'auto')
.attr('text-anchor', 'middle')
.text('Text meant to fit within circle')
.attr('fill', 'red');
Run Code Online (Sandbox Code Playgroud)
