Grappa Graphviz dot-Visualization Problem and Questions

萝らか妹 提交于 2019-12-10 09:57:30

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7217288/grappa-graphviz-dot-visualization-problem-and-questions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!