2017-06-18 697 views
0

我用我的Neo4j配置了Popoto.js,它工作正常。 但我的要求是用我想要的节点启动grpah。例如,如果我传递一个节点id或一个关键约束,那么该图应该以该节点为根节点开始。默认情况下,图表以我们传递给start方法的标签开始。 有没有这样做的选择?Popoto.js Neo4j-如何启动特定节点的图形

我试过使用getPredefinedConstraints。这样可行。但不幸的是,它用约束来过滤特定的节点类型,无论它在遍历时出现在哪里,这都是不可取的。 我在下面试过,但那并不完全符合我的需要。请帮忙。

"Person" :{ 
    "returnAttributes":["name","age"], 
    "constraintAttribute" : "name", 
    "getPredefinedConstraints": function (node) { 
     x = ["$identifier.name =~ '(?i).*" + nameValue + ".*'"]; 
     return x; 
    } 
} 

回答

0

您可以使用事件侦听器时被添加到设置像在下面的例子中的值根节点:

请注意,您还可以设置根节点“不可改变”的状态,以避免价值取消选择。

/** 
* Listener used when root node is added 
* In this listener root node is initialized with a value 
* and set in immutable state to avoid value deselection. 
* 
* @param rootNode root node reference when graph is created. 
*/ 
var rootNodeListener = function (rootNode) { 

    // Change root node type and label with instanceData 
    rootNode.value = { 
     type: popoto.graph.node.NodeTypes.VALUE, 
     label: "Person", 
     attributes: {name:'Tom Hanks'} 
    }; 

    // Set node as immutable, in this state the value cannot be deselected. 
    rootNode.immutable = true; 
}; 

// Add rootNodeListener on NODE_ROOT_ADD event 
popoto.graph.on(popoto.graph.Events.NODE_ROOT_ADD, rootNodeListener); 

在这里看到的活生生的例子: http://www.popotojs.com/live/simple-graph/selected-with-event.html

或者因为1.1.2你可以用一个预定义的图表(包括选择的值)作为启动功能的参数是这样开始Popoto:

popoto.start({ 
    label: "Person", 
    rel: [ 
     { 
      label: "ACTED_IN", 
      node: { 
       label: "Movie", 
       value: { 
        title: "The Matrix" 
       } 
      } 
     }, 
     { 
      label: "DIRECTED", 
      node: { 
       label: "Movie" 
      } 
     }, 
     { 
      label: "PRODUCED", 
      node: { 
       label: "Movie" 
      } 
     }, 
     { 
      label: "WROTE", 
      node: { 
       label: "Movie" 
      } 
     } 
    ] 
}); 

活生生的例子在这里:http://www.popotojs.com/live/results/predefined-data.html

而且这里更复杂的一个:http://www.popotojs.com/live/save/index.html

+0

谢谢你的回复。 正如您在示例2中提到的那样,我能够使用保存的图形选项来解决这种情况。但是对于我的场景,选项1看起来更理想,请让我尝试一下。特别是让节点不可变的选项会有很大的帮助。 –