use of org.gephi.graph.api.Graph in project gephi by gephi.
the class StatisticsControllerImpl method executeDynamic.
private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel();
double window = statistics.getWindow();
double tick = statistics.getTick();
GraphView currentView = graphModel.getVisibleView();
Interval bounds = statistics.getBounds();
if (bounds == null) {
if (currentView.isMainView()) {
bounds = graphModel.getTimeBounds();
} else {
bounds = currentView.getTimeInterval();
}
statistics.setBounds(bounds);
}
if (dynamicLongTask != null) {
//Count
int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick);
dynamicLongTask.start(c);
}
//Init
statistics.execute(graphModel);
//Loop
for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) {
double high = low + window;
Graph graph = graphModel.getGraphVisible();
graph.writeLock();
try {
GraphView view = graphModel.createView();
Subgraph g = graphModel.getGraph(view);
TimeIndex<Node> nodeIndex = graphModel.getNodeTimeIndex(currentView);
if (Double.isInfinite(nodeIndex.getMinTimestamp()) && Double.isInfinite(nodeIndex.getMaxTimestamp())) {
for (Node node : graph.getNodes()) {
g.addNode(node);
}
} else {
for (Node node : nodeIndex.get(new Interval(low, high))) {
g.addNode(node);
}
}
TimeIndex<Edge> edgeIndex = graphModel.getEdgeTimeIndex(currentView);
if (Double.isInfinite(edgeIndex.getMinTimestamp()) && Double.isInfinite(edgeIndex.getMaxTimestamp())) {
for (Edge edge : graph.getEdges()) {
if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
g.addEdge(edge);
}
}
} else {
for (Edge edge : edgeIndex.get(new Interval(low, high))) {
if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
g.addEdge(edge);
}
}
}
statistics.loop(g.getView(), new Interval(low, high));
} finally {
graph.writeUnlock();
}
//Cancelled?
if (dynamicLongTask != null && dynamicLongTask.isCancelled()) {
return;
} else if (dynamicLongTask != null) {
dynamicLongTask.progress();
}
}
statistics.end();
model.addReport(statistics);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class ClusteringCoefficient method execute.
@Override
public void execute(GraphModel graphModel) {
isDirected = graphModel.isDirected();
Graph graph = null;
if (isDirected) {
graph = graphModel.getDirectedGraphVisible();
} else {
graph = graphModel.getUndirectedGraphVisible();
}
execute(graph);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class DataTableTopComponent method initNodesView.
private void initNodesView() {
Runnable initNodesRunnable = new Runnable() {
@Override
public void run() {
try {
if (dataTablesModel == null) {
return;
}
String busyMsg = NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.tableScrollPane.busyMessage");
BusyUtils.BusyLabel busylabel = BusyUtils.createCenteredBusyLabel(tableScrollPane, busyMsg, nodeTable.getTable());
busylabel.setBusy(true);
//Attributes columns
nodeAvailableColumnsModel.syncronizeTableColumns();
final Column[] cols = nodeAvailableColumnsModel.getAvailableColumns();
refreshAvailableColumnsButton(nodeAvailableColumnsModel, Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable());
//Nodes from graph
Graph graph;
if (visibleOnly) {
graph = graphModel.getGraphVisible();
} else {
graph = graphModel.getGraph();
}
if (graph == null) {
tableScrollPane.setViewportView(null);
return;
}
//Model
nodeTable.refreshModel(graph.getNodes().toArray(), cols, graphModel, dataTablesModel);
busylabel.setBusy(false);
nodeTable.scrollToFirstElementSelected();
} catch (Exception e) {
Exceptions.printStackTrace(e);
JLabel errorLabel = new JLabel(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.tableScrollPane.error"), SwingConstants.CENTER);
tableScrollPane.setViewportView(errorLabel);
}
}
};
SwingUtilities.invokeLater(initNodesRunnable);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class DataTableTopComponent method exportTableAsCSV.
/**
* <p>Exports a AttributeTable to a CSV file showing first a dialog to select the
* file to write.</p>
*
* @param parent Parent window
* @param visibleOnly Show only visible graph
* @param table Table to export
* @param separator Separator to use for separating values of a row in the
* CSV file. If null ',' will be used.
* @param charset Charset encoding for the file
* @param columnsToExport Indicates the indexes of the columns to export.
* All columns will be exported if null
*/
public static void exportTableAsCSV(JComponent parent, boolean visibleOnly, Table table, boolean edgesTable, Character separator, Charset charset, Integer[] columnsToExport, String fileName) {
//Validate that at least 1 column is selected:
if (columnsToExport.length < 1) {
return;
}
String lastPath = NbPreferences.forModule(JTableCSVExporter.class).get(LAST_PATH, null);
final JFileChooser chooser = new JFileChooser(lastPath);
chooser.setAcceptAllFileFilterUsed(false);
DialogFileFilter dialogFileFilter = new DialogFileFilter(NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.filechooser.csvDescription"));
dialogFileFilter.addExtension("csv");
chooser.addChoosableFileFilter(dialogFileFilter);
File selectedFile = new File(chooser.getCurrentDirectory(), fileName);
chooser.setSelectedFile(selectedFile);
int returnFile = chooser.showSaveDialog(null);
if (returnFile != JFileChooser.APPROVE_OPTION) {
return;
}
File file = chooser.getSelectedFile();
if (!file.getPath().endsWith(".csv")) {
file = new File(file.getPath() + ".csv");
}
//Save last path
String defaultDirectory = file.getParentFile().getAbsolutePath();
NbPreferences.forModule(JTableCSVExporter.class).put(LAST_PATH, defaultDirectory);
try {
Element[] rows;
Graph graph;
if (visibleOnly) {
graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraphVisible();
} else {
graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
}
if (edgesTable) {
rows = graph.getEdges().toArray();
} else {
rows = graph.getNodes().toArray();
}
AttributeTableCSVExporter.writeCSVFile(graph, table, file, separator, charset, columnsToExport, rows);
JOptionPane.showMessageDialog(parent, NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.dialog.success"));
} catch (Exception ex) {
Logger.getLogger("").log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(parent, NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.dialog.error"), NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.dialog.error.title"), JOptionPane.ERROR_MESSAGE);
}
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class GraphElementsControllerImpl method duplicateNode.
@Override
public Node duplicateNode(Node node) {
Graph g = getCurrentGraph();
Node copy = copyNode(node, g);
return copy;
}
Aggregations