【问题标题】:Grappa Graphviz dot-Visualization Problem and QuestionsGrappa Graphviz dot-Visualization Problem and Questions
【发布时间】:2011-11-05 05:56:17
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案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:为了使上述代码正常工作,路径中必须有“点”(或您使用的任何其他格式化程序),否则您需要为其提供可执行文件的完整路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 2011-03-04
      • 2021-06-04
      • 1970-01-01
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多