当我计算textpath元素的文本长度时,我的样式“字母间距”有不同的价值不会改变。
有没有办法来处理,由于额外的间距长度多余?
目前,我计算到长度限制:Textlength隐藏在二层,partion图形一些标签:
textsElements
.attr("dy", function(d) {
var offset = (radius / strokeWidth)/2;
var rotation = getRotationDeg(d)
return rotation > 0 && rotation < 180 ? -offset : offset;
})
.append("textPath")
.attr("startOffset", "50%")
.attr("class","labels-text")
.style("text-anchor", "middle")
.attr("xlink:href", function (d) { return '#' + createTextPathId(d); })
.text(function (d) { return d.name; });
// Hide labels that are to long
textsElements.each(function(d){
var el = d3.select(this);
d.labelToLong= false;
if(( d.hiddenArcLength - this.getComputedTextLength()) < 5) {
el.style("opacity",0);
d.labelToLong = true;
}
});
textpath.labels-text {letter-spacing: 1px;}