Gephi Toolkit Javadoc

org.gephi.graph.api
Interface GraphModel


public interface GraphModel

Root interface that contains the complete graph structure and build Graph objets on demand.

The graph structure contains several views. GraphView are sub-graphs with a unique identifier, the viewId. The model maintains all views, and especially:

Different type of graph can be queried: directed, undirected, mixed and hierarchical. All types can be queried at any time, regardless how the structure is. Indeed even if only directed edges were appened to the graph, an undirected graph can be obtained.

It is preferable to use the main graph for performing updates (add, remove, ...).

Append data to an empty model

The following code shows how to add two nodes an an edge to graph.
 Graph graph = model.getGraph();
 Node n1 = model.factory().newNode();
 Node n2 = model.factory().newNode();
 Edge e1 = model.factory().newEdge(n1, n2);
 graph.addNode(n1);
 graph.addNode(n2);
 graph.addEdge(e1);
 

Set Visible view

The following code shows how to set the visible view. This is useful if you need to visualize a sub-graph.
 GraphView newView = model.newView();     //Duplicate main view
 Graph subGraph = model.getGraph(newView);
 //Filter subgraph by removing nodes and edges
 model.setVisibleView(newView);       //Set the view as current visible view
 
Note: Pay attention to destroy views when they are not used anymore.

Author:
Mathieu Bastian
See Also:
GraphController

Method Summary
 void addGraphListener(GraphListener graphListener)
          Add graphListener as a listener to this graph, if it is not already.
 void clear()
          Clears the model by deleting all views and reseting main view.
 GraphModel copy()
          Returns a complete copy of this model, including all views but not listeners.
 GraphView copyView(GraphView view)
          Copy view to a new graph view.
 void destroyView(GraphView view)
          Destroy view, if exists.
 GraphFactory factory()
          Returns the factory that creates nodes and edges for this model.
 DirectedGraph getDirectedGraph()
          Build a DirectedGraph to access the main view.
 DirectedGraph getDirectedGraph(GraphView view)
          Build a DirectedGraph to access view.
 DirectedGraph getDirectedGraphVisible()
          Build a DirectedGraph to access the visible view.
 Graph getGraph()
          Build a Graph to access the main view.
 Graph getGraph(GraphView view)
          Build a Graph to access view/code>.
 Graph getGraphVisible()
          Build a Graph to access the visible view.
 HierarchicalDirectedGraph getHierarchicalDirectedGraph()
          Build a HierarchicalDirectedGraph to access the main view.
 HierarchicalDirectedGraph getHierarchicalDirectedGraph(GraphView view)
          Build a HierarchicalDirectedGraph to access view.
 HierarchicalDirectedGraph getHierarchicalDirectedGraphVisible()
          Build a HierarchicalDirectedGraph to access the visible view.
 HierarchicalGraph getHierarchicalGraph()
          Build a HierarchicalGraph to access the main view.
 HierarchicalGraph getHierarchicalGraph(GraphView view)
          Build a HierarchicalGraph to access view.
 HierarchicalGraph getHierarchicalGraphVisible()
          Build a HierarchicalGraph to access the visible view.
 HierarchicalMixedGraph getHierarchicalMixedGraph()
          Build a HierarchicalMixedGraph to access the main view.
 HierarchicalMixedGraph getHierarchicalMixedGraph(GraphView view)
          Build a HierarchicalMixedGraph to access view.
 HierarchicalMixedGraph getHierarchicalMixedGraphVisible()
          Build a HierarchicalMixedGraph to access the visible view.
 HierarchicalUndirectedGraph getHierarchicalUndirectedGraph()
          Build a HierarchicalUndirectedGraph to access the main view.
 HierarchicalUndirectedGraph getHierarchicalUndirectedGraph(GraphView view)
          Build a HierarchicalUndirectedGraph to access view.
 HierarchicalUndirectedGraph getHierarchicalUndirectedGraphVisible()
          Build a HierarchicalUndirectedGraph to access the visible view.
 MixedGraph getMixedGraph()
          Build a MixedGraph to access the main view.
 MixedGraph getMixedGraph(GraphView view)
          Build a MixedGraph to access view.
 MixedGraph getMixedGraphVisible()
          Build a MixedGraph to access the visible view.
 UndirectedGraph getUndirectedGraph()
          Build a UndirectedGraph to access the main view.
 UndirectedGraph getUndirectedGraph(GraphView view)
          Build a UndirectedGraph to access view.
 UndirectedGraph getUndirectedGraphVisible()
          Build a UndirectedGraph to access the visible view.
 GraphView getVisibleView()
          Returns the current viisble view.
 Workspace getWorkspace()
          Returns the workspace this graph model belongs to.
 boolean isDirected()
          Returns true if the graph is directed by default.
 boolean isHierarchical()
          Returns true if the graph is hierarchical.
 boolean isMixed()
          Returns true if the graph is mixed by default.
 boolean isUndirected()
          Returns true if the graph is undirected by default.
 GraphView newView()
          Create a new view by duplicating main view.
 void pushFrom(Graph graph)
          Copy the graph structure from graph to this model.
 void pushNodes(Graph graph, Node[] nodes)
          Copy the nodes and edges betweeen these nodes from the graph to this model.
 void removeGraphListener(GraphListener graphListener)
          Remove graphListener as a listener to this graph.
 GraphSettings settings()
          Returns the model settings.
 void setVisibleView(GraphView view)
          Sets the current visible view and nofity listeners the visible view changed.
 

Method Detail

factory

GraphFactory factory()
Returns the factory that creates nodes and edges for this model.

Returns:
the graph model factory

settings

GraphSettings settings()
Returns the model settings.

Returns:
the graph model settings

newView

GraphView newView()
Create a new view by duplicating main view. The view contains all nodes and edges in the structure.

Returns:
a new graph view, obtained from duplicating main view

copyView

GraphView copyView(GraphView view)
Copy view to a new graph view. The new view contains all nodes and edges present in view.

Returns:
a new graph view, obtained from duplicating view

destroyView

void destroyView(GraphView view)
Destroy view, if exists. Always destroy views that are not needed anymore to avoid memory overhead.

Parameters:
view - the view that is to be destroyed

setVisibleView

void setVisibleView(GraphView view)
Sets the current visible view and nofity listeners the visible view changed.

Parameters:
view - the view that is to be set as the visible view

getVisibleView

GraphView getVisibleView()
Returns the current viisble view. By default, returns the main view.

Returns:
the current visible view

getGraph

Graph getGraph()
Build a Graph to access the main view. If no undirected edges have been added, returns a DirectedGraph. If the graph only contains undirected edges, returns a UndirectedGraph. If both directed and undirected edges exists, returns a MixedGraph.

Returns:
a graph object, directed by default

getDirectedGraph

DirectedGraph getDirectedGraph()
Build a DirectedGraph to access the main view.

Returns:
a directed graph object

getUndirectedGraph

UndirectedGraph getUndirectedGraph()
Build a UndirectedGraph to access the main view.

Returns:
an undirected graph object

getMixedGraph

MixedGraph getMixedGraph()
Build a MixedGraph to access the main view.

Returns:
a mixed graph object

getHierarchicalGraph

HierarchicalGraph getHierarchicalGraph()
Build a HierarchicalGraph to access the main view. If no undirected edges have been added, returns a HierarchicalDirectedGraph. If the graph only contains undirected edges, returns a HierarchicalUndirectedGraph. If both directed and undirected edges exists, returns a HierarchicalMixedGraph.

Hierarchical graphs are normal graphs with more features to handle graphs within graphs.

Returns:
a hierarchical graph object, directed by default

getHierarchicalDirectedGraph

HierarchicalDirectedGraph getHierarchicalDirectedGraph()
Build a HierarchicalDirectedGraph to access the main view.

Returns:
a hierarchical directed graph object

getHierarchicalUndirectedGraph

HierarchicalUndirectedGraph getHierarchicalUndirectedGraph()
Build a HierarchicalUndirectedGraph to access the main view.

Returns:
a hierarchical undirected graph object

getHierarchicalMixedGraph

HierarchicalMixedGraph getHierarchicalMixedGraph()
Build a HierarchicalMixedGraph to access the main view.

Returns:
a hierarchical mixed graph object

getGraphVisible

Graph getGraphVisible()
Build a Graph to access the visible view. If no undirected edges have been added, returns a DirectedGraph. If the graph only contains undirected edges, returns a UndirectedGraph. If both directed and undirected edges exists, returns a MixedGraph.

Returns:
a graph object, directed by default

getDirectedGraphVisible

DirectedGraph getDirectedGraphVisible()
Build a DirectedGraph to access the visible view.

Returns:
a directed graph object

getUndirectedGraphVisible

UndirectedGraph getUndirectedGraphVisible()
Build a UndirectedGraph to access the visible view.

Returns:
an undirected graph object

getMixedGraphVisible

MixedGraph getMixedGraphVisible()
Build a MixedGraph to access the visible view.

Returns:
a mixed graph object

getHierarchicalGraphVisible

HierarchicalGraph getHierarchicalGraphVisible()
Build a HierarchicalGraph to access the visible view. If no undirected edges have been added, returns a HierarchicalDirectedGraph. If the graph only contains undirected edges, returns a HierarchicalUndirectedGraph. If both directed and undirected edges exists, returns a HierarchicalMixedGraph.

Hierarchical graphs are normal graphs with more features to handle graphs within graphs.

Returns:
a hierarchical graph object, directed by default

getHierarchicalDirectedGraphVisible

HierarchicalDirectedGraph getHierarchicalDirectedGraphVisible()
Build a HierarchicalDirectedGraph to access the visible view.

Returns:
a hierarchical directed graph object

getHierarchicalUndirectedGraphVisible

HierarchicalUndirectedGraph getHierarchicalUndirectedGraphVisible()
Build a HierarchicalUndirectedGraph to access the visible view.

Returns:
a hierarchical undirected graph object

getHierarchicalMixedGraphVisible

HierarchicalMixedGraph getHierarchicalMixedGraphVisible()
Build a HierarchicalMixedGraph to access the visible view.

Returns:
a hierarchical mixed graph object

getGraph

Graph getGraph(GraphView view)
Build a Graph to access view/code>. If no undirected edges have been added, returns a DirectedGraph. If the graph only contains undirected edges, returns a UndirectedGraph. If both directed and undirected edges exists, returns a MixedGraph.

Returns:
a graph object on view, directed by default

getDirectedGraph

DirectedGraph getDirectedGraph(GraphView view)
Build a DirectedGraph to access view.

Returns:
a directed graph object on view

getUndirectedGraph

UndirectedGraph getUndirectedGraph(GraphView view)
Build a UndirectedGraph to access view.

Returns:
an undirected graph object on view

getMixedGraph

MixedGraph getMixedGraph(GraphView view)
Build a MixedGraph to access view.

Returns:
a mixed graph object on view

getHierarchicalGraph

HierarchicalGraph getHierarchicalGraph(GraphView view)
Build a HierarchicalGraph to access view. If no undirected edges have been added, returns a HierarchicalDirectedGraph. If the graph only contains undirected edges, returns a HierarchicalUndirectedGraph. If both directed and undirected edges exists, returns a HierarchicalMixedGraph.

Hierarchical graphs are normal graphs with more features to handle graphs within graphs.

Returns:
a hierarchical graph object on view, directed by default

getHierarchicalDirectedGraph

HierarchicalDirectedGraph getHierarchicalDirectedGraph(GraphView view)
Build a HierarchicalDirectedGraph to access view.

Returns:
a hierarchical directed graph object on view

getHierarchicalUndirectedGraph

HierarchicalUndirectedGraph getHierarchicalUndirectedGraph(GraphView view)
Build a HierarchicalUndirectedGraph to access view.

Returns:
a hierarchical undirected graph object on view

getHierarchicalMixedGraph

HierarchicalMixedGraph getHierarchicalMixedGraph(GraphView view)
Build a HierarchicalMixedGraph to access view.

Returns:
a hierarchical mixed graph object on view

pushFrom

void pushFrom(Graph graph)
Copy the graph structure from graph to this model. The given graphmust come from a different GraphModel, e.g. a different workspace.

Parameters:
graph - the graph that is to be copied in this model
Throws:
java.lang.IllegalArgumentException - if graph belongs to this graph model

pushNodes

void pushNodes(Graph graph,
               Node[] nodes)
Copy the nodes and edges betweeen these nodes from the graph to this model. The given graphmust come from a different GraphModel, e.g. a different workspace.

Parameters:
graph - the graph that is to be copied in this model
nodes - the nodes to copy
Throws:
java.lang.IllegalArgumentException - if graph belongs to this graph model

copy

GraphModel copy()
Returns a complete copy of this model, including all views but not listeners.

Returns:
a copy of this graph model

clear

void clear()
Clears the model by deleting all views and reseting main view. Calling this method immediately makes all Graph on other views than main obsolete.


addGraphListener

void addGraphListener(GraphListener graphListener)
Add graphListener as a listener to this graph, if it is not already. To pass a WeakReference, use Netbeans WeakListeners utility class.

Parameters:
graphListener - the listener to add

removeGraphListener

void removeGraphListener(GraphListener graphListener)
Remove graphListener as a listener to this graph.

Parameters:
graphListener - the listener to remove

isDirected

boolean isDirected()
Returns true if the graph is directed by default. This value is an indicator of the current state and it means that so far all edges are directed in the graph.

Returns:
true if the graph is only directed or false otherwise
See Also:
DirectedGraph

isUndirected

boolean isUndirected()
Returns true if the graph is undirected by default. This value is an indicator of the current state and it means that so far all edges are undirected in the graph.

Returns:
true if the graph is only undirected or false otherwise
See Also:
UndirectedGraph

isMixed

boolean isMixed()
Returns true if the graph is mixed by default. This value is an indicator of the current state and it means that directed and undirected edges has been added to the graph. When it returns true, isDirected() and isUndirected() methods always returns false.

Returns:
true if the graph is mixed or false otherwise
See Also:
MixedGraph

isHierarchical

boolean isHierarchical()
Returns true if the graph is hierarchical. This indicates the presence of a hierarchy, in other words the height of the tree is greater than 0.

Returns:
true if the graph is clustered or false otherwise
See Also:
HierarchicalGraph

getWorkspace

Workspace getWorkspace()
Returns the workspace this graph model belongs to.

Returns:
the workspace that owns this graph model

Gephi Toolkit Javadoc