我有一个函数可以清除节点或边缘数据集中的所有数据,然后继续用新数据重新填充它们。它是一个分层网络,在创建所有节点和边之后动态设置级别,因此节点的级别属性最终
由nodes.update()调用添加。
节点的级别已正确设置,可以在我的控制台日志中看到,但图表不反映级别。没有显示错误。看到节点看起来是如何正确的,我不认为这是设置水平问题的方法,但我能想到的唯一可能会干扰的其他事情是在像我这样的角度工厂中使用它,节点.update()不会触发重新呈现图形,或者触发我的选项。任何见解都值得赞赏,因为我真的不知道为什么设置级别不会改变我的图形。
抱歉缺乏信息。我根本不知道从哪里开始,也不想分享我的整个文件。
networkFactory:
var nodes, edges, network;
visApp.factory('networkFactory', function() {
var service = {};
service.init = function() {
// create an array with nodes
nodes = new vis.DataSet();
// create an array with edges
edges = new vis.DataSet();
// create a network
var container = document.getElementById('callFlow');
var data = {
nodes: nodes,
edges: edges
};
var options = {
physics: false,
nodes: {
shape: 'box',
size: 25
},
edges: {
smooth: {
type: 'cubicBezier',
roundness:.75
}
},
layout: {
hierarchical: {
direction: 'LR',
sortMethod: 'directed'
}
},
interaction: {
navigationButtons: true
}
};
network = new vis.Network(container, data, options);
};
service.updateVis = function(profile) {
try {
console.log("updating network...");
clearNetwork();
addNodesFromProfile(profile);
addEdgesFromProfile(profile);
console.log("setting hierarchical levels");
setLevels("ENTRY", 1, 1);
console.log("network updated:\n" + JSON.stringify(nodes.get()));
}
catch(err) {alert(err)}
};
的console.log:
updating network...
adding nodes
adding edges
setting hierarchical levels
network updated:
[{"id":"mainMenu","label":"mainMenu","level":4},{"id":"broadcast","label":"broadcast","level":3},{"id":"greeting","label":"greeting","level":2},{"id":"salesMenu","label":"salesMenu","level":5},{"id":"exitAssurance","label":"exitAssurance","level":5},{"id":"EXIT","label":"EXIT","level":7},{"id":"exitArchitecture","label":"exitArchitecture","level":6},{"id":"exitSalesEast","label":"exitSalesEast","level":6},{"id":"exitCXAnalytics","label":"exitCXAnalytics","level":6},{"id":"servicesMenu","label":"servicesMenu","level":5},{"id":"exitSalesWest","label":"exitSalesWest","level":6},{"id":"exitOther","label":"exitOther","level":5},{"id":"ENTRY","label":"ENTRY","level":1}]
答案 0 :(得分:2)
添加
network.body.emitter.emit('_dataChanged')
之前
network.redraw()
答案 1 :(得分:0)
在nodes.update()
之后,您可以使用network.redraw()
功能刷新视图。