Package org.gephi.graph.api

Examples of org.gephi.graph.api.GraphView


        private boolean self = true;
        private int depth = 1;

        public Graph filter(Graph graph) {

            GraphView graphView = graph.getView();
            HierarchicalGraph mainGraph = graphView.getGraphModel().getHierarchicalGraph();

            List<Node> nodes = new ArrayList<Node>();
            for (Node n : graph.getNodes()) {
                nodes.add(n.getNodeData().getNode(mainGraph.getView().getViewId()));
            }

            Set<Node> result = new HashSet<Node>();

            Set<Node> neighbours = new HashSet<Node>();
            neighbours.addAll(nodes);

            //Put all neighbors into result
            for (int i = 0; i < depth; i++) {
                Node[] nei = neighbours.toArray(new Node[0]);
                neighbours.clear();
                for (Node n : nei) {
                    //Extract all neighbors of n
                    for (Node neighbor : mainGraph.getNeighbors(n)) {
                        if (!result.contains(neighbor)) {
                            neighbours.add(neighbor);
                            result.add(neighbor);
                        }
                    }
                }
                if (neighbours.isEmpty()) {
                    break;
                }
            }

            if (self) {
                result.addAll(nodes);
            } else {
                result.removeAll(nodes);
            }

            //Update nodes
            for (Node node : mainGraph.getNodes().toArray()) {
                if (result.contains(node)) {
                    graph.addNode(node);
                } else if(graph.contains(node)) {
                    graph.removeNode(node);
                }
            }

            //Update edges
            for (Node n : graph.getNodes().toArray()) {
                Node mainNode = n.getNodeData().getNode(mainGraph.getView().getViewId());
                Edge[] edges = mainGraph.getEdges(mainNode).toArray();
                for (Edge e : edges) {
                    if (e.getSource().getNodeData().getNode(graphView.getViewId()) != null
                            && e.getTarget().getNodeData().getNode(graphView.getViewId()) != null) {
                        graph.addEdge(e);
                    }
                }
            }
View Full Code Here


            if (graphs.length > 1) {
                throw new IllegalArgumentException("Not Filter accepts a single graph in parameter");
            }

            HierarchicalGraph hgraph = (HierarchicalGraph) graphs[0];
            GraphView hgraphView = hgraph.getView();
            HierarchicalGraph mainHGraph = hgraph.getView().getGraphModel().getHierarchicalGraph();
            for (Edge e : mainHGraph.getEdges().toArray()) {
                Node source = e.getSource().getNodeData().getNode(hgraphView.getViewId());
                Node target = e.getTarget().getNodeData().getNode(hgraphView.getViewId());
                if (source != null && target != null) {
                    Edge edgeInGraph = hgraph.getEdge(source, target);
                    if (edgeInGraph == null) {
                        //The edge is not in graph
                        hgraph.addEdge(e);
View Full Code Here

        public Graph filter(Graph[] graphs) {
            if (graphs.length > 1) {
                throw new IllegalArgumentException("Not Filter accepts a single graph in parameter");
            }
            HierarchicalGraph hgraph = (HierarchicalGraph) graphs[0];
            GraphView hgraphView = hgraph.getView();
            HierarchicalGraph mainHGraph = hgraph.getView().getGraphModel().getHierarchicalGraph();
            for (Node n : mainHGraph.getNodes().toArray()) {
                if (n.getNodeData().getNode(hgraphView.getViewId()) == null) {
                    //The node n is not in graph
                    hgraph.addNode(n);
                } else {
                    //The node n is in graph
                    hgraph.removeNode(n);
                }
            }

            for (Node n : hgraph.getNodes().toArray()) {
                Node mainNode = n.getNodeData().getNode(mainHGraph.getView().getViewId());
                Edge[] edges = mainHGraph.getEdgesAndMetaEdges(mainNode).toArray();
                for (Edge e : edges) {
                    if (e.getSource().getNodeData().getNode(hgraphView.getViewId()) != null
                            && e.getTarget().getNodeData().getNode(hgraphView.getViewId()) != null) {
                        hgraph.addEdge(e);
                    }
                }
            }
View Full Code Here

            if (graphs.length > 1) {
                throw new IllegalArgumentException("Filter accepts a single graph in parameter");
            }

            HierarchicalGraph hgraph = (HierarchicalGraph) graphs[0];
            GraphView hgraphView = hgraph.getView();
            HierarchicalGraph mainHGraph = hgraph.getView().getGraphModel().getHierarchicalGraph();

            List<Edge> edgesToKeep = new ArrayList<Edge>();
            for (Edge e : mainHGraph.getEdges().toArray()) {
                Node source = e.getSource().getNodeData().getNode(hgraphView.getViewId());
                Node target = e.getTarget().getNodeData().getNode(hgraphView.getViewId());
                boolean keep = false;
                switch (option) {
                    case SOURCE:
                        keep = source != null;
                        break;
                    case TARGET:
                        keep = target != null;
                        break;
                    case BOTH:
                        keep = source != null && target != null;
                        break;
                    case ANY:
                        keep = source != null || target != null;
                        break;
                }
                if (keep) {
                    edgesToKeep.add(e);
                }
            }

            hgraph.clearEdges();

            for (Node n : mainHGraph.getNodes().toArray()) {
                if (n.getNodeData().getNode(hgraphView.getViewId()) == null) {
                    hgraph.addNode(n);
                }
            }

            for (Edge e : edgesToKeep) {
View Full Code Here

                throw new IllegalArgumentException("Filter accepts a single filter in parameter");
            }
            HierarchicalGraph hgraph = (HierarchicalGraph) graph;
            if (filters[0] instanceof NodeFilter && ((NodeFilter) filters[0]).init(hgraph)) {
                NodeFilter filter = (NodeFilter) filters[0];
                GraphView hgraphView = hgraph.getView();
                for (Edge e : hgraph.getEdges().toArray()) {
                    Node source = e.getSource().getNodeData().getNode(hgraphView.getViewId());
                    Node target = e.getTarget().getNodeData().getNode(hgraphView.getViewId());
                    boolean remove = false;
                    switch (option) {
                        case SOURCE:
                            remove = !filter.evaluate(hgraph, source);
                            break;
View Full Code Here

            double high = low + window;

//            Graph g = dynamicGraph.getSnapshotGraph(low, high);
           
           
            GraphView currentView = graphModel.getVisibleView();
            Graph graph = graphModel.getGraphVisible();
            GraphView view = graphModel.createView();
            Graph g = graphModel.getGraph(view);
           
            TimestampIndex<Node> nodeIndex = graphModel.getNodeTimestampIndex(currentView);
            for(Node node : nodeIndex.get(low, high)) {
                g.addNode(node);
View Full Code Here

TOP

Related Classes of org.gephi.graph.api.GraphView

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.