我想通过Javascript来识别我的节点,从而确保每个元素(图、节点、边缘)都有一个唯一的ID。我找到了https://github.com/magjac/d3-graphviz#maintaining-object-constancy部分,并认为.keyMode('id')会告诉d3-graphviz使用我的ID。但是id仍然在使用图形ID,而且似乎不使用节点ID。我在这个示例中找到了一个title属性:https://bl.ocks.org/magjac/28a70231e2c9dddb84b3b20f450a215f,这个属性是什么?我能确定这是我要找的身份证吗?id和title之间D3-图的关系是什么?
编辑我试着挖掘并想出了这个简单的例子。我有这个(自动生成的)输入文件:
digraph {
label=""
id="g1"
n1 [id="n1", label="First Node"]
n2 [id="n2", label="Second Node"]
n1 -> n2 [id="e1", arrowHead="normal", arrowTail="dot"]
}我得到这样的结果:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="134pt" height="116pt" viewBox="0.00 0.00 133.59 116.00">
<g id="g1" class="graph" transform="translate(4,112) scale(1)">
<polygon fill="white" stroke="transparent" points="-4,4 -4,-112 129.59,-112 129.59,4 -4,4"></polygon>
<!-- n1 -->
<g id="n1" class="node">
<title>n1</title>
<ellipse fill="none" stroke="black" cx="62.8" cy="-90" rx="52.16" ry="18"></ellipse>
<text text-anchor="middle" x="62.8" y="-85.8" font-family="Times,serif" font-size="14.00">First Node</text>
</g>
<!-- n2 -->
<g id="n2" class="node">
<title>n2</title>
<ellipse fill="none" stroke="black" cx="62.8" cy="-18" rx="62.59" ry="18"></ellipse>
<text text-anchor="middle" x="62.8" y="-13.8" font-family="Times,serif" font-size="14.00">Second Node</text>
</g>
<!-- n1->n2 -->
<g id="e1" class="edge">
<title>n1->n2</title>
<path fill="none" stroke="black" d="M62.8,-71.7C62.8,-63.98 62.8,-54.71 62.8,-46.11"></path>
<polygon fill="black" stroke="black" points="66.3,-46.1 62.8,-36.1 59.3,-46.1 66.3,-46.1"></polygon>
</g>
</g>
</svg>但是,当我以编程方式在一个为节点提供<g>的鼠标事件中时,我得到ID:svg-0.g1.n2 --最后一点造成了混乱。我需要找到属性值,而不是连接的值。但那会奏效的。谢谢!
发布于 2022-07-22 18:52:01
底层Graphviz语言提供了一个id属性(https://www.graphviz.org/docs/attrs/id/)。基于d3-graphviz一致性文本,看起来d3-graphviz将遵守这个id属性。
https://stackoverflow.com/questions/73084282
复制相似问题