1

我正在研究我在 Java/Eclipse 中的个人家谱,并且很高兴地遇到了图形表示方面的问题。到目前为止,就我的数据库提要而言,结果看起来已经足够了,但我仍然缺少关键点以使其更易于浏览。

第 1 点:顶点代表一个人或一个工会,我的图表是从年长成员到年轻成员的。这由边缘上的箭头反映出来。然而,我只想将箭头组合在一个方向上(如果你愿意,我会尝试将几代人组合在一起),但我无法开始找到如何做到这一点。有关信息,我现在正在使用 NodeLinkTreeLayout。

第 2 点:除了图形本身,我的应用程序主窗口还包含第二个 JPanel,我想在其中修改/插入成员。所以我想为每个节点添加一个动作来调用第二个 JPanel 中的过程。到目前为止,我对如何从节点访问 java 类的研究尚无定论,似乎所有来自 starter prefuse 包的示例都仅基于图形交互。

它在那里。您可能已经明白我对 prefuse 非常陌生,而不是 Java 专业人士。因此,任何评论/指示/建议将不胜感激。我将添加一个 screecap 和我的图形代码,以便您了解可以做得更好的地方。

感谢您抽出宝贵时间,并期待阅读您的见解。约兰

图表样本

public class ShowGraph extends Display {

    public static final String EDGES = "graph.edges";

    public ShowGraph() {
        super(new Visualization());
        Graph mG = FamGraph.getGraph();

        m_vis.addGraph("graph", mG);
        m_vis.setInteractive("graphe.edges", null, false);
        m_vis.setValue("graph.nodes", null, VisualItem.SHAPE, new Integer(Constants.SHAPE_ELLIPSE));

        EdgeRenderer edgeR = new EdgeRenderer(Constants.EDGE_TYPE_CURVE, Constants.EDGE_ARROW_FORWARD);
        LabelRenderer nodeR = new LabelRenderer("name");
        nodeR.setRoundedCorner(8, 8);
        nodeR.setHorizontalAlignment(Constants.LEFT);

        DefaultRendererFactory drf = new DefaultRendererFactory();
        drf.setDefaultRenderer(nodeR);
        drf.setDefaultEdgeRenderer(edgeR);

        m_vis.setRendererFactory(drf);


        int[] palette = new int[] {
                ColorLib.rgb(255, 180, 180), ColorLib.rgb(190, 190, 255)
        };
        DataColorAction nFill = new DataColorAction("graph.nodes", "label", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
        ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(230));
        ColorAction arrow = new ColorAction("graph.edges", VisualItem.FILLCOLOR, ColorLib.gray(230));
        ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0));

        ActionList color = new ActionList();
        color.add(nFill);
        color.add(edges);
        color.add(arrow);
        color.add(text);

        ActionList layout = new ActionList(Activity.INFINITY);
        //layout.add(new ForceDirectedLayout("graph", true));
        layout.add(new NodeLinkTreeLayout("graph"));
        layout.add(new RepaintAction());

        m_vis.putAction("color", color);
        m_vis.putAction("layout", layout);

        setSize(1200, 900);         //size controlled by parent jpanel - Comment out after tests
        pan(360, 250);
        setHighQuality(true);
        addControlListener(new DragControl());
        addControlListener(new PanControl());
        addControlListener(new ZoomControl());
        addControlListener(new ZoomToFitControl());

        m_vis.run("color");
        m_vis.run("layout");
    }

    public static void main(String[] args) {
        Fulltree.fireUp();
        ShowGraph mG = new ShowGraph();
        JFrame frame = new JFrame("My family chart");
        JPanel thePanel = new JPanel();
        frame.getContentPane().add(thePanel);
        thePanel.add(mG);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

}
4

1 回答 1

1

因此,经过大量研究,如果有人遇到同样的问题,我会回答我自己的问题:

  • 至于第 1 点:ForceDirectedGraph 比 NodeLinkTreeLayout 好很多,尤其是当您的图表开始计算许多成员时。家族分支比查看世代一致更有意义。

  • 至于第 2 点:与节点相关的操作是要走的路,通过 ControlListener:

    addControlListener(new ControlAdapter() {
        public void itemClicked(VisualItem item, MouseEvent e) {
            // anything you need here
            // even filter right and left click for a sub menu
        }
    });
    

还有一件事:如果您向图表添加操作(搜索、谓词......),如果您需要在某个时候重建图表,请确保停止它们。如果您不这样做,您的操作将产生错误,您将花费数小时(如果不是数天)来调试。

于 2018-09-29T08:58:11.567 回答