Search in sources :

Example 76 with Node

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

the class GraphDistanceNGTest method testDirectedCyclicGraphBetweenness.

@Test
public void testDirectedCyclicGraphBetweenness() {
    GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());
    HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
    double[] betweenness = metricsMap.get(GraphDistance.BETWEENNESS);
    Node n1 = directedGraph.getNode("0");
    Node n3 = directedGraph.getNode("2");
    int index1 = indicies.get(n1);
    int index3 = indicies.get(n3);
    assertEquals(betweenness[index1], 6.0, TOLERANCE);
    assertEquals(betweenness[index3], 6.0, TOLERANCE);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 77 with Node

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

the class AddNodeToGraph method execute.

@Override
public void execute() {
    String label = JOptionPane.showInputDialog(null, NbBundle.getMessage(AddNodeToGraph.class, "AddNodeToGraph.dialog.text"), NbBundle.getMessage(AddNodeToGraph.class, "AddNodeToGraph.name"), JOptionPane.QUESTION_MESSAGE);
    if (label != null) {
        Node node = Lookup.getDefault().lookup(GraphElementsController.class).createNode(label);
        Lookup.getDefault().lookup(DataTablesController.class).setNodeTableSelection(new Node[] { node });
    }
}
Also used : Node(org.gephi.graph.api.Node) GraphElementsController(org.gephi.datalab.api.GraphElementsController) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 78 with Node

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

the class AddEdgeToGraphUI method setup.

@Override
public void setup(Manipulator m, DialogControls dialogControls) {
    this.manipulator = (AddEdgeToGraph) m;
    if (manipulator.isDirected()) {
        directedRadioButton.setSelected(true);
    } else {
        undirectedRadioButton.setSelected(true);
    }
    graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
    nodes = graph.getNodes().toArray();
    workspace = Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace();
    for (Node n : nodes) {
        sourceNodesComboBox.addItem(n.getId() + " - " + n.getLabel());
        targetNodesComboBox.addItem(n.getId() + " - " + n.getLabel());
    }
    SelectedOptions selectedOptions = workspace.getLookup().lookup(SelectedOptions.class);
    if (selectedOptions != null) {
        setNodeComboBoxSelection(sourceNodesComboBox, selectedOptions.source);
        setNodeComboBoxSelection(targetNodesComboBox, selectedOptions.target);
        edgeTypeComboBox.setSelectedItem(selectedOptions.edgeType);
    } else {
        workspace.add(new SelectedOptions());
    }
    refreshAvailableEdgeTypes();
    dialogControls.setOkButtonEnabled(nodes.length > 0);
}
Also used : Node(org.gephi.graph.api.Node) GraphController(org.gephi.graph.api.GraphController)

Example 79 with Node

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

the class AttributeColumnsControllerImpl method detectNodeDuplicatesByColumn.

@Override
public List<List<Node>> detectNodeDuplicatesByColumn(Column column, boolean caseSensitive) {
    final HashMap<String, List<Node>> valuesMap = new HashMap<>();
    Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
    Object value;
    String strValue;
    TimeFormat timeFormat = graph.getModel().getTimeFormat();
    DateTimeZone timeZone = graph.getModel().getTimeZone();
    for (Node node : graph.getNodes().toArray()) {
        value = node.getAttribute(column);
        if (value != null) {
            strValue = AttributeUtils.print(value, timeFormat, timeZone);
            if (!caseSensitive) {
                strValue = strValue.toLowerCase();
            }
            if (valuesMap.containsKey(strValue)) {
                valuesMap.get(strValue).add(node);
            } else {
                ArrayList<Node> newGroup = new ArrayList<>();
                newGroup.add(node);
                valuesMap.put(strValue, newGroup);
            }
        }
    }
    final List<List<Node>> groupsList = new ArrayList<>();
    for (List<Node> group : valuesMap.values()) {
        if (group.size() > 1) {
            groupsList.add(group);
        }
    }
    return groupsList;
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) HashMap(java.util.HashMap) Node(org.gephi.graph.api.Node) ArrayList(java.util.ArrayList) DateTimeZone(org.joda.time.DateTimeZone) Graph(org.gephi.graph.api.Graph) ArrayList(java.util.ArrayList) List(java.util.List)

Example 80 with Node

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

the class GraphElementsControllerImpl method buildNode.

private Node buildNode(Graph graph, String label, String id) {
    Node newNode;
    if (id != null) {
        newNode = graph.getModel().factory().newNode(id);
    } else {
        newNode = graph.getModel().factory().newNode();
    }
    newNode.setSize(DEFAULT_NODE_SIZE);
    newNode.setLabel(label);
    //Set random position to the node:
    newNode.setX((float) ((0.01 + Math.random()) * 1000) - 500);
    newNode.setY((float) ((0.01 + Math.random()) * 1000) - 500);
    return newNode;
}
Also used : Node(org.gephi.graph.api.Node)

Aggregations

Node (org.gephi.graph.api.Node)301 GraphModel (org.gephi.graph.api.GraphModel)169 Test (org.testng.annotations.Test)152 Edge (org.gephi.graph.api.Edge)116 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)102 DirectedGraph (org.gephi.graph.api.DirectedGraph)84 GraphController (org.gephi.graph.api.GraphController)82 HashMap (java.util.HashMap)62 Graph (org.gephi.graph.api.Graph)50 Column (org.gephi.graph.api.Column)22 LinkedList (java.util.LinkedList)17 NodeIterable (org.gephi.graph.api.NodeIterable)12 EdgeIterable (org.gephi.graph.api.EdgeIterable)10 Table (org.gephi.graph.api.Table)10 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 GraphElementsController (org.gephi.datalab.api.GraphElementsController)6 Color (java.awt.Color)5 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 MouseClickEventListener (org.gephi.tools.spi.MouseClickEventListener)4