我正在努力使用 textWrap 来正确调整文本的大小和所需的换行符。结果我不得不用分隔符';'分割文本 在我的代码的早期部分中使用正则表达式(15 个字符后)。
此时添加文本环绕要么没有影响,要么将文本呈现为对象。
任何帮助或建议将不胜感激
PS:我对 D3 很陌生,所以提前为任何愚蠢的错误道歉
node.filter(d => !String(d.icon).includes('img/'))
.append('text')
.classed('node-icon', true)
.attr('font-size', d=>d.radius > 100 ? "14" : "10")
.attr("fill", "white")
.attr('clip-path', d => `url(#clip-${d.id})`)
.selectAll('tspan')
.data(d => d.icon.split(';'))
.enter()
.append('tspan')
.attr('x', 0)
.attr('y', (d, i, nodes) => (13 + (i - nodes.length / 2 - 0.5) * 11))
.text(name => name);