Prefuse Toolkit: dynamically adding nodes and edges

前端 未结 4 1122
无人及你
无人及你 2020-12-24 11:14

Does anyone have experience with the prefuse graph toolkit? Is it possible to change an already displayed graph, ie. add/remove nodes and/or edges, and have the display corr

4条回答
  •  执念已碎
    2020-12-24 11:56

    You should be aware the several layers of prefuse:

    • Data
    • Visualization
    • Display

    To be short, the three layers can be linked this way:

    Graph graph = new Graph(eg. yourXML_file);
    Visualization viz = new Visualization();
    viz.add(GRAPH, graph);
    Display disp = new Display();
    disp.setVisualization(viz);
    

    Display is a graphic component that you add to a panel as usual.

    Here you only modify the data layer.

    Node newNode = graph.addNode();
    graph.addEdge(oldNode, newNode);
    

    You need now to update the visual layer:

    viz.run("repaint");
    

    The repaint action has to be defined.

    ActionList repaint = new ActionList();
    repaint.add(new RepaintAction());
    viz.putAction("repaint", repaint);
    

    I really advise you to read the prefuse doc. And you can find a lot a resources on the official forum

    At least, I can say you that prefuse is for the moment not really efficient for live graph update.

    But it should not be enough, as you modified the graph structure, you have to regenerate it in the visualization (ie. recalculate the node placements etc...). There are two actions already defined in your sample code. Run them at the end of your actionPerformed.

    viz.run("color");
    viz.run("layout");
    

    This method is not very efficient, because it adds a lot of computation each time you add a node, but there are not any others for the moment with prefuse.

提交回复
热议问题