Gephi Visualization (ii)--GEPHI Toolkit Challenge Prefuse

Source: Internet
Author: User
Tags netbeans

Following the "Gephi Visualization (i)--using Gephi toolkit to create Gephi app" In the garden, this article provides a detailed introduction to Gephi Toolkit after using the Gephi Toolkit toolset for visual programming. Understanding how it works and how it differs from Gephi applications, Gephi Toolkit requirements for the platform, and finally, by comparing the visual Toolset Prefuse, lists the similarities between the two visualization tools.

Gephi Toolkit is a standard Java class library in which any Java project can be introduced (including Eclipse, NetBeans, etc.), which contains the necessary modules in Gephi such as graph, Layout, Filters, Io, and so on.

The toolkit has only one jar file that can be used in Java applications, preserving most of the features of Gephi.

  Official homepage: http://gephi.github.io/toolkit/

  GitHub Home: Https://github.com/gephi/gephi-toolkit-demos

  Working principle:

Gephi is based on the idea of modularization, which truly embodies the idea of cohesion-poly-low coupling. Each module is responsible for different responsibilities, such as graph with a specific graphical structure, and layout-specific layouts. The Gephi Toolkit here is the tool set that stripped the user interfaces modules (UI module) from the Gephi source and is able to keep the program running properly, which is what this toolset is all about. We can get an overview of the relationship between Gephi and Gephi Toolkit:

See, it is also the separation of the dependency module with NetBeans, so that Gephi Toolkit can also be run in Eclipse or MyEclipse (Gephi is based on the NetBeans platform development).

Gephi Toolkit has added a preview feature since the 0.8 release to ensure visual representation through the Previewcontroller class after writing the visual requirements code and to support scaling.

Below we still go through the form of code to explore Gephi Toolkit

  1. Creating a project is essential, and it is worth mentioning that Gephi supports multiple workspaces, a mechanism similar to that of multiple workspaces (i.e. desktops) of Linux (heard Win10 also supports this multi-desktop effect). Gephi different workspace in the same time to perform different graphics display and operation.

The code is as follows:

Init a Project-and therefore a workspaceprojectcontroller pc = Lookup.getdefault (). Lookup (Projectcontroller.class); Pc.newproject (); Workspace Workspace = Pc.getcurrentworkspace ();

  

  2. through the lookup global class, get the operation model or controller of each object ( the personal feeling lookup uses the principle of reflection to get the object of the class, not to delve into)

Graphmodel Graphmodel = Lookup.getdefault (). Lookup (Graphcontroller.class). Getmodel (); Previewmodel model = Lookup.getdefault (). Lookup (Previewcontroller.class). Getmodel (); Previewcontroller Previewcontroller = Lookup.getdefault (). Lookup (Previewcontroller.class);

Graphmodel is like a container for the entire graphical element, including nodes, edges, tags, and so on, and Previewmodel equals to an operation entry for how to perform a preview.

  3. in the workspace to import data, different from the above directly read the data file, the method used to generate random graphs, the number of randomly generated nodes 500, The probability of the edge-to-edge connection is 0.005, and the data is received with the container container, and the container is loaded into the workspace workspace using the Import interface controller.

Generate a new random graph into a containercontainer container = Lookup.getdefault (). Lookup (Containerfactory.class). Newcontainer (); Randomgraph randomgraph = new Randomgraph (); Randomgraph.setnumberofnodes (+); Randomgraph.setwiringprobability ( 0.005); Randomgraph.generate (Container.getloader ());     Append container to graph Structureimportcontroller Importcontroller = Lookup.getdefault (). Lookup ( Importcontroller.class); importcontroller.process (container, New Defaultprocessor (), workspace);

  

  4. add various layout algorithms to the AutoLayout by automating the layout class. The Forceatlaslayout layout and the Yifanhulayout layout are respectively added here, and the execution time is set to one minute.

AutoLayout AutoLayout = new AutoLayout (1, timeunit.minutes); Autolayout.setgraphmodel (Graphmodel); Yifanhulayout firstlayout = new Yifanhulayout (null, new Stepdisplacement (1f)); Forceatlaslayout secondlayout = new forceatlaslayout (null); Autolayout.dynamicproperty Adjustbysizeproperty = Autolayout.createdynamicproperty ("ForceAtlas.adjustSizes.name", Boolean.true, 0.1f);//true after 10% of layout timeautolayout.dynamicproperty Repulsionproperty = Autolayout.createdynamicproperty ("ForceAtlas.repulsionStrength.name", New Double (.), 0f);//500 for the complete Periodautolayout.addlayout (Firstlayout, 0.5f); Autolayout.addlayout (Secondlayout, 0.5f, new Autolayout.dynamicproperty[]{adjustbysizeproperty, Repulsionproperty}); Autolayout.execute ();

  By looking at the source code of the AutoLayout class, we find that the AutoLayout in the Autolayout.addlayout () method is actually a list collection.

5. said so much. , we do visualize or need to see the truth, you can set the display parameters through Previewmodel, such as whether to display the label on the node, the color thickness of the edge, and so on.

Model.getproperties (). Putvalue (Previewproperty.show_node_labels, boolean.true); Model.getproperties (). PutValue ( Previewproperty.node_label_color, New Dependantoriginalcolor (Color.White)); Model.getproperties (). PutValue ( Previewproperty.edge_color, New Edgecolor (Color.White)); Model.getproperties (). Putvalue (Previewproperty.edge_ THICKNESS, New Float (0.1f)); Model.getproperties (). Putvalue (Previewproperty.background_color, Color.Black); Model.getproperties (). Putvalue (Previewproperty.node_label_font, Model.getproperties (). GetFontValue ( Previewproperty.node_label_font). Derivefont (8));p Reviewcontroller.refreshpreview (); New processing target, get the pappletprocessingtarget target = (processingtarget) previewcontroller.getrendertarget ( Rendertarget.processing_target); Papplet applet = Target.getapplet (); Applet.init ()//refresh the preview and reset the Zoompreviewcontroller.render ( target); Target.refresh (); Target.resetzoom ();//add the applet to a JFrame and displayjframe frame = new JFrame ("Test PrevIew "); Frame.setlayout (new BorderLayout ()); Frame.setdefaultcloseoperation (Jframe.exit_on_close); Frame.add (applet, borderlayout.center); Frame.pack (); frame.setvisible (true);

  

Once all the required parameters have been configured, add them to the JFrame for an interface display.

Pictures in the process of running the program:

You can see from the graph that the yifanhulayout and forceatlaslayout layouts were performed separately.

  After reading Gephi Toolkit in the construction of graphics, add layout effect, the process of showing graphics, or can not help to take and prefuse contrast, although some of the names of different classes, but in the processing methods are similar to the wonderful, the following simple list of several similarities:

  1.Workspace (Gephi) and visualization (Prefuse)

Prefuse in the visualization is a data center, so the data will eventually be pooled into the data center, including the structure of the graph, how to render, the layout of the addition, and so on; Gephi's workspace is also an internal top-level container, Similar to the Visualizaiton function, through the code

Previewcontroller.refreshpreview ();

  Entering the Refreshpreview () method can also be found to update the workspace object, which is to update the data.

  2.Graphmodel (Gephi) and Visualgraph (Prefuse)

Visualgraph in Prefuse is the process of completing graph from graph to data center, which adds nodes or edges to the original graph graph and how other elements are eventually drawn, including a lot of configuration elements for final drawing Gephi's Graphmodel is also an object for graph manipulation, which allows you to do what you want to do with graph.

  3.AutoLayout (Gephi) and ActionList (Prefuse)

The actionlist in Prefuse is a list collection where you can add many actions (i.e. various display effects or constraints) to it, and AutoLayout in Gephi is a similar data interface. By finding the source of the method Autolayout.addlayout (), it is also found that the desired layout is added to a list collection.

Of course, the same point of the two Toolset is not limited to this, and there are also a lot of differences between the two, the details welcome to join the bulletin board on the left group discussion.

If you feel useful, welcome to praise, your praise and encouragement is my continuous momentum!

This article link: "Gephi visualization (ii)--GEPHI Toolkit Prefuse"

Gephi Visualization (ii)--GEPHI Toolkit Challenge Prefuse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.