简体   繁体   English

绘制指向 d3 圆形包布局的链接

[英]Draw links to a d3 circle pack layout

I need to be able to draw links between the circles in a circle pack layout, like {source: i, target: j} .我需要能够在圆包布局中的圆之间绘制链接,例如{source: i, target: j} I've seen some questions about how to combine this layout with the force layout that made me think It could be a way to achieve this but I haven't had any luck on that path, also what I need is something completely static.我已经看到一些关于如何将此布局与力布局相结合的问题,这让我认为这可能是实现这一目标的一种方式,但我在这条道路上没有任何运气,而且我需要的是完全静态的东西。 Thank you in advance for any suggestions.预先感谢您的任何建议。

I finally could draw lines between nodes by appending them to the svg and calculating each line position based on the radius of the nodes that each line were to connect, but the problem was that the pack layout that I'm using is zoomable, so when I tried to zoom by clicking the lines neither translate nor re-sized (of course, since there was no code performing such things), so I tried to implement a translation function for the lines so they would move along with the zoom, then I saw that it would take some serious geometry to achieve this, so since I'm a lazy programmer and not at all experienced with d3 I tried to come with something more simple... at last I decided to represent the links between the nodes with a different approach (without lines), I used the "mouseover" event so when the pointer is over a node it will highlight (changed circle stroke attribute color and width) the nodes connected to it.我终于可以通过将它们附加到 svg 并根据每条线要连接的节点的半径计算每条线位置来在节点之间绘制线,但问题是我使用的包布局是可缩放的,所以当我尝试通过单击既不平移也不重新调整大小的线条进行缩放(当然,因为没有执行此类操作的代码),因此我尝试为线条实现平移功能,以便它们随缩放一起移动,然后我看到这需要一些严肃的几何来实现这一点,所以由于我是一个懒惰的程序员,并且对 d3 完全没有经验,所以我尝试使用更简单的东西......最后我决定用一种不同的方法(没有线条),我使用了“mouseover”事件,所以当指针悬停在一个节点上时,它会突出显示(改变圆形笔触属性颜色和宽度)连接到它的节点。 This way I achieved my goal and the view looks a lot cleaner without all the lines crossing over it (they were a lot).通过这种方式,我实现了我的目标,并且没有所有线条越过它,视图看起来更干净(它们很多)。 I know that some may think that this does not answer the original question, and I'm sure that this can be achieved by someone with more experience (and time and patience) using lines and implementing the right calculation, but in my case this solution solves my problem and maybe it could be of help to others.我知道有些人可能认为这不能回答最初的问题,我相信这可以通过使用线条并实施正确计算的更有经验(以及时间和耐心)的人来实现,但在我的情况下,此解决方案解决了我的问题,也许对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM