@Override public boolean init(Graph graph) { Node[] nodes = graph.getNodes().toArray(); Arrays.sort(nodes, new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { Comparable a1 = (Comparable) o1.getAttribute(column); Comparable a2 = (Comparable) o2.getAttribute(column); if (a1 == null && a2 != null) { return 1; } else if (a1 != null && a2 == null) { return -1; } else if (a1 == null && a2 == null) { return 0; } else { return a2.compareTo(a1); } } }); topSet = new HashSet<Node>(top); for (int i = 0; i < top && i < nodes.length; i++) { topSet.add(nodes[i]); } return true; }
/** * Used for iterating through all nodes of the graph * * @return Array with all graph nodes */ private Node[] getNodesArray() { return Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph().getNodes().toArray(); }
@Override public Node[] getNodeNeighbours(Node node) { return getCurrentGraph().getNeighbors(node).toArray(); }
/** * Sets nodesToSearch as all nodes in the graph if they are null or empty array. * Also only search on visible view if data table is showing visible only. */ private void checkNodesToSearch() { if (nodesToSearch == null || nodesToSearch.length == 0) { Graph graph; if (Lookup.getDefault().lookup(DataTablesController.class).isShowOnlyVisible()) { graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraphVisible(); } else { graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph(); } nodesToSearch = graph.getNodes().toArray(); } }
for (Node node : graph.getNodes().toArray()) { if (!result.contains(node)) { graph.removeNode(node);
DateTimeZone timeZone = graph.getModel().getTimeZone(); for (Node node : graph.getNodes().toArray()) { value = node.getAttribute(column); if (value != null) {
@Override public Graph filter(Graph graph) { int removed = 0; do { removed = 0; for (Node n : graph.getNodes().toArray()) { if (graph.getDegree(n) < k) { graph.removeNode(n); removed++; } } } while (removed > 0); return graph; }
@Override public void execute() { //Note that a function to inverse selection directly in the table with DataTablesController //would be more efficient than calculating it here, but this example demonstrates some table selection features. DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class); Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph(); if (dtc.isNodeTableMode()) { //Get currently selected nodes and calculate inverse set. Node[] selected = dtc.getNodeTableSelection(); ArrayList<Node> nodes = new ArrayList<Node>(); nodes.addAll(Arrays.asList(graph.getNodes().toArray())); for (Node node : selected) { nodes.remove(node); } dtc.setNodeTableSelection(nodes.toArray(new Node[0])); } else if (dtc.isEdgeTableMode()) { //Get currently selected edges and calculate inverse set. Edge[] selected = dtc.getEdgeTableSelection(); ArrayList<Edge> edges = new ArrayList<Edge>(); edges.addAll(Arrays.asList(graph.getEdges().toArray())); for (Edge edge : selected) { edges.remove(edge); } dtc.setEdgeTableSelection(edges.toArray(new Edge[0])); } }
@Override public void goAlgo() { Graph graph = graphModel.getGraphVisible(); graph.readLock(); int nodeCount = graph.getNodeCount(); Node[] nodes = graph.getNodes().toArray(); int rows = (int) Math.round(Math.sqrt(nodeCount)) + 1; int cols = (int) Math.round(Math.sqrt(nodeCount)) + 1; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols && (i * rows + j) < nodes.length; j++) { Node node = nodes[i * rows + j]; float x = (-areaSize / 2f) + ((float) j / cols) * areaSize; float y = (areaSize / 2f) - ((float) i / rows) * areaSize; float px = node.x(); float py = node.y(); node.setX(px + (x - px) * (speed / 10000f)); node.setY(py + (y - py) * (speed / 10000f)); } } graph.readUnlock(); }
if (onlyVisibleElements) { nodes = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraphVisible().getNodes().toArray(); } else { nodes = new Node[0];//Search on all nodes
@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); }
nodeTable.refreshModel(graph.getNodes().toArray(), cols, graphModel, dataTablesModel);
graph.readLock(); int nodeCount = graph.getNodeCount(); Node[] nodes = graph.getNodes().toArray();
@Override public void actionPerformed(ActionEvent evt) { GraphController gc = Lookup.getDefault().lookup(GraphController.class); GraphModel gm = gc.getGraphModel(); Graph graph = gm.getGraphVisible(); for (Node n : graph.getNodes().toArray()) { n.getTextProperties().setColor(Color.BLACK); n.getTextProperties().setAlpha(0f); } for (Edge e : graph.getEdges().toArray()) { e.getTextProperties().setColor(Color.BLACK); e.getTextProperties().setAlpha(0f); } } });
@Override public void initAlgo() { AbstractLayout.ensureSafeLayoutNodePositions(graphModel); speed = 1.; speedEfficiency = 1.; graph = graphModel.getGraphVisible(); graph.readLock(); try { Node[] nodes = graph.getNodes().toArray(); // Initialise layout data for (Node n : nodes) { if (n.getLayoutData() == null || !(n.getLayoutData() instanceof ForceAtlas2LayoutData)) { ForceAtlas2LayoutData nLayout = new ForceAtlas2LayoutData(); n.setLayoutData(nLayout); } ForceAtlas2LayoutData nLayout = n.getLayoutData(); nLayout.mass = 1 + graph.getDegree(n); nLayout.old_dx = 0; nLayout.old_dy = 0; nLayout.dx = 0; nLayout.dy = 0; } pool = Executors.newFixedThreadPool(threadCount); currentThreadCount = threadCount; } finally { graph.readUnlockAll(); } }
Node[] nodes = graph.getNodes().toArray(); for (Node n : nodes) { double avg = 0;
GraphView reducedView = graphModel.copyView(graph.getView()); graph = graphModel.getGraph(reducedView); Node[] nodes = graph.getNodes().toArray(); for (int i = 0; i < nodes.length; i++) { float r = (float) i / (float) nodes.length;
@Override public Graph filter(Subgraph[] graphs) { if (graphs.length > 1) { throw new IllegalArgumentException("Not Filter accepts a single graph in parameter"); } Graph graph = graphs[0]; Graph mainGraph = graph.getView().getGraphModel().getGraph(); for (Node n : mainGraph.getNodes().toArray()) { if (!graph.contains(n)) { //The node n is not in graph graph.addNode(n); } else { //The node n is in graph graph.removeNode(n); } } for (Edge e : mainGraph.getEdges()) { Node source = e.getSource(); Node target = e.getTarget(); if (graph.contains(source) && graph.contains(target)) { Edge edgeInGraph = graph.getEdge(source, target, e.getType()); if (edgeInGraph == null) { graph.addEdge(e); } } } return graph; }
for (Node n : graph.getNodes().toArray()) { int degree = graph.getDegree(n);