SigmaJs 添加更多节点属性

SigmaJs Adding More Node Attributes

我正在尝试添加有关节点的信息。 JSON 通过这种方式导入到图表中:

$.getJSON...
     s = new sigma({
        graph: json,
        settings: {
            enableHovering: false
      }

JSON 文件的属性比 sigma 搜索的导入图多。例如

"nodes": [{"size": 3.104487111312395, "color": "rgb(181, 229, 127)", 
    "attributes": {"pp": "...jpg"}, "id":1,"x":1,"y":1,

但是 sigmajs 没有将这些属性导入图形,它只使用 x y 颜色和大小。

    <circle data-node-id="1" class="sigma-node" fill="rgb(85, 184, 141)"
 cx="357.70791360671683" cy="-151.86561654993392" r="1.8292755337720816"
 style="display: none;"></circle>

如何将附加属性导入 sigma 节点?

在 SVG 渲染器上,Sigma 只采用这些属性:

  • 颜色
  • 编号
  • x
  • y
  • 尺码

看这里:https://github.com/jacomyal/sigma.js/blob/master/src/renderers/svg/sigma.svg.nodes.def.js#L43-L45

如果您想在 SVG 对象上获得更多数据,您可以:

  • 用你自己的
  • 覆盖sigma.svg.nodes.def.js文件
  • 在生成 SVG 后使用一些 JS 脚本对其进行了增强:在 sigma 的节点数组上进行循环,通过其 id 获取 SVG 元素,然后执行您想要的操作

但出于我的好奇,你为什么要这样做?

干杯