Search in sources :

Example 6 with Graph

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

the class FilterModelPersistenceProvider method readXML.

public void readXML(XMLStreamReader reader, FilterModelImpl model) throws XMLStreamException {
    Map<Integer, Query> idMap = new HashMap<>();
    boolean end = false;
    while (reader.hasNext() && !end) {
        Integer eventType = reader.next();
        if (eventType.equals(XMLEvent.START_ELEMENT)) {
            String name = reader.getLocalName();
            if ("autorefresh".equalsIgnoreCase(name)) {
                String val = reader.getAttributeValue(null, "value");
                model.setAutoRefresh(Boolean.parseBoolean(val));
            } else if ("query".equalsIgnoreCase(name)) {
                String id = reader.getAttributeValue(null, "id");
                String parent = reader.getAttributeValue(null, "parent");
                Query query = readQuery(reader, model);
                if (query != null) {
                    idMap.put(Integer.parseInt(id), query);
                    if (parent != null) {
                        int parentId = Integer.parseInt(parent);
                        Query parentQuery = idMap.get(parentId);
                        //For example a partition filter, which depends on partitions, and partitions are not serialized
                        if (parentQuery != null) {
                            model.setSubQuery(parentQuery, query);
                        }
                    } else {
                        //Top query
                        model.addFirst(query);
                    }
                }
            } else if ("savedquery".equalsIgnoreCase(name)) {
                String id = reader.getAttributeValue(null, "id");
                String parent = reader.getAttributeValue(null, "parent");
                Query query = readQuery(reader, model);
                if (query != null) {
                    idMap.put(Integer.parseInt(id), query);
                    if (parent != null) {
                        int parentId = Integer.parseInt(parent);
                        Query parentQuery = idMap.get(parentId);
                        if (parentQuery != null) {
                            AbstractQueryImpl impl = (AbstractQueryImpl) parentQuery;
                            impl.addSubQuery(query);
                        }
                    } else {
                        model.getLibrary().saveQuery(query);
                    }
                }
            }
        } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
            if ("filtermodel".equalsIgnoreCase(reader.getLocalName())) {
                end = true;
            }
        }
    }
    //Init filters
    Graph graph;
    graph = model.getGraphModel().getGraph();
    for (Query rootQuery : model.getQueries()) {
        for (Query q : rootQuery.getDescendantsAndSelf()) {
            Filter filter = q.getFilter();
            if (filter instanceof NodeFilter || filter instanceof EdgeFilter || filter instanceof ElementFilter) {
                FilterProcessor filterProcessor = new FilterProcessor();
                filterProcessor.init(filter, graph);
            }
        }
    }
}
Also used : Query(org.gephi.filters.api.Query) HashMap(java.util.HashMap) Graph(org.gephi.graph.api.Graph)

Example 7 with Graph

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

the class InterEdgesBuilder method getBuilders.

@Override
public FilterBuilder[] getBuilders(Workspace workspace) {
    List<FilterBuilder> builders = new ArrayList<>();
    GraphModel gm = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
    Graph graph = gm.getGraph();
    AppearanceModel am = Lookup.getDefault().lookup(AppearanceController.class).getModel(workspace);
    //Force refresh
    am.getNodeFunctions(graph);
    for (Column nodeCol : gm.getNodeTable()) {
        if (!nodeCol.isProperty()) {
            if (am.getNodePartition(graph, nodeCol) != null) {
                InterEdgesFilterBuilder builder = new InterEdgesFilterBuilder(nodeCol, am);
                builders.add(builder);
            }
        }
    }
    return builders.toArray(new FilterBuilder[0]);
}
Also used : Graph(org.gephi.graph.api.Graph) AppearanceModel(org.gephi.appearance.api.AppearanceModel) Column(org.gephi.graph.api.Column) FilterBuilder(org.gephi.filters.spi.FilterBuilder) GraphModel(org.gephi.graph.api.GraphModel) ArrayList(java.util.ArrayList) AppearanceController(org.gephi.appearance.api.AppearanceController) GraphController(org.gephi.graph.api.GraphController)

Example 8 with Graph

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

the class PartitionCountBuilder method getBuilders.

@Override
public FilterBuilder[] getBuilders(Workspace workspace) {
    List<FilterBuilder> builders = new ArrayList<>();
    GraphModel gm = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
    Graph graph = gm.getGraph();
    AppearanceModel am = Lookup.getDefault().lookup(AppearanceController.class).getModel(workspace);
    //Force refresh
    am.getNodeFunctions(graph);
    for (Column nodeCol : gm.getNodeTable()) {
        if (!nodeCol.isProperty()) {
            if (am.getNodePartition(graph, nodeCol) != null) {
                PartitionCountFilterBuilder builder = new PartitionCountFilterBuilder(nodeCol, am);
                builders.add(builder);
            }
        }
    }
    for (Column edgeCol : gm.getEdgeTable()) {
        if (!edgeCol.isProperty()) {
            if (am.getEdgePartition(graph, edgeCol) != null) {
                PartitionCountFilterBuilder builder = new PartitionCountFilterBuilder(edgeCol, am);
                builders.add(builder);
            }
        }
    }
    return builders.toArray(new FilterBuilder[0]);
}
Also used : Graph(org.gephi.graph.api.Graph) AppearanceModel(org.gephi.appearance.api.AppearanceModel) Column(org.gephi.graph.api.Column) AbstractAttributeFilterBuilder(org.gephi.filters.plugin.AbstractAttributeFilterBuilder) GraphModel(org.gephi.graph.api.GraphModel) ArrayList(java.util.ArrayList) AppearanceController(org.gephi.appearance.api.AppearanceController) GraphController(org.gephi.graph.api.GraphController)

Example 9 with Graph

use of org.gephi.graph.api.Graph 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.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 10 with Graph

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

the class LegacyAttributeRowsPersistenceProvider method readRows.

public void readRows(XMLStreamReader reader, GraphModel graphModel, LegacyMapHelper mapHelper) throws XMLStreamException {
    Graph graph = graphModel.getGraph();
    boolean end = false;
    while (reader.hasNext() && !end) {
        int type = reader.next();
        switch(type) {
            case XMLStreamReader.START_ELEMENT:
                String name = reader.getLocalName();
                if (ELEMENT_NODE_ROW.equalsIgnoreCase(name)) {
                    String id = reader.getAttributeValue(null, "for");
                    Node node = graph.getNode(id);
                    readRow(reader, node, graphModel.getNodeTable(), mapHelper);
                } else if (ELEMENT_EDGE_ROW.equalsIgnoreCase(name)) {
                    String id = reader.getAttributeValue(null, "for");
                    Edge edge = graph.getEdge(id);
                    readRow(reader, edge, graphModel.getEdgeTable(), mapHelper);
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                if (ELEMENT_ROWS.equalsIgnoreCase(reader.getLocalName())) {
                    end = true;
                }
                break;
        }
    }
}
Also used : Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

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