【发布时间】:2019-04-02 16:46:04
【问题描述】:
我有一个 React 组件,其中包含一个内置于 react-d3-graph 的图形,并且我试图在单击链接时选择节点之间的链接,但我无法找出定位它的正确方法。我可以使用以下脚本定位单个节点:
d3.select("#graph-id-graph-wrapper").selectAll("g#graph-id-graph-container-
可缩放").selectAll("g[id='" + source + "']").selectAll("path").attr('fill',"red").attr('opacity',"1")
graph-id-graph-wrapper 为顶层div,graph-id-graph-container-zoomable 为子div,节点在布局中引用为g,带ID,路径为实际矩形节点象征。链接是没有 ID 的路径(节点路径的子节点),在代码中如下所示:
<path cursor="pointer" opacity="1" d="M-10.606601717798213,-10.606601717798213h21.213203435596427v21.213203435596427h-21.213203435596427Z" fill="#57a3ff" stroke="none" stroke-width="1.5" class=""></path>
我已经尝试了 d3.select(this) 的无数种变体,但没有任何效果。节点更容易定位,因为它们有 ID,但链接路径没有。
【问题讨论】: