简体   繁体   English

在 SVG 中围绕 DndTree 中的标签绘制矩形(D3 树图)

[英]Draw rectangle in SVG around tags in DndTree (D3 tree graph)

I've found this great piece of code, which I'd like to use in my hobby project: http://bl.ocks.org/robschmuecker/7926762我找到了这段很棒的代码,我想在我的爱好项目中使用它: http : //bl.ocks.org/robschmuecker/7926762

I'd like to draw rectangles around the nodes (and color them, which wil have different meanings).我想在节点周围绘制矩形(并为它们着色,这将具有不同的含义)。

I've found this question: How can I draw a box around text with SVG?我发现了这个问题: How can I draw a box around text with SVG? I changed it to operate on classes and added this piece of code at the end of update() method: add_bounding_box('nodeText');我将其更改为对类进行操作,并在 update() 方法的末尾添加了这段代码: add_bounding_box('nodeText');

The following happened:发生了以下情况:

在此处输入图片说明

Also it had issues when I was trying to close the nodes, being duplicated.当我试图关闭节点时,它也有问题,被复制。

I've tried to reach out the developer to help me with this feature, but he hasn't yet answered me.我试图联系开发人员以帮助我完成此功能,但他尚未回复我。

I was able to do what I wanted by slightly modifying the above linked code.通过稍微修改上面的链接代码,我能够做我想做的事。 So, in the current case there wasn't any problem with the transformation, because I added the element already as the child of the transformed element.因此,在当前情况下,转换没有任何问题,因为我已经将元素添加为转换元素的子元素。

The issue was that the linked question sets attribute X and Y to some number, which shouldn't be happening in my case.问题是链接的问题将 X 和 Y 属性设置为某个数字,这在我的情况下不应该发生。 I've stripped those attributes.我已经剥离了这些属性。

Also I had to take into account that it's zoomable, so I had to divide width/height by the scale count.我还必须考虑到它是可缩放的,所以我必须将宽度/高度除以比例数。

Finally I just had to take care whether the item was left or right aligned, but that's actually trivial.最后我只需要注意项目是左对齐还是右对齐,但这实际上是微不足道的。

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

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