Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

<groupId>org.gephi</groupId>
<artifactId>toolkit-demos</artifactId>
<version>0.10.0</version>
<version>0.11.2</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.0</version>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
<release>17</release>
</configuration>
</plugin>
<plugin>
Expand All @@ -37,9 +36,12 @@

<repositories>
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<id>central-portal-snapshots</id>
<name>Central Portal Snapshots</name>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/org/gephi/toolkit/demos/DynamicMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ License, or (at your option) any later version.
import org.gephi.io.generator.plugin.RandomGraph;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.gephi.statistics.api.StatisticsController;
import org.gephi.statistics.plugin.dynamic.DynamicDegree;
Expand Down Expand Up @@ -69,21 +67,16 @@ License, or (at your option) any later version.
public class DynamicMetric {

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Generate a new random graph into a container
Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
RandomGraph randomGraph = new RandomGraph();
randomGraph.setNumberOfNodes(500);
randomGraph.setWiringProbability(0.005);
randomGraph.generate(container.getLoader());

//Append container to graph structure
//Create a correctly configured project/workspace and process the graph
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
importController.process(container, new DefaultProcessor(), workspace);
Workspace workspace = importController.process(container);

//Add a fake 'Date' column to nodes
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/org/gephi/toolkit/demos/Filtering.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ License, or (at your option) any later version.
import org.gephi.graph.api.GraphView;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;

Expand All @@ -63,15 +61,8 @@ License, or (at your option) any later version.
public class Filtering {

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Get controllers and models
//Get controllers
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
AppearanceModel appearanceModel = Lookup.getDefault().lookup(AppearanceController.class).getModel();

//Import file
Container container;
Expand All @@ -83,8 +74,10 @@ public void script() {
return;
}

//Append imported data to GraphAPI
importController.process(container, new DefaultProcessor(), workspace);
//Create a correctly configured project/workspace and process the import
Workspace workspace = importController.process(container);
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
AppearanceModel appearanceModel = Lookup.getDefault().lookup(AppearanceController.class).getModel(workspace);

//Filter, remove degree < 10
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
Expand Down
42 changes: 30 additions & 12 deletions src/main/java/org/gephi/toolkit/demos/GenerateGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ License, or (at your option) any later version.
import org.gephi.io.generator.plugin.DynamicGraph;
import org.gephi.io.generator.plugin.RandomGraph;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ContainerUnloader;
import org.gephi.io.importer.api.ColumnDraft;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.AppendProcessor;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.graph.api.Configuration;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.TimeRepresentation;
import org.gephi.graph.api.types.IntervalDoubleMap;
import org.gephi.graph.api.types.TimestampDoubleMap;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;
Expand All @@ -50,39 +57,50 @@ License, or (at your option) any later version.
public class GenerateGraph {

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Generate a new random graph into a container
Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
RandomGraph randomGraph = new RandomGraph();
randomGraph.setNumberOfNodes(500);
randomGraph.setWiringProbability(0.005);
randomGraph.generate(container.getLoader());

//Append container to graph structure
//Create a correctly configured project/workspace and process the graph
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
importController.process(container, new DefaultProcessor(), workspace);
Workspace workspace = importController.process(container);

//Generate another graph and append it to the current workspace
Container container2 = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
RandomGraph randomGraph2 = new RandomGraph();
randomGraph2.setNumberOfNodes(100);
randomGraph2.setWiringProbability(0.01);
randomGraph2.generate(container.getLoader());
randomGraph2.generate(container2.getLoader());
Comment thread
sim51 marked this conversation as resolved.
importController.process(container2, new AppendProcessor(), workspace); //Use AppendProcessor to append to current workspace

//Create new workspace
Workspace workspace2 = pc.newWorkspace(pc.getCurrentProject());
pc.openWorkspace(workspace2); //Set as current workspace

//Generate dynamic graph into workspace 2
Container container3 = Lookup.getDefault().lookup(Container.Factory.class).newContainer();

DynamicGraph dynamicGraph = new DynamicGraph();
dynamicGraph.generate(container3.getLoader());

//Create the second workspace with its immutable temporal configuration
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
ContainerUnloader unloader = container3.getUnloader();
Class<?> elementIdType = unloader.getElementIdType().getTypeClass();
Configuration.Builder configurationBuilder = graphController.getDefaultConfigurationBuilder()
.timeRepresentation(unloader.getTimeRepresentation())
.nodeIdType(elementIdType)
.edgeIdType(elementIdType);
if (unloader.getEdgeTypeLabelClass() != null) {
configurationBuilder.edgeLabelType(unloader.getEdgeTypeLabelClass());
}
ColumnDraft weightColumn = unloader.getEdgeColumn("weight");
if (weightColumn != null && weightColumn.isDynamic()) {
configurationBuilder.edgeWeightType(unloader.getTimeRepresentation() == TimeRepresentation.INTERVAL
? IntervalDoubleMap.class : TimestampDoubleMap.class);
}
Configuration configuration = configurationBuilder.build();
Workspace workspace2 = pc.openNewWorkspace(configuration);
importController.process(container3, new DefaultProcessor(), workspace2);
}
}
27 changes: 11 additions & 16 deletions src/main/java/org/gephi/toolkit/demos/HeadlessSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ License, or (at your option) any later version.
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.EdgeDirectionDefault;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.layout.plugin.force.StepDisplacement;
import org.gephi.layout.plugin.force.yifanHu.YifanHuLayout;
import org.gephi.preview.api.PreviewModel;
import org.gephi.preview.api.PreviewProperty;
import org.gephi.preview.types.EdgeColor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.gephi.statistics.plugin.GraphDistance;
import org.openide.util.Lookup;
Expand All @@ -75,18 +73,8 @@ License, or (at your option) any later version.
public class HeadlessSimple {

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Get models and controllers for this new workspace - will be useful later
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
PreviewModel model = DemoPreview.configureStraightEdges();
//Get controllers
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
AppearanceController appearanceController = Lookup.getDefault().lookup(AppearanceController.class);
AppearanceModel appearanceModel = appearanceController.getModel();

//Import file
Container container;
Expand All @@ -99,8 +87,15 @@ public void script() {
return;
}

//Append imported data to GraphAPI
importController.process(container, new DefaultProcessor(), workspace);
//Create a correctly configured project/workspace and process the import
Workspace workspace = importController.process(container);

//Get models and controllers for the new workspace
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
PreviewModel model = DemoPreview.configureStraightEdges();
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
AppearanceController appearanceController = Lookup.getDefault().lookup(AppearanceController.class);
AppearanceModel appearanceModel = appearanceController.getModel(workspace);

//See if graph is well imported
DirectedGraph graph = graphModel.getDirectedGraph();
Expand Down Expand Up @@ -156,7 +151,7 @@ public void script() {
//Preview
model.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS, Boolean.TRUE);
model.getProperties().putValue(PreviewProperty.EDGE_COLOR, new EdgeColor(Color.GRAY));
model.getProperties().putValue(PreviewProperty.EDGE_THICKNESS, new Float(0.1f));
model.getProperties().putValue(PreviewProperty.EDGE_THICKNESS, 0.1f);
model.getProperties().putValue(PreviewProperty.NODE_LABEL_FONT, model.getProperties().getFontValue(PreviewProperty.NODE_LABEL_FONT).deriveFont(8));

//Export
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/org/gephi/toolkit/demos/ImportDynamic.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ License, or (at your option) any later version.
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.MergeProcessor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;

Expand Down Expand Up @@ -80,11 +79,6 @@ License, or (at your option) any later version.
public class ImportDynamic {

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Import first file
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
Container[] containers = new Container[3];
Expand All @@ -98,11 +92,11 @@ public void script() {
return;
}

//Process the container using the MergeProcessor
importController.process(containers, new MergeProcessor(), workspace);
//Let the processor create a correctly configured project/workspace
Workspace workspace = importController.process(containers, new MergeProcessor(), null)[0];

//Get the price attribute
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
Graph graph = graphModel.getGraph();
for (Node n : graph.getNodes()) {
TimestampIntegerMap value = (TimestampIntegerMap) n.getAttribute("price");
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/org/gephi/toolkit/demos/ImportExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ License, or (at your option) any later version.
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.EdgeDirectionDefault;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;

Expand All @@ -55,12 +53,7 @@ License, or (at your option) any later version.
public class ImportExport {

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Get controllers and models
//Get controllers
ImportController importController = Lookup.getDefault().lookup(ImportController.class);

//Import file
Expand All @@ -75,8 +68,8 @@ public void script() {
return;
}

//Append imported data to GraphAPI
importController.process(container, new DefaultProcessor(), workspace);
//Create a correctly configured project/workspace and process the import
Workspace workspace = importController.process(container);

//Export full graph
ExportController ec = Lookup.getDefault().lookup(ExportController.class);
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/org/gephi/toolkit/demos/ManipulateAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ License, or (at your option) any later version.
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.EdgeDirectionDefault;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;

Expand All @@ -48,12 +46,7 @@ public class ManipulateAttributes {
private static final int MAX_PRINTED_VALUES = 5;

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Get controllers and models
//Get controllers
ImportController importController = Lookup.getDefault().lookup(ImportController.class);

//Import file
Expand All @@ -68,11 +61,11 @@ public void script() {
return;
}

//Append imported data to GraphAPI
importController.process(container, new DefaultProcessor(), workspace);
//Create a correctly configured project/workspace and process the import
Workspace workspace = importController.process(container);

//List node columns
GraphModel model = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
GraphModel model = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
for (Column col : model.getNodeTable()) {
System.out.println(col);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/gephi/toolkit/demos/ManualGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ License, or (at your option) any later version.
public class ManualGraph {

public void script() {
//Init a project - and therefore a workspace
//Create an empty workspace with its immutable graph configuration
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();
Workspace workspace = pc.openNewWorkspace(Configuration.builder().build());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On others demo you do final Workspace workspace1 = importController.process(container);.
Is there a reason of this change ?


//Get a graph model - it exists because we have a workspace
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/gephi/toolkit/demos/ParallelWorkspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ License, or (at your option) any later version.
import org.gephi.io.generator.plugin.RandomGraph;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.layout.plugin.AutoLayout;
import org.gephi.layout.plugin.force.StepDisplacement;
import org.gephi.layout.plugin.force.yifanHu.YifanHuLayout;
Expand Down Expand Up @@ -60,10 +59,7 @@ License, or (at your option) any later version.
public class ParallelWorkspace {

public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
final Workspace workspace1 = pc.getCurrentWorkspace();

//Generate a new random graph into a container
Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
Expand All @@ -72,9 +68,9 @@ public void script() {
randomGraph.setWiringProbability(0.005);
randomGraph.generate(container.getLoader());

//Append container to graph structure
//Create a correctly configured project/workspace and process the graph
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
importController.process(container, new DefaultProcessor(), workspace1);
final Workspace workspace1 = importController.process(container);

//Duplicate this workspace
final Workspace workspace2 = pc.duplicateWorkspace(workspace1);
Expand Down
Loading