Package org.gephi.graph.api

Examples of org.gephi.graph.api.Graph


        RankingResultImpl rankingResult = new RankingResultImpl();
        rankingResult.transformer = transformer;
        rankingResult.ranking = ranking;

        Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraphVisible();
        DynamicModel dynamicModel = rankingModelImpl.getDynamicModel();
        boolean refreshed = RankingFactory.refreshRanking((AbstractRanking) ranking, graph, dynamicModel != null ? dynamicModel.getVisibleInterval() : null);

        if (ranking instanceof NodeRanking) {
            ((AbstractRanking) ranking).setGraph(graph);
            for (Node node : graph.getNodes().toArray()) {
                Object rank = ranking.getValue(node);
                Object result = null;
                if (rank != null) {
                    float normalizedValue = ranking.normalize(rank);
                    if (transformer.isInBounds(normalizedValue)) {
                        result = transformer.transform(node, normalizedValue);
                    }
                }
                rankingResult.addResult(node, rank, result);
            }
        } else {
            ((AbstractRanking) ranking).setGraph(graph);
            for (Edge edge : graph.getEdges().toArray()) {
                Object rank = ranking.getValue(edge);
                Object result = null;
                if (rank != null) {
                    float normalizedValue = ranking.normalize(rank);
                    if (transformer.isInBounds(normalizedValue)) {
View Full Code Here


                } else {
                    q.setResult(input[0])//Put input as result, the filter don't do anything
                }
            }
        }
        Graph finalResult = tree[0].result;

        //Destroy intermediate views
        GraphView finalView = finalResult.getView();
        for (GraphView v : views) {
            if (v != finalView) {
                graphModel.destroyView(v);
            }
        }
View Full Code Here

                }
            }

            //Create nodes:
            GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
            Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
            String id = null;
            Node node;
            Attributes nodeAttributes;
            reader = new CsvReader(new FileInputStream(file), separator, charset);
            reader.readHeaders();
            while (reader.readRecord()) {
                //Prepare the correct node to assign the attributes:
                if (idColumn != null) {
                    id = reader.get(idColumn);
                    if (id == null || id.isEmpty()) {
                        node = gec.createNode(null);//id null or empty, assign one
                    } else {
                        graph.readLock();
                        node = graph.getNode(id);
                        graph.readUnlock();
                        if (node != null) {//Node with that id already in graph
                            if (assignNewNodeIds) {
                                node = gec.createNode(null);
                            }
                        } else {
View Full Code Here

                }
            }

            //Create edges:
            GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
            Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
            String id = null;
            Edge edge;
            String sourceId, targetId;
            Node source, target;
            String type;
            boolean directed;
            Attributes edgeAttributes;
            reader = new CsvReader(new FileInputStream(file), separator, charset);
            reader.readHeaders();
            while (reader.readRecord()) {
                sourceId = reader.get(sourceColumn);
                targetId = reader.get(targetColumn);

                if (sourceId == null || sourceId.isEmpty() || targetId == null || targetId.isEmpty()) {
                    continue;//No correct source and target ids were provided, ignore row
                }

                graph.readLock();
                source = graph.getNode(sourceId);
                graph.readUnlock();

                if (source == null) {
                    if (createNewNodes) {//Create new nodes when they don't exist already and option is enabled
                        if (source == null) {
                            source = gec.createNode(null, sourceId);
                        }
                    } else {
                        continue;//Ignore this edge row, since no new nodes should be created.
                    }
                }

                graph.readLock();
                target = graph.getNode(targetId);
                graph.readUnlock();

                if (target == null) {
                    if (createNewNodes) {//Create new nodes when they don't exist already and option is enabled
                        if (target == null) {
                            target = gec.createNode(null, targetId);
View Full Code Here

            public void mouseClick(int[] positionViewport, float[] position3d) {
                color = nodePencilPanel.getColor();
                size = nodePencilPanel.getNodeSize();
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                Graph graph = gc.getModel().getGraph();
                Node node = gc.getModel().factory().newNode();
                node.getNodeData().setX(position3d[0]);
                node.getNodeData().setY(position3d[1]);
                node.getNodeData().setSize(size);
                node.getNodeData().setR(color.getRed() / 255f);
                node.getNodeData().setG(color.getGreen() / 255f);
                node.getNodeData().setB(color.getBlue() / 255f);
                graph.addNode(node);
            }
        };
        return listeners;
    }
View Full Code Here

    }

    private void filter(AbstractQueryImpl query) {
        FilterProcessor processor = new FilterProcessor();
        GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
        Graph result = processor.process((AbstractQueryImpl) query, graphModel);
//        System.out.println("#Nodes: " + result.getNodeCount());
//        System.out.println("#Edges: " + result.getEdgeCount());
        if (running) {
            GraphView view = result.getView();
            graphModel.setVisibleView(view);
            if (model.getCurrentResult() != null) {
                graphModel.destroyView(model.getCurrentResult());
            }
            model.setCurrentResult(view);
        } else {
            //destroy view
            graphModel.destroyView(result.getView());
        }
    }
View Full Code Here

        Progress.setDisplayName(progressTicket, "MCL Clustering");

        HashMap<Integer, Node> nodeMap = new HashMap<Integer, Node>();
        HashMap<Node, Integer> intMap = new HashMap<Node, Integer>();

        Graph graph = graphModel.getGraphVisible();
        graph.readLock();

        //Load matrix
        SparseMatrix matrix = new SparseMatrix();
        int nodeId = 0;
        for (Edge e : graph.getEdges()) {
            Node source = e.getSource();
            Node target = e.getTarget();
            Integer sourceId;
            Integer targetId;
            if ((sourceId = intMap.get(source)) == null) {
                sourceId = nodeId++;
                intMap.put(source, sourceId);
                nodeMap.put(sourceId, source);
            }
            if ((targetId = intMap.get(target)) == null) {
                targetId = nodeId++;
                intMap.put(target, targetId);
                nodeMap.put(targetId, target);
            }
            double weight = e.getWeight();
            matrix.add(sourceId, targetId, weight);

            if (cancelled) {
                graph.readUnlockAll();
                return;
            }
        }

        graph.readUnlock();

        matrix = matrix.transpose();
        matrix = run(matrix, maxResidual, gammaExp, loopGain, zeroMax);

        if (cancelled) {
View Full Code Here

        if (filter instanceof Operator) {
            return new OperatorQueryImpl((Operator) filter);
        }
        //Init filter
        if (filter instanceof NodeFilter || filter instanceof EdgeFilter) {
            Graph graph = null;
            if (model != null && model.getGraphModel() != null) {
                graph = model.getGraphModel().getGraph();
            } else {
                GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
                graph = graphModel.getGraph();
View Full Code Here

    }

    public GraphView filter(Query query) {
        FilterProcessor processor = new FilterProcessor();
        GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
        Graph result = processor.process((AbstractQueryImpl) query, graphModel);
        return result.getView();
    }
View Full Code Here

            if (graphModel != null) {
                graph = graphModel.getHierarchicalGraphVisible();
            }
        }
        //Refresh reader if sight changed
        Graph g = graph;
        if (g != null) {
            if (g.getGraphModel().getVisibleView().getViewId() != graphView) {
                reset();
            }
            return g.getNodeVersion() > nodeVersion || g.getEdgeVersion() > edgeVersion;
        }
        return false;
    }
View Full Code Here

TOP

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

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.