我有一个函数可以清除节点或边数据集中可能存在的任何数据,然后继续用新数据重新填充它们。它是一个分层网络,级别是在创建所有节点和边后动态设置的,因此节点的级别属性最终是
通过nodes.update() 调用添加。
节点的级别设置正确,可以在我的控制台日志中看到,但图表不反映级别。没有显示错误。看到节点似乎是正确的,我不认为设置级别的方法是问题所在,但我能想到的唯一可能干扰的其他事情是在像我这样的角度工厂中使用它,节点.update() 不会触发图形的重新渲染,或者我的选项。任何见解都值得赞赏,因为我真的不知道为什么设置级别不会改变我的图表。
抱歉缺少信息。我只是不知道从哪里开始,也不想分享我的整个文件。
网络工厂:
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)}
};
控制台.日志:
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}]
添加
network.body.emitter.emit('_dataChanged')
之前
network.redraw()
在
nodes.update()
之后您可以使用network.redraw()
功能刷新视图。
要自动更新图表,必须在网络对象上调用以下方法:
network.setData({nodes: yourNodes, edges: yourEdges})