protected void buildTree() { this.m_currentPoint = new Point(0, 20); Collection<V> roots = TreeUtils.getRoots(graph); if (roots.size() > 0 && graph != null) { calculateDimensionX(roots); for(V v : roots) { calculateDimensionX(v); m_currentPoint.x += this.basePositions.get(v)/2 + this.distX; buildTree(v, this.m_currentPoint.x); } } }
protected void buildTree(V v, int x) { if (alreadyDone.add(v)) { //go one level further down this.m_currentPoint.y += this.distY; this.m_currentPoint.x = x; this.setCurrentPositionFor(v); int sizeXofCurrent = basePositions.get(v); int lastX = x - sizeXofCurrent / 2; int sizeXofChild; int startXofChild; for (V element : graph.getSuccessors(v)) { sizeXofChild = this.basePositions.get(element); startXofChild = lastX + sizeXofChild / 2; buildTree(element, startXofChild); lastX = lastX + sizeXofChild + distX; } this.m_currentPoint.y -= this.distY; } }
public Dimension getSize() { int height = (int) Math.round(2 * Y_DIST * (1 + distanceToLeaf(root))); int width = (int) Math.round(2 * treeLayout.transform(root).getX()); return new Dimension(width, height); }
public DerivationTreeTransformer(DerivationTree t, Dimension d, boolean isAnchored) { this.isAnchored = isAnchored; anchorPoint = new Point2D.Double(0, 0); graph = t; DelegateForest<Node, DerivationTreeEdge> del = new DelegateForest<>(t); del.setRoot(t.root); del.setRoot(t.sourceRoot); root = t.root; sourceRoot = t.sourceRoot; Y_DIST = d.getHeight() / (2 * (1 + distanceToLeaf(root))); int leafCount = 0; for (Node n : t.getVertices()) { if (t.outDegree(n) == 0) leafCount++; } X_DIST = d.getWidth() / leafCount; treeLayout = new TreeLayout<>(del, (int) Math.round(X_DIST)); }
public void setGraph(Graph<V,E> graph) { if(graph instanceof Forest) { this.graph = (Forest<V,E>)graph; buildTree(); } else { throw new IllegalArgumentException("graph must be a Forest"); } }
private int calculateDimensionX(V v) { int size = 0; int childrenNum = graph.getSuccessors(v).size(); if (childrenNum != 0) { for (V element : graph.getSuccessors(v)) { size += calculateDimensionX(element) + distX; } } size = Math.max(0, size - distX); basePositions.put(v, size); return size; }
public void actionPerformed(ActionEvent e) { Collection<String> picked = new HashSet<String>(vv.getPickedVertexState().getPicked()); if(picked.size() == 1) { Object root = picked.iterator().next(); Forest<String, Integer> inGraph = (Forest<String, Integer>)layout.getGraph(); try { collapser.collapse(vv.getGraphLayout(), inGraph, root); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } vv.getPickedVertexState().clear(); vv.repaint(); } }});
treeLayout = new TreeLayout<String,Integer>(graph); radialLayout = new RadialTreeLayout<String,Integer>(graph); radialLayout.setSize(new Dimension(600,600));
public void setGraph(Graph<V,E> graph) { if(graph instanceof Forest) { this.graph = (Forest<V,E>)graph; buildTree(); } else { throw new IllegalArgumentException("graph must be a Forest"); } }
private int calculateDimensionX(V v) { int size = 0; int childrenNum = graph.getSuccessors(v).size(); if (childrenNum != 0) { for (V element : graph.getSuccessors(v)) { size += calculateDimensionX(element) + distX; } } size = Math.max(0, size - distX); basePositions.put(v, size); return size; }
public void actionPerformed(ActionEvent e) { Collection<String> picked = vv.getPickedVertexState().getPicked(); for(Object v : picked) { if(v instanceof Forest) { Forest<String, Integer> inGraph = (Forest<String, Integer>)layout.getGraph(); collapser.expand(inGraph, (Forest<?, ?>)v); } vv.getPickedVertexState().clear(); vv.repaint(); } }});
protected void buildTree() { this.m_currentPoint = new Point(0, 20); Collection<V> roots = TreeUtils.getRoots(graph); if (roots.size() > 0 && graph != null) { calculateDimensionX(roots); for(V v : roots) { calculateDimensionX(v); m_currentPoint.x += this.basePositions.get(v)/2 + this.distX; buildTree(v, this.m_currentPoint.x); } } int width = 0; for(V v : roots) { width += basePositions.get(v); } }
protected void buildTree(V v, int x) { if (!alreadyDone.contains(v)) { alreadyDone.add(v); //go one level further down this.m_currentPoint.y += this.distY; this.m_currentPoint.x = x; this.setCurrentPositionFor(v); int sizeXofCurrent = basePositions.get(v); int lastX = x - sizeXofCurrent / 2; int sizeXofChild; int startXofChild; for (V element : graph.getSuccessors(v)) { sizeXofChild = this.basePositions.get(element); startXofChild = lastX + sizeXofChild / 2; buildTree(element, startXofChild); lastX = lastX + sizeXofChild + distX; } this.m_currentPoint.y -= this.distY; } }
layout = new TreeLayout<String,Integer>(graph); collapser = new TreeCollapser();
/** * Creates an instance for the specified graph, X distance, and Y distance. */ public TreeLayout(Forest<V,E> g, int distx, int disty) { if (g == null) throw new IllegalArgumentException("Graph must be non-null"); if (distx < 1 || disty < 1) throw new IllegalArgumentException("X and Y distances must each be positive"); this.graph = g; this.distX = distx; this.distY = disty; buildTree(); }
private int calculateDimensionX(Collection<V> roots) { int size = 0; for(V v : roots) { int childrenNum = graph.getSuccessors(v).size(); if (childrenNum != 0) { for (V element : graph.getSuccessors(v)) { size += calculateDimensionX(element) + distX; } } size = Math.max(0, size - distX); basePositions.put(v, size); } return size; }
public Point2D transform(Node n) { double x, y; Point2D t = treeLayout.transform(n); if (n.isSource) { x = /* treeLayout.transform(root).getX() + */(t.getX() - treeLayout.transform(sourceRoot).getX() + treeLayout.transform(root).getX()); y = Y_DIST * (distanceToLeaf(n) + 1); } else { x = t.getX(); y = Y_DIST * (-1) * distanceToLeaf(n); } if (isAnchored) { x += anchorPoint.getX(); y += anchorPoint.getY(); } return new Point2D.Double(x, y + Y_DIST * (1 + distanceToLeaf(root))); }
treeLayout = new TreeLayout<String,Integer>(graph); radialLayout = new RadialTreeLayout<String,Integer>(graph); radialLayout.setSize(new Dimension(600,600));
/** * Creates an instance for the specified graph, X distance, and Y distance. * @param g the graph on which the layout algorithm is to operate * @param distx the horizontal spacing between adjacent siblings * @param disty the vertical spacing between adjacent siblings */ public TreeLayout(Forest<V,E> g, int distx, int disty) { if (g == null) throw new IllegalArgumentException("Graph must be non-null"); if (distx < 1 || disty < 1) throw new IllegalArgumentException("X and Y distances must each be positive"); this.graph = g; this.distX = distx; this.distY = disty; buildTree(); }
private int calculateDimensionX(Collection<V> roots) { int size = 0; for(V v : roots) { int childrenNum = graph.getSuccessors(v).size(); if (childrenNum != 0) { for (V element : graph.getSuccessors(v)) { size += calculateDimensionX(element) + distX; } } size = Math.max(0, size - distX); basePositions.put(v, size); } return size; }