我不确定我使用当前的SVG标准可以解决的问题,但我想如果有人知道答案我会问这里
我有一个不断变化的svg路径(通过在d3中形成的节点周围形成一个船体来定义顶点,强制驱动所以节点不断移动,并且边界船体移动以容纳节点)
因为我无法预测顶点,也不知道文本将是什么(因为它取决于那种情况下节点的分组,哪些更改)我所能做的就是盲目地将文本路径上的文本应用到路径中.问题有时文本显示不好.
问题1:颠倒的文本 - 我不介意文本在路径上的位置,但令人讨厌的是它经常以颠倒的方式结束
例如(图片):

[NB问题2分支到SVG文本路径渲染在带有尖角的文本路径上严重破坏单词,如答案中所建议的]
问题2:分解文本 - 当角落形成时,文本有分裂的倾向.起来.我不认为我使用dy将文本推到边界之外有帮助(路径实际上对节点很紧,我应用40个笔划宽度来给出一些填充:dy将文本推到该笔划之外)
例如(图片):

关于我能做些什么来解决这个问题的任何想法?
- 克里斯
svg代码供参考:
问题1:
<g id="hull_elements">
<path class="boundary" id="Secure" d="M219.31353652066463,309.7274362305448L199.3259715998452,277.60331505353355L54.5215284230899,92.9756148805194L29.418010605669316,64.72387260525474Z" style="fill: #b0c4de; stroke: #b0c4de; stroke-width: 40px; stroke-linejoin: round;"></path>
<path class="boundary" id="DMZ" d="M234.7675515627913,79.25604751762172L122.76947855325542,190.1418483839412L271.90702281166267,76.40758102069142Z" style="fill: #b0c4de; stroke: #b0c4de; stroke-width: 40px; stroke-linejoin: round;"></path>
</g>
<g id="hull_text">
<text dy="30"><textPath startOffset="0" text-anchor="start" method="align" spacing="auto" xlink:href="#Secure">Secure</textPath></text>
<text dy="30"><textPath startOffset="0" text-anchor="start" method="align" spacing="auto" xlink:href="#DMZ">DMZ</textPath></text>
</g>
Run Code Online (Sandbox Code Playgroud)
问题2:
<g id="hull_elements"><path class="boundary" id="Secure" d="M30.716331539726912,88.02778447495649L66.8405337274694,100.01086904278971L251.78816229874747,53.214214251587265L277.8704519199028,25.642491075146587Z" style="fill: #b0c4de; stroke: #b0c4de; stroke-width: 40px; stroke-linejoin: round;"></path>
<path class="boundary" id="DMZ" d="M177.8575710153683,149.56053657599713L251.04637461899244,245.55658992744486L277.76418020025847,271.7261370009561L159.53295211932644,118.0340968521715Z" style="fill: #b0c4de; stroke: #b0c4de; stroke-width: 40px; stroke-linejoin: round;"></path>
</g>
<g id="hull_text">
<text dy="30"><textPath startOffset="0" text-anchor="start" method="align" spacing="auto" xlink:href="#Secure">Secure</textPath></text>
<text dy="30"><textPath startOffset="0" text-anchor="start" method="align" spacing="auto" xlink:href="#DMZ">DMZ</textPath></text>
</g>
Run Code Online (Sandbox Code Playgroud)
玩游戏的jsfiddle显示了这个(移动节点以查看问题) http://jsfiddle.net/zuzzy/GC2C2/
[编辑添加问题2分支的NB - zuzzy]
对于问题1,我认为你需要检测x坐标何时向左移动并在这种情况下将路径拉回到前面.
如果你有
M 0,0 L 100, 0
Run Code Online (Sandbox Code Playgroud)
那可以100> 0所以保持原样.但
M 100, 0 L 0,0
Run Code Online (Sandbox Code Playgroud)
0 <100因此需要逆转.在这种情况下,倒转将为我们提供第一种情况下的路径.
这是一个完整的例子.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="MyPath"
d="M 300 200
L 100 200" />
<path id="MyPathReversed"
d="M 100 200
L 300 200" />
</defs>
<desc>Example toap01 - simple text on a path</desc>
<g transform="translate(0, 100)">
<text font-family="Verdana" font-size="42.5" fill="blue" >
<textPath xlink:href="#MyPath">
upside down
</textPath>
</text>
</g>
<text font-family="Verdana" font-size="42.5" fill="blue" >
<textPath xlink:href="#MyPathReversed">
right way up
</textPath>
</text>
</svg>
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我建议你将问题2作为一个单独的问题.