private static void doSpringLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, int repulsion) { SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph); layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER); layout.setRepulsionRange(repulsion); layout.setInitializer(initializer(graphLayout)); layout.setSize(size); int count = 0; while(!layout.done() && count < 700) { layout.step(); count++; } for(VertexRef v : jungGraph.getVertices()) { graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v))); } }
/** * Relaxation step. Moves all nodes a smidge. */ public void step() { try { for(V v : getGraph().getVertices()) { SpringVertexData svd = springVertexData.getUnchecked(v); if (svd == null) { continue; } svd.dx /= 4; svd.dy /= 4; svd.edgedx = svd.edgedy = 0; svd.repulsiondx = svd.repulsiondy = 0; } } catch(ConcurrentModificationException cme) { step(); } relaxEdges(); calculateRepulsion(); moveNodes(); }
protected void moveNodes() synchronized (getSize()) { try { for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = springVertexData.getUnchecked(v); if(vd == null) continue; Point2D xyd = apply(v); xyd.getY()+Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; moveNodes();
public void actionPerformed(ActionEvent ae) { Dimension d = new Dimension(600,600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); layout = new SpringLayout<Number,Number>(g, Functions.<Integer>constant(EDGE_LENGTH)); layout.setSize(d); vv.getModel().setGraphLayout(layout, d); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<Number,Number>(g, d); vv.getModel().setGraphLayout(layout, d); } } });
protected void moveNodes() synchronized (getSize()) { try { for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = springVertexData.get(v); if(vd == null) continue; Point2D xyd = transform(v); xyd.getY()+Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; moveNodes();
protected void calculateRepulsion() { try { for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; double dx = 0, dy = 0; for (V v2 : getGraph().getVertices()) { if (v == v2) continue; Point2D p = apply(v); Point2D p2 = apply(v2); if(p == null || p2 == null) continue; double vx = p.getX() - p2.getX(); calculateRepulsion();
protected void calculateRepulsion() { try { for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; double dx = 0, dy = 0; for (V v2 : getGraph().getVertices()) { if (v == v2) continue; Point2D p = transform(v); Point2D p2 = transform(v2); if(p == null || p2 == null) continue; double vx = p.getX() - p2.getX(); calculateRepulsion();
protected void relaxEdges() { try { for(E e : getGraph().getEdges()) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); Point2D p1 = apply(v1); Point2D p2 = apply(v2); if(p1 == null || p2 == null) continue; double vx = p1.getX() - p2.getX(); f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2)); relaxEdges();
protected void relaxEdges() { try { for(E e : getGraph().getEdges()) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); Point2D p1 = transform(v1); Point2D p2 = transform(v2); if(p1 == null || p2 == null) continue; double vx = p1.getX() - p2.getX(); f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2)); relaxEdges();
/** * Sets the dimensions of the available space for layout to {@code size}. */ @Override public void setSize(Dimension size) { if(initialized == false) setInitializer(new RandomLocationTransformer<V>(size)); super.setSize(size); }
/** * Relaxation step. Moves all nodes a smidge. */ @Override public void step() { super.step(); currentIteration++; testAverageDeltas(); }
@Override public void setSize(Dimension size) { super.setSize(size); for(V v : getGraph().getVertices()) { initializeLocation(v,apply(v),getSize()); } }
/** * Had to override this one as well, to ensure that setRoot() is called. */ @Override public void initialize() { super.initialize(); setRoot(); }
private Layout<Node, Edge> newLayout(final Diagram diagram) { final Layout<Node, Edge> diagramLayout; if (layout != null && layout.startsWith("spring")) { diagramLayout = new SpringLayout<Node, Edge>(diagram, new ConstantTransformer(Integer.parseInt(config("spring", "100")))); } else if (layout != null && layout.startsWith("kk")) { Distance<Node> distance = new DijkstraDistance<Node, Edge>(diagram); if (layout.endsWith("unweight")) { distance = new UnweightedShortestPath<Node, Edge>(diagram); } diagramLayout = new KKLayout<Node, Edge>(diagram, distance); } else if (layout != null && layout.equalsIgnoreCase("circle")) { diagramLayout = new CircleLayout<Node, Edge>(diagram); } else if (layout != null && layout.equalsIgnoreCase("fr")) { diagramLayout = new FRLayout<Node, Edge>(diagram); } else { final LevelLayout levelLayout = new LevelLayout(diagram); levelLayout.adjust = adjust; diagramLayout = levelLayout; } return diagramLayout; }
@Override public void setSize(Dimension size) { if(initialized == false) setInitializer(new RandomLocationTransformer<V>(size)); super.setSize(size); }
/** * Relaxation step. Moves all nodes a smidge. */ @Override public void step() { super.step(); currentIteration++; testAverageDeltas(); }
@Override public void setSize(Dimension size) { super.setSize(size); for(V v : getGraph().getVertices()) { initializeLocation(v,transform(v),getSize()); } }
/** * Had to override this one as well, to ensure that setRoot() is called. */ @Override public void initialize() { super.initialize(); setRoot(getGraph()); }
private static void doSpringLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, int repulsion) { SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph); layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER); layout.setRepulsionRange(repulsion); layout.setInitializer(initializer(graphLayout)); layout.setSize(size); int count = 0; while(!layout.done() && count < 700) { layout.step(); count++; } for(VertexRef v : jungGraph.getVertices()) { graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v))); } }
@Override public void actionPerformed(ActionEvent e) { final GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent(); SpringLayout springLayout = new SpringLayout<String, String>(viewerPanel.getCurrentGraph()); MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer(); vv.setGraphLayout(springLayout); vv.repaint(); } }