我有一个JSON格式的数据集,其中包含关于节点和边缘的信息,用于在cytoscapeJS中生成网络图。JSON数据包含节点的id、值、形状、颜色和节点的 ('element‘或'none')属性,以及边缘的id、源、目标和标签。我的样式表使用这个“visibleDisplay”属性在cy容器首次初始化时根据需要显示/隐藏节点。
我希望允许用户取消隐藏节点的选项“显示邻里”。我已经修改了我的旧代码以使用集合,但它仍然无法工作:
function showNeighbourhood() {
var eleID;
var neighbourArray= new Array();
var neighbours= cy.collection(); // collection
cy.nodes().forEach(function( ele ) {
if(ele.selected()) { // get the currently selected node.
eleID= ele.id();
}
});
// Find its connected neighbours.
cy.edges().forEach(function( edg ) {
if(edg.data('source') === eleID) {
neighbourArray[neighbourArray.length]= edg.data('target');
}
else if(edg.data('target') === eleID) {
neighbourArray[neighbourArray.length]= edg.data('source');
}
});
// Add the array to the collection.
neighbours.add(neighbourArray);
// Show neighbourhood, using the collection.
neighbours.show();
}对如何使这项工作有什么建议吗?我不能使用集合上的show()方法使所需的节点可见吗?
发布于 2015-03-17 16:12:39
您只需要使用node.neighborhood(),例如cy.$(':selected').neighborhood().removeClass('hidden')。
https://stackoverflow.com/questions/28970633
复制相似问题