React D3树库SVG样式在树上没有看到

发布于 2025-01-30 05:23:37 字数 600 浏览 4 评论 0 原文

我有这样的SVG设计:

true svg crenderCustomNodeElement prop,SVG这样更改:

obgly svg

是否有人知道为什么会发生这种情况?

您可以从这里看到完整的代码:

I have an svg design like this:

true svg

when I put this svg into the Tree component with renderCustomNodeElement prop, svg changes like this:

broken svg

Does anyone know why is this happening?

You can see the full code from here:
https://codesandbox.io/s/rd3t-v2-custom-svg-tag-forked-dp4bbt?file=/src/App.js

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2025-02-06 05:23:37

在检查器中查看代码时,您可以看到以下类添加到元素中:

.rd3t-node {
    cursor: pointer;
    fill: #777;
    stroke: #000;
    stroke-width: 2;
}

这些中风属性是导致它的原因。我无法立即分辨出是什么原因引起的,但是它似乎是React-D3-Tree库添加的类。

我将以下内容添加到您的styles.css,以修复它。

svg .rd3t-node {
    stroke-width: 0px;
}

请注意,如果您在SVG中添加任何中风的东西,这也可能会弄乱中风。最好检查 react d3树文档,以查看是否可以更好地覆盖它。

When viewing your code in the inspector, you can see the following class is added to your elements:

.rd3t-node {
    cursor: pointer;
    fill: #777;
    stroke: #000;
    stroke-width: 2;
}

Those stroke attributes are what's causing it. I cannot immediately tell what's causing it, but it seems to be a class added by the react-d3-tree library.

I added the following to your styles.css, which fixed it.

svg .rd3t-node {
    stroke-width: 0px;
}

Note that if you add anything that has a stroke to your svg, this might also mess with the stroke. It would be better to check the react d3 tree documentation to see if you can override it in a better way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文