Refine search
protected void initialize(Graph<V, E> graph) { this.graph = graph; this.vertex_scores = new HashMap<V, Double>(); this.edge_scores = new HashMap<E, Double>(); this.vertex_data = new HashMap<V, BetweennessData>(); for (V v : graph.getVertices()) { this.vertex_scores.put(v, 0.0); } for (E e : graph.getEdges()) { this.edge_scores.put(e, 0.0); } }
/** * @see edu.uci.ics.jung.graph.Hypergraph#addEdge(Object, Collection, * EdgeType) */ @Override public synchronized boolean addEdge(E e, Collection<? extends V> vertices, EdgeType edgeType) { return delegate.addEdge(e, vertices, edgeType); }
/** * adds root as a root of the tree * @param root the initial tree root */ public void setRoot(V root) { delegate.addVertex(root); }
/** * @return the root of each tree of this forest as a {@code Collection}. */ public Collection<V> getRoots() { Collection<V> roots = new HashSet<V>(); for(V v : delegate.getVertices()) { if(delegate.getPredecessorCount(v) == 0) { roots.add(v); } } return roots; }
private Set<V> getRoots() { Set<V> roots = graph.getVertices().stream() .filter(v -> graph.getInEdges(v).isEmpty()) // Preserve the order of the roots .collect(Collectors.toCollection(LinkedHashSet::new)); return roots; }
private void shift(final Layout<ElementName, Dependency> l, final int dx, final int dy) { for (final ElementName each : l.getGraph().getVertices()) { final Point2D point = l.transform(each); point.setLocation(point.getX() + dx, point.getY() + dy); } } }
public Paint apply(E e) { Layout<V, E> layout = vv.getGraphLayout(); Pair<V> p = layout.getGraph().getEndpoints(e); V b = p.getFirst(); V f = p.getSecond(); Point2D pb = transformer.transform(layout.apply(b)); Point2D pf = transformer.transform(layout.apply(f)); float xB = (float) pb.getX(); float yB = (float) pb.getY(); float xF = (float) pf.getX(); float yF = (float) pf.getY(); if ((layout.getGraph().getEdgeType(e)) == EdgeType.UNDIRECTED) { xF = (xF + xB) / 2; yF = (yF + yB) / 2; } if(selfLoop.apply(Context.<Graph<V,E>,E>getInstance(layout.getGraph(), e))) { yF += 50; xF += 50; } return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true); }
Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().apply(Context.<Graph<V,E>,E>getInstance(graph,e))) return; if (!rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v1)) || !rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v2))) return; p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1); p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY();
protected void relaxEdges() { try { for(E e : getGraph().getEdges()) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); double vx = p1.getX() - p2.getX(); double vy = p1.getY() - p2.getY(); double len = Math.sqrt(vx * vx + vy * vy); f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2));
private void checkEdge(E e) { Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1); p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); Shape s2 = rc.getVertexShapeTransformer().apply(v2); Shape edgeShape = rc.getEdgeShapeTransformer().apply(e);
protected void calcAttraction(E e) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); boolean v1_locked = isLocked(v1); boolean v2_locked = isLocked(v2); Point2D p2 = transform(v2); if(p1 == null || p2 == null) return; double xDelta = p1.getX() - p2.getX(); double yDelta = p1.getY() - p2.getY(); double deltaLength = Math.max(EPSILON, p1.distance(p2));
public void setLocation(V v, Point2D location) { boolean wasInSublayout = false; for(Layout<V,E> layout : layouts.keySet()) { if(layout.getGraph().getVertices().contains(v)) { Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(-center.getX()+d.width/2,-center.getY()+d.height/2); Point2D localLocation = at.transform(location, null); layout.setLocation(v, localLocation); wasInSublayout = true; } } if(wasInSublayout == false && getGraph().getVertices().contains(v)) { delegate.setLocation(v, location); } }
for(E e : graph.getEdges()) { Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); Point2D p1 = layout.apply(v1); Point2D p2 = layout.apply(v2); float x1 = (float)p1.getX(); float y1 = (float)p1.getY(); float x2 = (float)p2.getX(); float y2 = (float)p2.getY(); Shape s2 = rc.getVertexShapeTransformer().apply(v2); Shape edgeShape = rc.getEdgeShapeTransformer().apply(e); for(V v : graph.getVertices()) { Shape shape = rc.getVertexShapeTransformer().apply(v); Point2D p = layout.apply(v);
final Pair<Node> endpoints = graph.getEndpoints(e); final Node v1 = endpoints.getFirst(); final Node v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Edge>getInstance(graph, e))) { return; if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v2))) { return; final FontMetrics fm = g.getFontMetrics(); int w = fm.stringWidth(e.text); double p = Math.max(0, p1.getX() + p2.getX() - w); xform.translate(Math.min(layout.getSize().width - w, p / 2), (p1.getY() + p2.getY() - fm.getHeight()) / 2); g.setTransform(xform); g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true);
public boolean evaluate(Context<Graph<V,E>,E> context) { Pair<V> endpoints = context.graph.getEndpoints(context.element); return endpoints.getFirst().equals(endpoints.getSecond()); } }
@Override public void rebuildGraph() { for (GUILink gl : new ArrayList<>(g.getEdges())) g.removeEdge(gl); for (GUINode gn : new ArrayList<>(g.getVertices())) g.removeVertex(gn); for (GUINode gn : callback.getVisualizationState().getCanvasAllGUINodes()) g.addVertex(gn); for (GUILink gl : callback.getVisualizationState().getCanvasAllGUILinks(true, true)) g.addEdge(gl, gl.getOriginNode(), gl.getDestinationNode()); updateAllVerticesXYPosition(); refresh(); }
public void paint(Graphics g) { if(mPred == null) return; // for all edges, paint edges that are in shortest path for (Number e : layout.getGraph().getEdges()) { if(isBlessed(e)) { String v1 = mGraph.getEndpoints(e).getFirst(); String v2 = mGraph.getEndpoints(e).getSecond(); Point2D p1 = layout.apply(v1); Point2D p2 = layout.apply(v2); p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p1); p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p2); Renderer<String,Number> renderer = vv.getRenderer(); renderer.renderEdge( vv.getRenderContext(), layout, e); } } } });
public void drawFromDeploymentModel(){ Collection<Edge> c = new ArrayList<Edge>(graph.getEdges()); for(Edge e : c) graph.removeEdge(e); Collection<Vertex> vs =new ArrayList<Vertex>(graph.getVertices()); for(Vertex ve : vs) graph.removeVertex(ve); ArrayList<Vertex> v = drawVerticesFromDeploymentModel(dmodel); drawEdgesFromDeploymentModel(dmodel, v); nodeTypes.removeAll(); nodeTypes.setModel(fillList()); }
public void paintEdge(RenderContext<V,E> rc, Layout<V, E> layout, E e) { GraphicsDecorator g2d = rc.getGraphicsContext(); Graph<V,E> graph = layout.getGraph(); if (!rc.getEdgeIncludePredicate().apply(Context.<Graph<V,E>,E>getInstance(graph,e))) return; // don't draw edge if either incident vertex is not drawn Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); if (!rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v1)) || !rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v2))) return; Stroke new_stroke = rc.getEdgeStrokeTransformer().apply(e); Stroke old_stroke = g2d.getStroke(); if (new_stroke != null) g2d.setStroke(new_stroke); drawSimpleEdge(rc, layout, e); // restore paint and stroke if (new_stroke != null) g2d.setStroke(old_stroke); }
/** * Returns <code>true</code> if this edge and its endpoints * in this graph are all included in the collections of * elements to be rendered, and <code>false</code> otherwise. * @param context the edge and graph to be queried * @return <code>true</code> if this edge and its endpoints are all * included in the collections of elements to be rendered, <code>false</code> * otherwise. */ protected boolean isEdgeRendered(Context<Graph<V,E>,E> context) { Predicate<Context<Graph<V,E>,V>> vertexIncludePredicate = vv.getRenderContext().getVertexIncludePredicate(); Predicate<Context<Graph<V,E>,E>> edgeIncludePredicate = vv.getRenderContext().getEdgeIncludePredicate(); Graph<V,E> g = context.graph; E e = context.element; boolean edgeTest = edgeIncludePredicate == null || edgeIncludePredicate.apply(context); Pair<V> endpoints = g.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); boolean endpointsTest = vertexIncludePredicate == null || (vertexIncludePredicate.apply(Context.<Graph<V,E>,V>getInstance(g,v1)) && vertexIncludePredicate.apply(Context.<Graph<V,E>,V>getInstance(g,v2))); return edgeTest && endpointsTest; }