首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Sigmajs和Neo4j数据库扩展节点(双击鼠标事件)?

如何使用Sigmajs和Neo4j数据库扩展节点(双击鼠标事件)?
EN

Stack Overflow用户
提问于 2018-02-12 13:10:22
回答 1查看 529关注 0票数 0

我正在使用Sigma.js库在Neo4j图形数据库的基础上创建一个webapp。

因此,我有一个有节点和边的图形,我想通过带有javascript的双击事件来扩展节点。

你能帮我做这个吗?

非常感谢

代码语言:javascript
复制
sigma.neo4j.cypher(
    {url :'http://localhost:7474', user: 'neo4j', password: 'neo4j'},
    'MATCH (n)-[r]->(m) RETURN n,r,m LIMIT 100' ,
    {container:'graph-container'},


    function (s) {
        s.graph.nodes().forEach(function (node){


            if (node.neo4j_labels[0] === "Movies"){
            node.label = node.neo4j_data['movie'];
            node.color = '#68BDF6';
            node.size = 26;
            node.type = "star";
          }

            else if (node.neo4j_labels[0] === "Personn"){
            node.label = node.neo4j_data['personn'];
            node.type = "diamond";
            node.color = '#303A2B';
            node.size = 12;
          }


            console.log(s.graph.nodes());
            s.settings('touchEnabled', true);
            s.settings('mouseEnabled', true);
            s.settings('defaultEdgeLabelSize', 18);
            s.settings('defaultNodeLabelSize', 18);
            s.settings('animationsTime', 1000);





        s.graph.edges().forEach(function(e) {
                    //e.type = 'curvedArrow';
                    //e.color='#F00';
                e.originalColor = e.color;
                e.type = "curvedArrow";
                e.size=2;


                    // e.label = neo4j_type;
                //console.log(s.graph.edges())
            });

            s.refresh();


   }); 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-13 12:14:03

您必须像这样绑定sigma事件doubleClickNode

代码语言:javascript
复制
s.bind("doubleClickNode", function(e) {
    var node = e.data.node;
    var query = 'MATCH (n)-[r]-(m) WHERE id(n)=' + node.id+ ' RETURN n,r,m';
    sigma.neo4j.cypher(
      neo4jConfig,
      query,
      function(graph) {
        // adding node if not existing
        graph.nodes.forEach(function (node){
            if(s.graph.nodes(node.id) === undefined) {
            s.graph.addNode(node);
          }
        });
        // adding edge if not existing
        graph.edges.forEach(function (edge){
            if(s.graph.edges(edge.id) === undefined) {
            s.graph.addEdge(edge);
          }
        });

       // apply style
        applyStyle(s);
      }
    );

  });

我的完整示例可以在这里获得:https://jsfiddle.net/sim51/qkc0g58o/34/

在使用它之前,您需要接受Neo4j SSL证书,方法是打开这个链接https://localhost:7473/browser并添加一个安全异常。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48747293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档