如何在手动导航中使增量添加的节点持久化

时间:2015-08-27 20:26:26

标签: javascript zoomcharts

使用NetChart缩放图(1.5.1),似乎addData()仅适用于navigation = showall。如果我尝试使用navigation = manual,则需要initialNodes

是否有方法initialNodes自动填充现有数据(以增量方式添加)?我想要的原因是因为,我想使用navigation = showall初始加载一组特定的节点/链接,然后将其更改为navigation = manual,以便用户可以单击以查看所有邻居

基本上,以下示例显示了这种情况......节点'f-1'被'm-1'的initialNodes覆盖。

<script>
  var t = new NetChart({
        container: document.getElementById("demo"),
        area: { height: 350 }

    });
    t.addData({nodes: [{loaded: true,id: "f-1",name: "Anna"},{id: "m-1",name: "Joe"}],links: [{to: "f-1",from: "m-1",id: "l01",type: "friend"}]});
    t.updateSettings({
        data:
        {
            preloadNodeLinks:true,
            dataFunction: function(nodeList, success, error){
                //return just the first node, net chart will ask for more
                jQuery.ajax({
                    url:"/dvsl/data/net-chart/friend-net/"+nodeList[0]+".json",
                    success: success,
                    error: error});
            }
        },
        navigation:{
            initialNodes:["m-1"],
            mode:"manual"
        }

    });


</script>

1 个答案:

答案 0 :(得分:0)

使用doubleclick找到解决方法:

<script>
    var t = new NetChart({
      container: document.getElementById("demo"),
      area: {
          height: 350
      },
      events:{
            onDoubleClick: dclickEvent
        }
  });
  t.addData({nodes: [{loaded: true,id: "f-1",name: "Anna"},{id: "m-1",name: "Joe"}],links: [{to: "f-1",from: "m-1",id: "l01",type: "friend"}]});


    function dclickEvent(event){
        if (!$("#click")[0].checked) return;
        console.log('event.clickNode', event.clickNode);
        if (event.clickNode) {
              jQuery.ajax({
                      url: "/dvsl/data/net-chart/friend-net/" + event.clickNode.id + ".json",
                      success: function(data) {
                          console.log('test-foo-data', data);
                          t.addData(data);
                      }
                  })

        }
    }


</script>