/** * * @param graphModel */ @Override public void execute(GraphModel graphModel) { Graph graph = graphModel.getGraphVisible(); execute(graph); }
@Override public void initAlgo() { this.graph = graphModel.getGraphVisible(); setConverged(false); cancel = false; }
@Override public void execute(GraphModel graphModel) { Graph graph = graphModel.getGraphVisible(); execute(graph); }
/** * 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(); } }
/** * Sets edgesToSearch as all edges 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 checkEdgesToSearch() { if (edgesToSearch == null || edgesToSearch.length == 0) { Graph hg; if (Lookup.getDefault().lookup(DataTablesController.class).isShowOnlyVisible()) { hg = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraphVisible(); } else { hg = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph(); } edgesToSearch = hg.getEdges().toArray(); } }
@Override public void select() { //Get current visible graph GraphController graphController = Lookup.getDefault().lookup(GraphController.class); Graph graph = graphController.getGraphModel().getGraphVisible(); //Build the autocomplete data. A simple map from node's label graph.readLock(); data = new HashMap<String, Node>(); for (Node n : graph.getNodes()) { String label = n.getLabel(); String id = n.getId().toString(); if (label != null) { if (!label.isEmpty()) { data.put(label, n); } } else if (id != null && !id.isEmpty()) { data.put(id, n); } } graph.readUnlock(); }
@Override public void loop(GraphView window, Interval interval) { Graph graph = graphModel.getGraph(window); int count = graph.getNodeCount(); graphModel.getGraphVisible().setAttribute(NB_NODES, count, interval.getLow()); graphModel.getGraphVisible().setAttribute(NB_NODES, count, interval.getHigh()); counts.put(interval.getLow(), count); counts.put(interval.getHigh(), count); }
@Override public void loop(GraphView window, Interval interval) { Graph graph = graphModel.getGraph(window); int count = graph.getEdgeCount(); graphModel.getGraphVisible().setAttribute(NB_EDGES, count, interval.getLow()); graphModel.getGraphVisible().setAttribute(NB_EDGES, count, interval.getHigh()); counts.put(interval.getLow(), count); counts.put(interval.getHigh(), count); }
@Override public void execute(GraphModel graphModel) { Graph graph = graphModel.getGraphVisible(); selfLoopCount = 0; totalEdgeCount = graph.getEdgeCount(); for (Edge e : graph.getEdges()) { if (e.isSelfLoop()) { selfLoopCount++; } } }
private Node[] getDiffusedNodes(Node[] input) { GraphModel model = Lookup.getDefault().lookup(GraphController.class).getGraphModel(); switch (diffusionMethod) { case NEIGHBORS: return DiffusionMethods.getNeighbors(model.getGraphVisible(), input); case NEIGHBORS_OF_NEIGHBORS: return DiffusionMethods.getNeighborsOfNeighbors(model.getGraphVisible(), input); case PREDECESSORS: if (model.isDirected()) { return DiffusionMethods.getPredecessors(model.getDirectedGraphVisible(), input); } else { return DiffusionMethods.getNeighbors(model.getGraphVisible(), input); } case SUCCESSORS: if (model.isDirected()) { return DiffusionMethods.getSuccessors(model.getDirectedGraphVisible(), input); } else { return DiffusionMethods.getNeighbors(model.getGraphVisible(), input); } } return new Node[0]; }
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { for (Node n : graph.getNodes()) { n.setX((float) (-size / 2 + size * random.nextDouble())); n.setY((float) (-size / 2 + size * random.nextDouble())); } converged = true; } finally { graph.readUnlockAll(); } }
@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()) { n.getTextProperties().setVisible(true); } for (Edge e : graph.getEdges()) { e.getTextProperties().setVisible(true); } } });
@Override public void actionPerformed(ActionEvent evt) { color = resetColorButton.getColor(); GraphController gc = Lookup.getDefault().lookup(GraphController.class); GraphModel gm = gc.getGraphModel(); Graph graph = gm.getGraphVisible(); for (Node n : graph.getNodes()) { n.setR(color.getRed() / 255f); n.setG(color.getGreen() / 255f); n.setB(color.getBlue() / 255f); n.setAlpha(1f); } for (Edge e : graph.getEdges()) { e.setR(color.getRed() / 255f); e.setG(color.getGreen() / 255f); e.setB(color.getBlue() / 255f); e.setAlpha(0f); } } });
@Override public void transform(Function function) { if (model != null) { GraphModel graphModel = model.getGraphModel(); Graph graph = graphModel.getGraphVisible(); ElementIterable<? extends Element> iterable; if (function.getElementClass().equals(Node.class)) { iterable = graph.getNodes(); } else { iterable = graph.getEdges(); } try { for (Element element : iterable) { function.transform(element, graph); } } catch (Exception e) { iterable.doBreak(); if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } } }
@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(); }
private boolean initObserver() { if (observer == null || observer.isDestroyed() || observer.getGraph().getView() != graphModel.getVisibleView()) { if (observer != null && !observer.isDestroyed()) { observer.destroy(); } observer = graphModel.createGraphObserver(graphModel.getGraphVisible(), false); return true; } return false; }
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { double sin = Math.sin(-getAngle() * Math.PI / 180); double cos = Math.cos(-getAngle() * Math.PI / 180); double px = 0f; double py = 0f; for (Node n : graph.getNodes()) { double dx = n.x() - px; double dy = n.y() - py; n.setX((float) (px + dx * cos - dy * sin)); n.setY((float) (py + dy * cos + dx * sin)); } setConverged(true); } finally { graph.readUnlockAll(); } }
@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() { if (graphModel == null) { return; } graph = graphModel.getGraphVisible(); graph.readLock(); try { energy = Float.POSITIVE_INFINITY; for (Node n : graph.getNodes()) { n.setLayoutData(new ForceVector()); } progress = 0; setConverged(false); setStep(initialStep); } finally { graph.readUnlockAll(); } }
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { double xMean = 0, yMean = 0; for (Node n : graph.getNodes()) { xMean += n.x(); yMean += n.y(); } xMean /= graph.getNodeCount(); yMean /= graph.getNodeCount(); for (Node n : graph.getNodes()) { double dx = (n.x() - xMean) * getScale(); double dy = (n.y() - yMean) * getScale(); n.setX((float) (xMean + dx)); n.setY((float) (yMean + dy)); } setConverged(true); } finally { graph.readUnlockAll(); } }