2011-08-27 9 views
3

내가이 점 코드를 사용하고 있습니다 질문 :그라파 graphviz를 점 시각화 문제와 내 테스트에 대한

Graph graph = null; 

    graph = program.getGraph(); 

    JScrollPane jsp = new JScrollPane(); 
    jsp.getViewport().setBackingStoreEnabled(true); 

    GrappaPanel gp = new GrappaPanel(graph); 
    gp.addGrappaListener(new GrappaAdapter()); 
    gp.setScaleToFit(false); 
    jsp.setViewportView(gp); 

출력은 :

digraph G { edge [dir=none]; 
p1 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; 
q1 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; 
q2 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; 
q3 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; 
{rank=same; father->p1; mother->p1}; 
{rank=same; q1->q2->q3}; 
{rank=same; son1; daughter1; daughter2}; 
p1->q2; 
q1->son1; 
q2->daughter1; 
q3->daughter2; 
} 

내 자바 코드 그래프를 만들 수는 다음과 이 : Link

왜 형식이 잘못 되었습니까? 왼쪽에서 오른쪽으로 트리를 표시 할 수 있습니까?

답변

1

GrappaPanel에서 그래프를 표시하기 전에 graphviz (그래프, "도트", "neato"... 중 하나)를 "포맷"하여 그래프에 요청해야합니다. 당신이 GrappaPanel를 구성하기 전에 다음을 수행해야합니다 GrappaSupport.filterGraph에서 "그래프"그래프

String [] processArgs = {"dot"}; // You can use "neato" or whatever formatter you want 
Process formatProcess = Runtime.getRuntime().exec(processArgs, null, null); 
GrappaSupport.filterGraph(graph, formatProcess); 
formatProcess.getOutputStream().close(); 

입니다. 그 후, 그래프의 형식이 올바르게 지정되어 있고 GrappaPanel을 사용하여 그래프를 볼 수 있습니다. 결과는 귀하가 링크에 올린 것보다 더 즐겁습니다.

호프, 도움이 되길 바랍니다.

추신 : 위 코드가 작동하려면 "점"(또는 사용하는 다른 포맷터)이 경로에 있어야합니다. 그렇지 않으면 실행 파일의 전체 경로를 지정해야합니다.