Search in sources :

Example 46 with Graph

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);
}
Also used : Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Subgraph(org.gephi.graph.api.Subgraph) GraphView(org.gephi.graph.api.GraphView) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Interval(org.gephi.graph.api.Interval)

Example 47 with Graph

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);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) Graph(org.gephi.graph.api.Graph)

Example 48 with 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);
}
Also used : BusyUtils(org.gephi.ui.components.BusyUtils) Graph(org.gephi.graph.api.Graph) Column(org.gephi.graph.api.Column) JLabel(javax.swing.JLabel) GraphController(org.gephi.graph.api.GraphController)

Example 49 with Graph

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);
    }
}
Also used : JTableCSVExporter(org.gephi.utils.JTableCSVExporter) Graph(org.gephi.graph.api.Graph) JFileChooser(javax.swing.JFileChooser) Element(org.gephi.graph.api.Element) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) File(java.io.File) GraphController(org.gephi.graph.api.GraphController)

Example 50 with Graph

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;
}
Also used : Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node)

Aggregations

Graph (org.gephi.graph.api.Graph)104 GraphModel (org.gephi.graph.api.GraphModel)57 Node (org.gephi.graph.api.Node)50 DirectedGraph (org.gephi.graph.api.DirectedGraph)43 Test (org.testng.annotations.Test)36 GraphController (org.gephi.graph.api.GraphController)27 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)24 Edge (org.gephi.graph.api.Edge)21 Column (org.gephi.graph.api.Column)9 ArrayList (java.util.ArrayList)8 Function (org.gephi.appearance.api.Function)6 GraphView (org.gephi.graph.api.GraphView)6 AttributeFunction (org.gephi.appearance.api.AttributeFunction)5 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 TransformerUI (org.gephi.appearance.spi.TransformerUI)3 GraphElementsController (org.gephi.datalab.api.GraphElementsController)3 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)3