gpt4 book ai didi

d3.js - SVG 粗曲线路径未按预期运行

转载 作者:行者123 更新时间:2023-12-04 21:50:30 24 4
gpt4 key购买 nike

我正在 D3 中创建一个桑基图,使用路径作为粗大的连接器来指示流程。但是,我发现那些比它们更长的路径开始表现得很奇怪。你可以在这里看到一个例子,我将路径分成几个部分:

 image description here

蓝色和橙色重叠,因为蓝色(以及它后面的灰色)的弯曲方式与较细的路径不同,它们有一种“扭结”。

所有的线曲线都很好,除了这些大的。我用 SVG 做了一个简单的例子:

<SVG height=800 width=800>
<g transform="translate(40,400)">
<Path class="link1" d="M29,-129C104.5,-129 104.5,-202.125 180,-202.125" />
<Path class="link2" d="M29,-129C104.5,-129 104.5,-202.125 180,-202.125" />
<Path class="link3" d="M29,-129C104.5,-129 104.5,-202.125 180,-202.125" />
<Path class="normal" d="M29,-129 L104.5,-129" />
<Path class="normal" d="M104.5,-202 L180,-202.125" />
</g>

你可以在这里看到它:

https://jsfiddle.net/hanvyj/t91pbp4w/

我在谷歌上找不到任何东西,我希望有人会遇到这个问题并知道解决方法,或者有更多的 SVG 经验并且知道不会这样做的 'SVG:Path' 的好替代品?

最佳答案

SVG 笔画宽度表现不同

问题示例:

enter image description here

<svg width="800px" height="600px" viewBox="0 0 100 100">
<path stroke-width="15" stroke="rgba(0,0,0,0.5)" fill="none" d="m0,40 c 20,0 20,-10 40,-10" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,24 c 5,0 5,-5 10,-5" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,27 c 5,0 5,-2 10,-2" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,30 10,0" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,33 c 5,0 5,2 10,2" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,36 c 5,0 5,5 10,5" />

<path stroke-width="3" stroke="rgba(255, 200, 50, 0.7)" fill="none" d="m0,46 c 20,0 20,-10 40,-10" />
</svg>

解决方案:

<svg width="800px" height="600px" viewBox="0 0 100 100">
<path stroke-width="15" stroke="rgba(0,0,0,0.5)" fill="none" d="m0,40 c 20,0 20,-10 40,-10" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,24 c 5,0 5,-5 10,-5" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,27 c 5,0 5,-2 10,-2" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,30 10,0" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,33 c 5,0 5,2 10,2" />
<path stroke-width="3" stroke="rgba(0,0,0,0.5)" fill="none" D="m40,36 c 5,0 5,5 10,5" />

<path stroke-width="3" stroke="rgba(255, 200, 50, 0.7)" fill="none" d="m0,46 c 22,0 22,-10 40,-10" />
</svg>

等等你对路径做了什么?

让我们看看那些橙色路径上的 d 属性。
问题路径:m0,46 c 20,0 20,-10 40,-10
解法路径:m0,46 c 22,0 22,-10 40,-10

我只是调整了C curve command 2 个单位。

我想要差异的图片...哦,好吧:

enter image description here

enter image description here

关于d3.js - SVG 粗曲线路径未按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32758762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com