2016-02-22 163 views
0

我有一個函數可清除節點或邊數據集中可能存在的任何數據,並繼續用新數據重新填充它們。它是一個分層網絡,在創建所有節點和邊界後動態設置層次,因此節點的層次屬性最終由nodes.update()調用添加 。
節點的級別已正確設置,並且可以在我的控制檯日誌中看到,但圖形不反映這些級別。沒有顯示錯誤。看到這些節點似乎是正確的,我認爲這不是設定問題級別的方法,但我能想到的唯一可能會干擾的其他事情就是在像我這樣的角工廠中使用它,節點.update()不會觸發圖形的重新渲染,也不會觸發我的選項。任何洞察力的讚賞,因爲我真的不知道爲什麼設置關卡不會改變我的圖表。Vis.js網絡圖不隨節點更改而更新

對不起,缺乏信息。我不知道從哪裏開始,也不想分享我的整個文件。

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

nodes.update()後,您可以使用network.redraw()功能來刷新視圖。

1

添加

network.body.emitter.emit('_dataChanged') 

network.redraw()