繁体   English   中英

预熔:整理边缘以便清晰

[英]Prefuse : Organizing edges for clarity

我正在用Java / Eclipse开发我的个人家谱,很高兴碰到图形表示形式的流行。 到目前为止,对于我的数据库提要,结果看起来已经足够了,但是我仍然缺少要点,以便于浏览。

要点1:顶点表示一个人或一个工会,而我的图表是从老年人到年轻人的。 这由边缘上的箭头反映。 但是,我只想将箭头按1个方向分组(如果您愿意,我想将几​​代人分组在一起),但是我无法开始寻找做到这一点的方法。 有关信息,到目前为止,我正在使用NodeLinkTreeLayout。

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

在那里。 您可能已经了解到,我是新手,不是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);
    }

}

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

  • 至于第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 } }); 

还有一件事:如果您向图表中添加动作(搜索,谓词...),请确保在需要重新构建图表时将其停止。 如果不这样做,您的操作将产生错误,您将花费数小时(如果不是几天的话)进行调试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM