Search in sources :

Example 1 with GraphView

use of org.gephi.graph.api.GraphView in project gephi by gephi.

the class DynamicSettingsPanel method setup.

public void setup(DynamicStatistics dynamicStatistics) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    TimeFormat timeFormat = graphModel.getTimeFormat();
    // Bounds
    GraphView currentView = graphModel.getVisibleView();
    if (currentView.isMainView()) {
        bounds = graphModel.getTimeBounds();
    } else {
        bounds = currentView.getTimeInterval();
    }
    String boundsStr = timeFormat.print(bounds.getLow()) + " - " + timeFormat.print(bounds.getHigh());
    currentIntervalLabel.setText(boundsStr);
    // TimeUnit
    if (timeFormat.equals(TimeFormat.DOUBLE)) {
        windowTimeUnitCombo.setVisible(false);
        tickTimeUnitCombo.setVisible(false);
    }
    // Set latest selected item
    if (!timeFormat.equals(TimeFormat.DOUBLE)) {
        loadDefaultTimeUnits();
    }
    // Window and tick
    double initValue = 0.;
    if (bounds.getHigh() - bounds.getLow() > 1) {
        initValue = 1.;
    }
    if (timeFormat.equals(TimeFormat.DOUBLE)) {
        windowTextField.setText(initValue + "");
        tickTextField.setText(initValue + "");
    } else {
        windowTextField.setText("" + windowTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
        tickTextField.setText("" + tickTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
    }
    // Add listeners
    windowTimeUnitCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getItem() != windowTimeUnitCombo.getSelectedItem()) {
                refreshWindowTimeUnit();
            }
        }
    });
    tickTimeUnitCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getItem() != tickTimeUnitCombo.getSelectedItem()) {
                refreshTickTimeUnit();
            }
        }
    });
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) ItemEvent(java.awt.event.ItemEvent) GraphModel(org.gephi.graph.api.GraphModel) ItemListener(java.awt.event.ItemListener) GraphView(org.gephi.graph.api.GraphView) GraphController(org.gephi.graph.api.GraphController)

Example 2 with GraphView

use of org.gephi.graph.api.GraphView in project gephi by gephi.

the class FilterControllerImpl method exportToLabelVisible.

@Override
public void exportToLabelVisible(Query query) {
    Graph result;
    if (model.getCurrentQuery() == query) {
        GraphView view = model.getCurrentResult();
        if (view == null) {
            return;
        }
        result = model.getGraphModel().getGraph(view);
    } else {
        FilterProcessor processor = new FilterProcessor();
        result = (Graph) processor.process((AbstractQueryImpl) query, model.getGraphModel());
    }
    Graph fullGraph = model.getGraphModel().getGraph();
    fullGraph.writeLock();
    try {
        for (Node n : fullGraph.getNodes()) {
            boolean inView = result.contains(n);
            n.getTextProperties().setVisible(inView);
        }
        for (Edge e : fullGraph.getEdges()) {
            boolean inView = result.contains(e);
            e.getTextProperties().setVisible(inView);
        }
    } finally {
        fullGraph.writeUnlock();
        fullGraph.readUnlockAll();
    }
}
Also used : Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node) GraphView(org.gephi.graph.api.GraphView) Edge(org.gephi.graph.api.Edge)

Example 3 with GraphView

use of org.gephi.graph.api.GraphView in project gephi by gephi.

the class FilterThread method select.

private void select(AbstractQueryImpl query) {
    FilterProcessor processor = new FilterProcessor();
    GraphModel graphModel = model.getGraphModel();
    Graph result = processor.process((AbstractQueryImpl) query, graphModel);
    if (running) {
        VisualizationController visController = Lookup.getDefault().lookup(VisualizationController.class);
        if (visController != null) {
            visController.resetSelection();
            visController.selectNodes(result.getNodes().toArray());
            visController.selectEdges(result.getEdges().toArray());
        }
        GraphView view = result.getView();
        model.setCurrentResult(view);
    } else {
        // destroy view
        graphModel.destroyView(result.getView());
    }
}
Also used : Graph(org.gephi.graph.api.Graph) VisualizationController(org.gephi.visualization.api.VisualizationController) GraphModel(org.gephi.graph.api.GraphModel) GraphView(org.gephi.graph.api.GraphView)

Example 4 with GraphView

use of org.gephi.graph.api.GraphView 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();
            graph.readUnlockAll();
        }
        // 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 5 with GraphView

use of org.gephi.graph.api.GraphView in project gephi by gephi.

the class FilterControllerImpl method exportToNewWorkspace.

@Override
public void exportToNewWorkspace(Query query) {
    Graph result;
    if (model.getCurrentQuery() == query) {
        GraphView view = model.getCurrentResult();
        if (view == null) {
            return;
        }
        result = model.getGraphModel().getGraph(view);
    } else {
        FilterProcessor processor = new FilterProcessor();
        GraphModel graphModel = model.getGraphModel();
        result = (Graph) processor.process((AbstractQueryImpl) query, graphModel);
    }
    final Graph graphView = result;
    new Thread(new Runnable() {

        @Override
        public void run() {
            ProgressTicketProvider progressProvider = Lookup.getDefault().lookup(ProgressTicketProvider.class);
            ProgressTicket ticket = null;
            if (progressProvider != null) {
                String msg = NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.task");
                ticket = progressProvider.createTicket(msg, null);
            }
            Progress.start(ticket);
            ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
            Workspace newWorkspace = pc.newWorkspace(pc.getCurrentProject());
            GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(newWorkspace);
            graphModel.bridge().copyNodes(graphView.getNodes().toArray());
            Graph graph = graphModel.getGraph();
            List<Edge> edgesToRemove = new ArrayList<>();
            for (Edge edge : graph.getEdges()) {
                if (!graphView.hasEdge(edge.getId())) {
                    edgesToRemove.add(edge);
                }
            }
            if (!edgesToRemove.isEmpty()) {
                graph.removeAllEdges(edgesToRemove);
            }
            Progress.finish(ticket);
            String workspaceName = newWorkspace.getLookup().lookup(WorkspaceInformation.class).getName();
        // StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.status", workspaceName));
        }
    }, "Export filter to workspace").start();
}
Also used : ArrayList(java.util.ArrayList) GraphView(org.gephi.graph.api.GraphView) ProjectController(org.gephi.project.api.ProjectController) WorkspaceInformation(org.gephi.project.api.WorkspaceInformation) ProgressTicketProvider(org.gephi.utils.progress.ProgressTicketProvider) Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Edge(org.gephi.graph.api.Edge) ProgressTicket(org.gephi.utils.progress.ProgressTicket) GraphController(org.gephi.graph.api.GraphController) Workspace(org.gephi.project.api.Workspace)

Aggregations

GraphView (org.gephi.graph.api.GraphView)8 Graph (org.gephi.graph.api.Graph)6 GraphModel (org.gephi.graph.api.GraphModel)6 Edge (org.gephi.graph.api.Edge)5 Node (org.gephi.graph.api.Node)4 GraphController (org.gephi.graph.api.GraphController)3 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 ArrayList (java.util.ArrayList)1 Column (org.gephi.graph.api.Column)1 Interval (org.gephi.graph.api.Interval)1 Subgraph (org.gephi.graph.api.Subgraph)1 TimeFormat (org.gephi.graph.api.TimeFormat)1 ProjectController (org.gephi.project.api.ProjectController)1 Workspace (org.gephi.project.api.Workspace)1 WorkspaceInformation (org.gephi.project.api.WorkspaceInformation)1 ProgressTicket (org.gephi.utils.progress.ProgressTicket)1 ProgressTicketProvider (org.gephi.utils.progress.ProgressTicketProvider)1 VisualizationController (org.gephi.visualization.api.VisualizationController)1 EdgeModel (org.gephi.visualization.model.edge.EdgeModel)1