简体   繁体   中英

Prefuse : Organizing edges for clarity

I'm working on my personal family tree in Java/Eclipse, and happily bumped into prefuse as for graphic representation. So far the result looks adaquate in regard to my database feed, but I'm still missing key points to make it easier to browse.

Point 1: verteces represent either a person or a union, and my graph is directed from older to younger members. This is reflected by the arrows on the edges. Yet I'd love to group the arrows in 1 direction only (I'm trying to group generations together if you like), but I can't start to find how to do that. For information, I'm using the NodeLinkTreeLayout as of now.

Point 2: aside from the graph itself, my app main window contains a second JPanel where I would like to modify / insert members. So I want to add an action to each node to call the procedures in the second JPanel. My research on how to access a java class from a node are inconclusive so far, it seems that all the examples from the starter prefuse pack are only based on graph interaction.

There it is. You might already have understood that I'm very new to prefuse and not a pro in Java. So any comment / directions / advice would really be appreciated. I will add a screecap and my graph code so you can see what could be done better.

Thank you for your time, and looking forward to reading your insights. yorran

图样本

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

}

So after a lot of reseach, I'm answering to my own questions in case someone meets the same issues :

  • as for point 1 : ForceDirectedGraph is a lot better than NodeLinkTreeLayout, especially when your graph starts counting many members. Family branches make a lot more sense than viewing generations aligned.

  • as for point 2 : node related actions are the way to go, through a 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 } }); 

One more thing : if you add actions to your graph (search, predicates...), make sure to stop them if you need to rebuild your graph at some point. If you don't, your actions will generate errors you will spend hours (if not days) to debug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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