admin管理员组文章数量:1410674
I have been working on creating a a cash thermometer that shows the progress for each month. I am having a problem with SVG text Wrapping and could use some help. The animation and everything else is set, I just cant get the text to wrap properly. Any help with this would be greatly appreciated. Below is the JS fiddle Link to my code. You'll notice that the text gets cut out and doesn't display properly.
/
//-- Draw Goal line
if (this.currentProgress >= this.currentGoal) {
this.drawTick(maxTemp, "Goal of " + this.currentGoal + " Reached! " + this.currentProgress + " receieved!", "Black", 0, width, tubeWidth, tubeBorderColor, scale, svg);
} else {
this.drawTick(maxTemp + 3, "Goal: " + this.currentGoal, "black", 0, width, tubeWidth, "Black", scale, svg);
this.drawTick(percentageOfGoal, "Current: " + this.currentProgress, this.getMercuryColor(t), 0, width, tubeWidth, tubeBorderColor, scale, svg);
}
I have been working on creating a a cash thermometer that shows the progress for each month. I am having a problem with SVG text Wrapping and could use some help. The animation and everything else is set, I just cant get the text to wrap properly. Any help with this would be greatly appreciated. Below is the JS fiddle Link to my code. You'll notice that the text gets cut out and doesn't display properly.
https://jsfiddle/corcorancr/4pto1wm5/1/
//-- Draw Goal line
if (this.currentProgress >= this.currentGoal) {
this.drawTick(maxTemp, "Goal of " + this.currentGoal + " Reached! " + this.currentProgress + " receieved!", "Black", 0, width, tubeWidth, tubeBorderColor, scale, svg);
} else {
this.drawTick(maxTemp + 3, "Goal: " + this.currentGoal, "black", 0, width, tubeWidth, "Black", scale, svg);
this.drawTick(percentageOfGoal, "Current: " + this.currentProgress, this.getMercuryColor(t), 0, width, tubeWidth, tubeBorderColor, scale, svg);
}
Share
Improve this question
edited Jul 21, 2017 at 14:59
Corcorancr
asked Jul 21, 2017 at 14:50
CorcorancrCorcorancr
11 gold badge1 silver badge2 bronze badges
2 Answers
Reset to default 2You need to wrap the text elements in a tspan
tag. I made use of the wrap function from a solution which already exists here.
The changes I made was to your drawTick
function, I added .call(wrap,30,label)
svg.append("text")
.attr("x", width / 2 + tubeWidth / 2 + 15)
.attr("y", scale(t))
.attr("dy", "0em")
.text(label)
.style("fill", labelColor)
.style("stroke", "black")
.style("font-size", "16px")
.call(wrap,30,label)
Check out my jsfiddle here
SVG text doesn't have any wrapping functionality. You will need to do it programmatically.
本文标签: javascriptSVG Text WrappingStack Overflow
版权声明:本文标题:javascript - SVG Text Wrapping - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744995154a2636626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论