neo4j - 如何使用 Sigma JS (NEO4J) 获取选定的节点?

标签 neo4j sigma.js

我正在尝试检索所选节点。

我已经做到了:

    s.graph.nodes()

但是这个命令返回所有图节点?

你知道该怎么做吗?

最佳答案

您可以创建一些查找函数来通过 ID 查找节点。

function lookupNodesByKeyValue(sigmaInstance, key, value) {
  return sigmaInstance.graph.nodes().filter(node => node[key] === value);
}
function lookupNodeByKeyValue(sigmaInstance, key, value) {
  return lookupNodesByKeyValue(sigmaInstance, key, value).pop();
}
function lookupNodeById(sigmaInstance, value) {
  return lookupNodeByKeyValue(sigmaInstance, 'id', value);
}

var graphData = {
  "nodes": [
    { "id": "n0", "label": "A node", "x": 0, "y": 0, "size": 3 },
    { "id": "n1", "label": "Another node", "x": 3, "y": 1, "size": 2 },
    { "id": "n2", "label": "And a last one", "x": 1, "y": 3, "size": 1 },
  ],
  "edges": [
    { "id": "e0", "source": "n0", "target": "n1" },
    { "id": "e1", "source": "n1", "target": "n2" },
    { "id": "e2", "source": "n2", "target": "n0" },
  ]
};

// Initialize Sigma object
var s = new sigma({ 
  graph: graphData,
  container: 'sigma-container',
  settings: { defaultNodeColor: '#ec5148' }
});
// Set initial zoom
s.cameras[0].goTo({ x: 1, y: 1, angle: 0, ratio: 2.0 });

console.log("Node 'n2' => " + lookupNodeById(s, "n2").label);
body {
  background: #ddd;
}

.sigma-wrapper {
  max-width: 240px;
  background: #fff;
  border: 2px solid #AAA;
  margin: auto;
}

#sigma-container {
  max-width: 240px;
  height: 240px;
}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.1/sigma.min.js"></script>
<div class="sigma-wrapper">
  <div id="sigma-container"></div>
</div>

关于neo4j - 如何使用 Sigma JS (NEO4J) 获取选定的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48910426/

相关文章:

java - 获取查询中的深度配置不使用 Neo4j OGM API 中的关系方向

javascript - 将嵌套的 Json 转换为带有 parentId 的平面 Json 到每个节点

javascript - 如何以编程方式在 Sigma.Js 中显示 overNode 标签?

javascript - 添加 sigma.js 导航按钮

java - 如何在 Java Neo4J 中正确迭代 Cypher 查询的组合结果

linux - 无法在 ubuntu 中启动 neo4j 服务器

javascript - 我如何 "plug in"sigma.js 的插件?

css - 如何在其相应的容器中包含 sigmajs 图

Azure 门户 : How to restrict IP address access to app deployed in an Azure virtual machine?

javascript - 在哪里以及如何使用数据段代码?