문제

I am using this RGraph example from the InfoVis toolkit to draw my nodes. This is how my nodes look in JSON:

{"id":"parentId","name":"parent","adjacencies":[{"nodeTo":"missingChildId","nodeFrom":"parentId"}]}

The problem is that missingChildId refers to a non-existing node. Currently InfoVis draws an edge from the parent node to a node which it labels "missingChildId".

I don't want this edge to be drawn.

Similarily the function node.eachAdjacency gives nodes that don't exist in the graph. Is there some sort of filter to sort those missing nodes out?

Thank you.

도움이 되었습니까?

해결책

There seems to be a couple of problems with your json data.

1: If you specify "nodeFrom" and "nodeTo" in adjacencies in your json data then infovis will create those adjacencies. In ideal case you should not have such adjacencies in your json data.

2: Also, nodeTo and nodeFrom in adjacencies points to ids of the nodes you want to refer to and ids are supposed to be unique. From your data it seems like "missingChildId" and "parentId" are not unique. Are you sure those are unique ids?

I think you must make sure that each node has a unique id and use them in adjacencies.

If there is no way you can fix your json for 1st problem then one work around is to hide those nodes with id "missingChildId".

So, after your graph is rendered, you can use following code to hide nodes with id "missingChildId".

rg.graph.eachNode( function(node){
    if( node.id == "missingChildId" )
        node.setData("alpha",0,"end");
});
rg.graph.animate({
   modes: ['node-property:alpha'],
   duration: 500
});

Similarly every time you iterate over nodes/adjacencies of graph you will have to filter out all such unwanted nodes by using their id. You can also set your custom property on nodes which are unwanted.

node.setData("ignore",true); 

And then filter them using this property.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top