-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Generator
This HowTo shows how to create a new graph generator in Gephi.
Please look at Plugin Quick Start to know how to create a new Netbeans Module. When you have your plugin module, that we will call MyGenerator, you can start this tutorial.
Add Lookup
, GraphAPI
and LongTaskAPI
modules as dependencies for your plugin module MyGenerator. See How To Set Module Dependencies.
- Create a new class that implements Generator. This is the place the code belongs.
- Fill getName() method by returning a display name like "My Generator". Fill
getUI()
method by returningnull
. Leaves other methods untouched for the moment. - Add
@ServiceProvider
annotation to your builder class. Add the following line before MyGenerator class definition, as shown below:
@ServiceProvider(service = Generator.class)
public class MyGenerator implements Generator {
...
Fill generate()
method by creating NodeDraft
and EdgeDraft
elements to add to the ContainerLoader
.
To let your graph creation task be canceled and its progress watched, implement LongTask
interface on MyGenerator.
Add two fields:
private boolean cancel = false; private ProgressTicket progressTicket;
and implement new methods:
public boolean cancel() {
cancel = true;
return true;
}
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
Use the cancel
field to terminate your algorithm execution properly and return from generate()
.
@ServiceProvider(service = Generator.class)
public class HelloWorld implements Generator {
protected ProgressTicket progress;
protected boolean cancel = false;
public void generate(ContainerLoader container) {
// create nodes
NodeDraft n1 = container.factory().newNodeDraft();
NodeDraft n2 = container.factory().newNodeDraft();
// set node labels
n1.setLabel("Hello");
n2.setLabel("World");
// create edge
EdgeDraft e = container.factory().newEdgeDraft();
e.setSource(n1);
e.setTarget(n2);
// fill in the graph
container.addNode(n1);
container.addNode(n2);
container.addEdge(e);
}
public String getName() {
return "Hello World";
}
public GeneratorUI getUI() {
return null;
}
public boolean cancel() {
cancel = true;
return true;
}
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
}
}
- Developer Handbook
- Build
- Code Style
- Localization
- Datasets
- Import CSV Data
- Import Dynamic Data
- Scripting Plugin
- Quick Start
- Démarrage rapide (FR)
- Layout
- Spatialisations (FR)
- Statistics
- Import
- Spigot importer with Wizard
- Export
- Generator
- Filter
- Extend Data Laboratory
- Preview renderer
- Add a module panel
- Add a submenu
- Build a plugin without Gephi source code
- Update a plugin
- Code Sharing Strategy
- Graph Streaming