Grappa Graphviz点可视化问题和问题

时间:2011-08-27 20:52:40

标签: java graphviz dot graph-layout family-tree

我正在使用这个点代码进行测试:

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

我创建图表的Java代码如下:

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

输出为:Link

为什么Tree格式错误?是否有可能让树从左到右显示?

1 个答案:

答案 0 :(得分:1)

你必须“询问”graphviz(任何工具,“dot”,“neato”......)来“格式化”图形,然后才能在GrappaPanel中以一种吸引人的方式显示它。在构建GrappaPanel之前,您需要执行以下操作:

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

GrappaSupport.filterGraph中的“图表”是您的图表。之后,您的图表格式正确,您可以使用GrappaPanel查看它。结果将比您在链接中发布的结果更令人愉快。

希望有所帮助,尊重。

PS:为了使上述代码有效,你必须在路径中使用“dot”(或你使用的任何其他格式化程序),否则你需要为它提供可执行文件的完整路径。 / p>