문제

i am using this dot-Code for my Test:

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;
}

My Java Code to create the Graph is the following:

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);

The Output is this: Link

Why is the Tree formatted so wrong? And is there an possibility to let the Tree display from left to right?

도움이 되었습니까?

해결책

You have to "ask" graphviz (any of the tools, "dot", "neato"...) to "format" the graph before you can display it (in an appealing way) in a GrappaPanel. Before you construct the GrappaPanel, you need to do the following:

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();

Where "graph" in GrappaSupport.filterGraph is your graph. After that, your graph is formatted properly and you can use the GrappaPanel to view it. The result will be more pleasant than what you posted in the link.

Hope that helps, regards.

PS: In order for the above code to work, you have to have "dot" (or any other formatter you use) to be in the path, otherwise you need to give it the full path of the executable file.

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