2013-08-26 3 views
2

나는 forceAtlas2가 실행되는 동안 주 그래프에서 하위 그래프를 동적으로 추가 및 제거하려는 sigma.js를 사용하는 프로젝트에서 작업하고 있습니다. 저는 JS 초보자입니다. 제 질문은 아마도 JavaScript 문제 일지 모르지만 저는 그 문제를 해결할 수 없습니다.Sigma.js - 기존 그래프의 노드 속성 수정

function loadGraph (json) { 
    console.log ("load graph"); 
    sigInst.stopForceAtlas2(); 
    $.getJSON(json, function (data) { 
     var edges = data.edges; 
     var nodes = data.nodes; 
     $.each(nodes, function (index, value) { 
      addNode(value.label, value.x, value.y, value.id, value.size, value.color); 
     }); 
     $.each(edges, function (index, value) { 
      addEdge(value.source, value.target, value.id, value.weight); 
     }); 
    }); 
    sigInst.draw(2,2,2); 

}

이것은위한 addNode 함수 :

function addNode (label, x, y, id, size, color) { 
if (!sigInst.hasNode(id)) { 
    sigInst.addNode(id,{ 
     'x': x, 
     'y': y, 
     label: label, 
     size:size, 
     color: color 
    }); 
    console.log ("added node " + id); 
} 
else { 
    var nodeExisting = sigInst.getNodes(id); 
    var exSize = parseInt(nodeExisting.size); 
    console.log ("node " + id + " former size: "+ exSize); 
    exSize += parseInt(size); 
    nodeExisting.size = exSize; 
    console.log ("node " + id + " size now: " + exSize); 
} 
sigInst.draw(); 

}

과는

는 시그마 인스턴스로 그래프 그래프를로드하기위한 기능이다 addEdge 함수 :

이 작업을하기 위해
function addEdge (source, target,id, weight) { 
if (!sigInst.hasEdge(id)) { 
    sigInst.addEdge(id, source, target, weight).draw(); 
} 
else { 
    var edgeExisting = sigInst.getEdges(id); 
    //console.log("existing weight: " + edgeExisting.weight); 
    var exSize = parseInt(edgeExisting.weight); 
    exSize += parseInt(weight); 
    edgeExisting.weight = exSize; 
    //console.log("modified weight: " + edgeExisting.weight + " (" + edgeExisting.source + " -> " + edgeExisting.target + ")"); 
} 

}

, 나는 sigma.min.js에 두 가지 기능을 추가 :

this.hasNode = function(id){return typeof(b.graph.nodesIndex[id]) != 'undefined';}; 

this.hasEdge = function (id) {return typeof(b.graph.edgesIndex[id])!='undefined';}; 

내 문제를 그 addNode 명 기능하지 않는 것입니다 실제로 기존 노드의 크기를 증가시킵니다. Java에서 왔습니다. JavaScript에서 기존 노드가 참조로 전달되지 않았을 가능성이 있으므로 필드를 수정하고 sigInst 객체가 이것을 반영 할 것으로 기대할 수는 없지만이를 수행하는 방법을 모르겠습니다. 아무도 도와 줄 수 있다면 가장 감사 할 것입니다. 미리 감사드립니다!

답변

2

OK가 해결 : 나 sigma.min.js 두 기능을 추가 :

this.setEdgeWeight = function(id,n){b.graph.edgesIndex[id].weight=n;} 

this.setNodeSize = function(id,n){b.graph.nodesIndex[id].size=n;}; 

는 I 명백하게 지연되었다. 어쩌면 누군가가 이러한 기능을 활용할 수 있습니다.

+1

노드/에지 속성을 동적으로 변경할 수있게하기 위해 수행 한 작업에 대해 자세히 설명해 주실 수 있습니까? 코드 추가를 시도했지만 작동하지 않았습니다. –