Package org.gephi.graph.api

Examples of org.gephi.graph.api.Edge


        graphGlobal2Directed.expand(parent0);
        assertEquals(4, graphGlobal2Directed.getMetaEdges().toArray().length);
        assertEquals(1, graphGlobal2Directed.getMetaEdges(nodeMap.get("Leaf 0")).toArray().length);
        assertEquals(1, graphGlobal2Directed.getMetaEdges(nodeMap.get("Leaf 1")).toArray().length);
        assertEquals(1, graphGlobal2Directed.getEdges().toArray().length);
        Edge uniqueEdge = graphGlobal2Directed.getEdges().toArray()[0];
        assertSame(nodeMap.get("Leaf 0"), uniqueEdge.getTarget());
        assertSame(nodeMap.get("Leaf 1"), uniqueEdge.getSource());
        assertEquals(5, graphGlobal2Directed.getEdgesAndMetaEdges().toArray().length);
    }
View Full Code Here


        }
        return edge.getWeight();
    }

    public Node getPredecessor(Node node) {
        Edge edge = predecessors.get(node);
        if (edge != null) {
            if (edge.getSource() != node) {
                return edge.getSource();
            } else {
                return edge.getTarget();
            }
        }
        return null;
    }
View Full Code Here

        int edgeCount = 0;
        for (EdgeDraftGetter edge : container.getEdges()) {
            Node source = edge.getSource().getNode();
            Node target = edge.getTarget().getNode();
            if (graph.getEdge(source, target) == null) {
                Edge e = null;
                switch (container.getEdgeDefault()) {
                    case DIRECTED:
                        e = factory.newEdge(edge.isAutoId()?null:edge.getId(), source, target, edge.getWeight(), true);
                        break;
                    case UNDIRECTED:
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);
                        }
                    } else {
                        continue;//Ignore this edge row, since no new nodes should be created.
                    }
                }

                if (typeColumn != null) {
                    type = reader.get(typeColumn);
                    //Undirected if indicated correctly, otherwise always directed:
                    if (type != null) {
                        directed = !type.equalsIgnoreCase("undirected");
                    } else {
                        directed = true;
                    }
                } else {
                    directed = true;//Directed by default when not indicated
                }

                //Prepare the correct edge to assign the attributes:
                if (idColumn != null) {
                    id = reader.get(idColumn);
                    if (id == null || id.isEmpty()) {
                        edge = gec.createEdge(source, target, directed);//id null or empty, assign one
                    } else {
                        edge = gec.createEdge(id, source, target, directed);
                        if (edge == null) {//Edge with that id already in graph
                            edge = gec.createEdge(source, target, directed);
                        }
                    }
                } else {
                    edge = gec.createEdge(source, target, directed);
                }

                if (edge != null) {//Edge could be created because it does not already exist:
                    //Assign attributes to the current edge:
                    edgeAttributes = edge.getEdgeData().getAttributes();
                    for (AttributeColumn column : columnsList) {
                        setAttributeValue(reader.get(column.getTitle()), edgeAttributes, column);
                    }
                }
            }
View Full Code Here

    private void refreshRows() {
        rows = columnsAndRowChooser.getRows();
        Object sourceRow = columnsAndRowChooser.getRow();
        Node node;
        Edge edge;
        //Prepare combo box with nodes/edges data:
        for (int i = 0; i < rows.length; i++) {
            if (rows[i] instanceof Node) {
                node = (Node) rows[i];
                rowComboBox.addItem(node.getId() + " - " + node.getNodeData().getLabel());
            } else {
                edge = (Edge) rows[i];
                rowComboBox.addItem(edge.getId() + " - " + edge.getEdgeData().getLabel());
            }
            if (rows[i] == sourceRow) {
                rowComboBox.setSelectedIndex(i);
            }
        }
View Full Code Here

        Set<Edge> edgesInDraft = new HashSet<Edge>();
        int newEdgeCount = 0;
        for (EdgeDraftGetter draftEdge : container.getEdges()) {
            Node source = draftEdge.getSource().getNode();
            Node target = draftEdge.getTarget().getNode();
            Edge edge = graph.getEdge(source, target);
            TimeInterval timeInterval = null;
            if (edge == null) {
                //Edge is new
                switch (container.getEdgeDefault()) {
                    case DIRECTED:
                        edge = factory.newEdge(draftEdge.isAutoId() ? null : draftEdge.getId(), source, target, draftEdge.getWeight(), true);
                        break;
                    case UNDIRECTED:
                        edge = factory.newEdge(draftEdge.isAutoId() ? null : draftEdge.getId(), source, target, draftEdge.getWeight(), false);
                        break;
                    case MIXED:
                        edge = factory.newEdge(draftEdge.isAutoId() ? null : draftEdge.getId(), source, target, draftEdge.getWeight(), draftEdge.getType().equals(EdgeType.UNDIRECTED) ? false : true);
                        break;
                }
                newEdgeCount++;
                graph.addEdge(edge);
                flushToEdge(draftEdge, edge);
            } else {
                timeInterval = (TimeInterval) edge.getEdgeData().getAttributes().getValue(edgeDynamicColumn.getIndex());
                flushToEdgeAttributes(draftEdge, edge);
            }
            edgesInDraft.add(edge);

            //Add Point
            edge.getEdgeData().getAttributes().setValue(edgeDynamicColumn.getIndex(), addPoint(timeInterval, point));
        }

        //Remove point from all edges not in draft
        for (Edge edge : graph.getEdges()) {
            if (!edgesInDraft.contains(edge)) {
                TimeInterval timeInterval = (TimeInterval) edge.getEdgeData().getAttributes().getValue(edgeDynamicColumn.getIndex());
                edge.getEdgeData().getAttributes().setValue(edgeDynamicColumn.getIndex(), removePoint(timeInterval, point));
            }
        }

        System.out.println("# New Nodes loaded: " + newNodeCount + "\n# New Edges loaded: " + newEdgeCount);
        workspace = null;
View Full Code Here

    @Test
    public void testDelete() {
        Node node1 = nodeMap.get("Node 1");
        Node node2 = nodeMap.get("Node 2");
        Edge edge21 = edgeMap.get("2-1");

        GraphView newView = dhnsGlobal.newView();
        HierarchicalGraph viewGraph = dhnsGlobal.getHierarchicalGraph(newView);

        assertNotNull(node1.getNodeData().getNode(newView.getViewId()));
        assertNotNull(dhnsGlobal.getGraphStructure().getNodeFromDictionnary(node1.getId(), newView.getViewId()));
        assertNotNull(dhnsGlobal.getGraphStructure().getNodeFromDictionnary(node1.getId(), graphGlobal.getView().getViewId()));
        assertNotNull(dhnsGlobal.getGraphStructure().getEdgeFromDictionnary(edge21.getId()));

        graphGlobal.removeNode(node1);

        assertNull(node1.getNodeData().getNode(graphGlobal.getView().getViewId()));
        assertNull(node1.getNodeData().getNode(newView.getViewId()));
View Full Code Here

            }
        }

        private JPopupMenu createPopup(Point p) {
            final Edge[] selectedEdges = getEdgesFromSelectedRows();
            final Edge clickedEdge = getEdgeFromRow(table.rowAtPoint(p));
            JPopupMenu contextMenu = new JPopupMenu();

            //First add edges manipulators items:
            DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
            Integer lastManipulatorType = null;
            for (EdgesManipulator em : dlh.getEdgesManipulators()) {
                em.setup(selectedEdges, clickedEdge);
                if (lastManipulatorType == null) {
                    lastManipulatorType = em.getType();
                }
                if (lastManipulatorType != em.getType()) {
                    contextMenu.addSeparator();
                }
                lastManipulatorType = em.getType();
                if (em.isAvailable()) {
                    contextMenu.add(PopupMenuUtils.createMenuItemFromEdgesManipulator(em, clickedEdge, selectedEdges));
                }
            }

            //Add AttributeValues manipulators submenu:
            AttributeRow row = (AttributeRow) clickedEdge.getEdgeData().getAttributes();
            int realColumnIndex = table.convertColumnIndexToModel(table.columnAtPoint(p)) - FAKE_COLUMNS_COUNT;//Get real attribute column index not counting fake columns.
            if (realColumnIndex >= 0) {
                AttributeColumn column = showingColumns[realColumnIndex];
                if (column != null) {
                    contextMenu.add(PopupMenuUtils.createSubMenuFromRowColumn(row, column));
View Full Code Here

            duplicateNode(n);
        }
    }

    public Edge createEdge(Node source, Node target, boolean directed) {
        Edge newEdge;
        if (directed) {
            newEdge = buildEdge(source, target, true);
            if (getDirectedGraph().addEdge(newEdge)) {//The edge will be created if it does not already exist.
                return newEdge;
            } else {
View Full Code Here

            }
        }
    }

    public Edge createEdge(String id, Node source, Node target, boolean directed) {
        Edge newEdge;
        if (source != target) {//Cannot create self-loop
            if (directed) {
                newEdge = buildEdge(id, source, target, true);
                if (getDirectedGraph().addEdge(newEdge)) {//The edge will be created if it does not already exist.
                    return newEdge;
View Full Code Here

TOP

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

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.