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);
}
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 });
}
}
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);
}
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;
}
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;
}
Aggregations