use of org.gephi.graph.api.Graph in project gephi-plugins-bootcamp by gephi.
the class GridLayout method goAlgo.
@Override
public void goAlgo() {
Graph graph = graphModel.getGraphVisible();
graph.readLock();
int nodeCount = graph.getNodeCount();
Node[] nodes = graph.getNodes().toArray();
int rows = (int) Math.round(Math.sqrt(nodeCount)) + 1;
int cols = (int) Math.round(Math.sqrt(nodeCount)) + 1;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols && (i * rows + j) < nodes.length; j++) {
Node node = nodes[i * rows + j];
float x = (-areaSize / 2f) + ((float) j / cols) * areaSize;
float y = (areaSize / 2f) - ((float) i / rows) * areaSize;
float px = node.x();
float py = node.y();
node.setX(px + (x - px) * (speed / 10000f));
node.setY(py + (y - py) * (speed / 10000f));
}
}
graph.readUnlock();
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class DefaultProcessor method process.
protected void process(ContainerUnloader container, Workspace workspace) {
//Architecture
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
graphModel = graphController.getGraphModel(workspace);
//Get graph
Graph graph = graphModel.getGraph();
GraphFactory factory = graphModel.factory();
//Time Format & Time zone
graphModel.setTimeFormat(container.getTimeFormat());
graphModel.setTimeZone(container.getTimeZone());
//Progress
Progress.start(progressTicket, container.getNodeCount() + container.getEdgeCount());
//Attributes - Creates columns for properties
flushColumns(container);
//Counters
int addedNodes = 0, addedEdges = 0;
//Create all nodes
ElementIdType elementIdType = container.getElementIdType();
for (NodeDraft draftNode : container.getNodes()) {
String idString = draftNode.getId();
Object id = toElementId(elementIdType, idString);
Node node = graph.getNode(id);
boolean newNode = false;
if (node == null) {
node = factory.newNode(id);
addedNodes++;
newNode = true;
}
flushToNode(draftNode, node);
if (newNode) {
graph.addNode(node);
}
Progress.progress(progressTicket);
}
//Create all edges and push to data structure
for (EdgeDraft draftEdge : container.getEdges()) {
String idString = draftEdge.getId();
Object id = toElementId(elementIdType, idString);
String sourceId = draftEdge.getSource().getId();
String targetId = draftEdge.getTarget().getId();
Node source = graph.getNode(toElementId(elementIdType, sourceId));
Node target = graph.getNode(toElementId(elementIdType, targetId));
Object type = draftEdge.getType();
int edgeType = graphModel.addEdgeType(type);
Edge edge = graph.getEdge(source, target, edgeType);
boolean newEdge = false;
if (edge == null) {
switch(container.getEdgeDefault()) {
case DIRECTED:
edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), true);
break;
case UNDIRECTED:
edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), false);
break;
case MIXED:
boolean directed = draftEdge.getDirection() == null || !draftEdge.getDirection().equals(EdgeDirection.UNDIRECTED);
edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), directed);
break;
}
addedEdges++;
newEdge = true;
}
flushToEdge(draftEdge, edge);
if (newEdge) {
graph.addEdge(edge);
}
Progress.progress(progressTicket);
}
//Report
int touchedNodes = container.getNodeCount();
int touchedEdges = container.getEdgeCount();
if (touchedNodes != addedNodes || touchedEdges != addedEdges) {
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0} ({1} added)", new Object[] { touchedNodes, addedNodes });
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0} ({1} added)", new Object[] { touchedEdges, addedEdges });
} else {
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0}", new Object[] { touchedNodes });
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0}", new Object[] { touchedEdges });
}
Progress.finish(progressTicket);
}
use of org.gephi.graph.api.Graph in project gephi-plugins-bootcamp by gephi.
the class CountSelfLoop method execute.
@Override
public void execute(GraphModel graphModel) {
Graph graph = graphModel.getGraphVisible();
selfLoopCount = 0;
totalEdgeCount = graph.getEdgeCount();
for (Edge e : graph.getEdges()) {
if (e.isSelfLoop()) {
selfLoopCount++;
}
}
}
use of org.gephi.graph.api.Graph in project gephi-plugins-bootcamp by gephi.
the class FindTool method select.
@Override
public void select() {
//Get current visible graph
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
Graph graph = graphController.getGraphModel().getGraphVisible();
//Build the autocomplete data. A simple map from node's label
graph.readLock();
data = new HashMap<String, Node>();
for (Node n : graph.getNodes()) {
String label = n.getLabel();
String id = n.getId().toString();
if (label != null) {
if (!label.isEmpty()) {
data.put(label, n);
}
} else if (id != null && !id.isEmpty()) {
data.put(id, n);
}
}
graph.readUnlock();
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class ImportCSVUIWizardAction method performAction.
@Override
public void performAction() {
wizardDescriptor = new WizardDescriptor(getPanels());
step1.setWizardDescriptor(wizardDescriptor);
step2.setWizardDescriptor(wizardDescriptor);
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
wizardDescriptor.setTitle(getName());
Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
dialog.setVisible(true);
dialog.toFront();
boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
if (!cancelled) {
//General parameters:
File file = (File) wizardDescriptor.getProperty("file");
Character separator = (Character) wizardDescriptor.getProperty("separator");
Charset charset = (Charset) wizardDescriptor.getProperty("charset");
String[] columnNames = (String[]) wizardDescriptor.getProperty("columns-names");
Class[] columnTypes = (Class[]) wizardDescriptor.getProperty("columns-types");
//Nodes import parameters:
Boolean assignNewNodeIds = (Boolean) wizardDescriptor.getProperty("assign-new-node-ids");
//Edges import parameters:
Boolean createNewNodes = (Boolean) wizardDescriptor.getProperty("create-new-nodes");
Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
dtc.setAutoRefreshEnabled(false);
try {
switch((Mode) wizardDescriptor.getProperty("mode")) {
case NODES_TABLE:
ac.importCSVToNodesTable(graph, file, separator, charset, columnNames, columnTypes, assignNewNodeIds);
break;
case EDGES_TABLE:
ac.importCSVToEdgesTable(graph, file, separator, charset, columnNames, columnTypes, createNewNodes);
break;
}
dtc.refreshCurrentTable();
} catch (Exception e) {
Logger.getLogger("").log(Level.SEVERE, null, e);
} finally {
dtc.setAutoRefreshEnabled(true);
}
}
step1.unSetup();
step2.unSetup();
}
Aggregations