Thread: [graphl-cvs] graphl/src/org/mediavirus/graphl/layout RepulsionNodeLayouter.java SortedNodeLayouter.j
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2004-10-27 10:55:49
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18264/src/org/mediavirus/graphl/layout Modified Files: RepulsionNodeLayouter.java SortedNodeLayouter.java Log Message: - FEATURE: finally implemented sortgedNodeLayouter with proportional layout - AbstractFacet.assignedElements is now a list, to be able to sort it - BUG: block graph update events during loading - FEATURE: nodes are placed at deterministic locations initially (loading the same file twice will result in the same layout) - FEATURE: minor performance enhancements for repulsionnodelayouter - renamed "controls" command line option to "toolbar" Index: RepulsionNodeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/RepulsionNodeLayouter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RepulsionNodeLayouter.java 14 Oct 2004 13:02:58 -0000 1.5 --- RepulsionNodeLayouter.java 27 Oct 2004 10:55:40 -0000 1.6 *************** *** 27,36 **** /* ! * Overrides @see org.mediavirus.graphl.layout.NodeLayouter#performLayoutStep(org.mediavirus.graphl.graph.Node, org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager) */ public void performLayoutStep(Node node, GraphManager graphManager) { if (!node.isDragging()) { NodeMovement movement = graphManager.getNodeMovement(node); ! for (Iterator nodes = getAssignedElements().iterator(); nodes.hasNext();) { Node node2 = (Node)nodes.next(); --- 27,41 ---- /* ! * @see org.mediavirus.graphl.layout.NodeLayouter#performLayoutStep(org.mediavirus.graphl.graph.Node, org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager) */ public void performLayoutStep(Node node, GraphManager graphManager) { if (!node.isDragging()) { NodeMovement movement = graphManager.getNodeMovement(node); ! double nodeX = node.getCenterX(); ! double nodeY = node.getCenterY(); ! ! //TODO (2) where do we get the repulsion of 2nd node? ! double factor=100.0*constantRepulsion*constantRepulsion; //*node2.getRepulsion(); //*rigidity; ! for (Iterator nodes = getAssignedElements().iterator(); nodes.hasNext();) { Node node2 = (Node)nodes.next(); *************** *** 41,46 **** double dx=0; double dy=0; ! double deltaX=node.getCenterX()-node2.getCenterX(); ! double deltaY=node.getCenterY()-node2.getCenterY(); double currentLengthSquared=deltaX*deltaX+deltaY*deltaY; //so it's length squared if (Math.abs(currentLengthSquared)<0.1) { --- 46,51 ---- double dx=0; double dy=0; ! double deltaX=nodeX-node2.getCenterX(); ! double deltaY=nodeY-node2.getCenterY(); double currentLengthSquared=deltaX*deltaX+deltaY*deltaY; //so it's length squared if (Math.abs(currentLengthSquared)<0.1) { *************** *** 55,60 **** // in the 'force field' } - //TODO (2) where do we get the repulsion of 2nd node? - double factor=100.0*constantRepulsion*constantRepulsion; //*node2.getRepulsion(); //*rigidity; dx*=factor; dy*=factor; --- 60,63 ---- Index: SortedNodeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/SortedNodeLayouter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SortedNodeLayouter.java 21 Oct 2004 16:00:47 -0000 1.6 --- SortedNodeLayouter.java 27 Oct 2004 10:55:40 -0000 1.7 *************** *** 5,10 **** --- 5,18 ---- package org.mediavirus.graphl.layout; + import java.awt.geom.Point2D; + import java.text.DateFormat; + import java.text.ParseException; + import java.util.Calendar; + import java.util.Collections; + import java.util.Comparator; + import java.util.Date; import java.util.Iterator; + import org.mediavirus.graphl.graph.GraphElement; import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager; *************** *** 18,121 **** public class SortedNodeLayouter extends AbstractFacet implements NodeLayouter { ! public static final int LEFTTORIGHT = 0; ! public static final int RIGHTTOLEFT = 1; ! public static final int TOPTOBOTTOM = 2; ! public static final int BOTTOMTOTOP = 3; ! int orientation = TOPTOBOTTOM; ! boolean align = false; boolean proportional = false; ! float distance = 150.0f; ! String property = null; /* ! * Overrides @see org.mediavirus.graphl.layout.NodeLayouter#performLayoutStep(org.mediavirus.graphl.graph.Node, org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager) */ public void performLayoutStep(Node node, GraphManager graphManager) { - if (!node.isDragging()) { - NodeMovement movement=graphManager.getNodeMovement(node); - - movement.dx=0; - movement.dy=0; ! String val1, val2; ! ! if (property != null) { ! val1 = node.getProperty(property, "").toLowerCase(); ! } ! else { ! val1 = node.getLabel().toLowerCase(); ! } ! ! for (Iterator nodes = getAssignedElements().iterator(); nodes.hasNext();) { ! Node other = (Node) nodes.next(); ! if (property != null) { ! val2 = other.getProperty(property, "").toLowerCase(); ! } ! else { ! val2 = other.getLabel().toLowerCase(); ! } ! ! int comp = val2.compareTo(val1); ! if (orientation == LEFTTORIGHT) { ! if (comp < 0) { ! movement.dx += (other.getCenterX()-node.getCenterX()+30) / 10; ! } ! else if (comp > 0) { ! movement.dx -= (node.getCenterX()+30-other.getCenterX()) / 10; ! } ! if (align) { ! movement.dy += (other.getCenterY() - node.getCenterY()) / 10; ! } ! } ! ! if (orientation == RIGHTTOLEFT) { ! if (comp > 0) { ! movement.dx += (other.getCenterX()-node.getCenterX()+30) / 10; ! } ! else if (comp < 0) { ! movement.dx -= (node.getCenterX()+30-other.getCenterX()) / 10; ! } ! if (align) { ! movement.dy += (other.getCenterY() - node.getCenterY()) / 10; ! } ! } ! ! if (orientation == TOPTOBOTTOM) { ! if (comp < 0) { ! movement.dy += (other.getCenterY()-node.getCenterY()+distance) / 10; ! } ! else if (comp > 0) { ! movement.dy -= (node.getCenterY()-other.getCenterY()+distance) / 10; ! } ! if (align) { ! movement.dx += (other.getCenterX() - node.getCenterX()) / 10; ! } ! } ! ! if (orientation == LEFTTORIGHT) { ! if (comp > 0){ ! movement.dy += (other.getCenterY()-node.getCenterY()+30) / 10; ! } ! else if (comp < 0) { ! movement.dy -= (node.getCenterY()+30-other.getCenterY()) / 10; ! } ! if (align) { ! movement.dx += (other.getCenterX() - node.getCenterX()) / 10; ! } ! } } ! double dx = movement.dx; double dy = movement.dy; ! ! movement.dx=dx/2; ! movement.dy=dy/2; ! double distanceMoved=Math.max(dx,dy); // Don't move faster then 30 units at a time. Important in order to prevent severed nodes from flying away. --- 26,112 ---- public class SortedNodeLayouter extends AbstractFacet implements NodeLayouter { ! public static final int RIGHT = 0; ! public static final int LEFT = 1; ! public static final int DOWN = 2; ! public static final int UP = 3; ! int orientation = DOWN; ! public static final int TIME = 0; ! public static final int DATE = 1; ! public static final int STRING = 2; ! ! int datatype = STRING; ! ! boolean align = true; boolean proportional = false; ! float distance = 20.0f; ! String property = "http://xmlns.com/foaf/0.1/name"; ! ! private boolean sorted = false; ! private SortedNodeLayouterComparator comparator = new SortedNodeLayouterComparator(property); ! private boolean centered = false; ! Point2D centerPoint = new Point2D.Double(); /* ! * @see org.mediavirus.graphl.layout.NodeLayouter#performLayoutStep(org.mediavirus.graphl.graph.Node, org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager) */ public void performLayoutStep(Node node, GraphManager graphManager) { ! NodeMovement movement=graphManager.getNodeMovement(node); ! if (!sorted) { ! sortList(); ! } ! ! int num = assignedElements.size(); ! int pos = Collections.binarySearch(assignedElements, node, comparator); ! ! if (!node.isDragging()) { ! ! if (!centered) { ! center(); ! } ! ! float offset; ! if (proportional) { ! long min = getRelativeValue(((Node)assignedElements.get(0)).getProperty(property)); ! long max = getRelativeValue(((Node)assignedElements.get(assignedElements.size()-1)).getProperty(property)); ! long val = getRelativeValue(node.getProperty(property)); ! offset = (num-1) * distance * (val-min) / (max-min) - (distance * (num-1) / 2); ! } ! else { ! offset = (pos * distance) - (distance * (num-1) / 2); ! } ! switch (orientation) { ! case RIGHT: ! movement.dx = ((centerPoint.getX() + offset) - node.getCenterX()) / 4; ! break; ! case LEFT: ! movement.dx = ((centerPoint.getX() - offset) - node.getCenterX()) / 4; ! break; ! case DOWN: ! movement.dy = ((centerPoint.getY() + offset) - node.getCenterY()) / 4; ! break; ! case UP: ! movement.dy = ((centerPoint.getY() - offset) - node.getCenterY()) / 4; ! break; } ! ! if (align) { ! if (orientation == RIGHT || orientation == LEFT) { ! movement.dy = (centerPoint.getY() - node.getCenterY()) / 4; ! } ! else { ! movement.dx = (centerPoint.getX() - node.getCenterX()) / 4; ! } ! } ! double dx = movement.dx; double dy = movement.dy; ! double distanceMoved=Math.max(dx,dy); // Don't move faster then 30 units at a time. Important in order to prevent severed nodes from flying away. *************** *** 131,142 **** } else { - NodeMovement movement=graphManager.getNodeMovement(node); movement.justChanged=true; movement.dx=0; movement.dy=0; } } ! /* * @see org.mediavirus.graphl.view.Facet#hasVisualController() */ --- 122,195 ---- } else { movement.justChanged=true; movement.dx=0; movement.dy=0; + if (pos == 0 || pos == num-1) { + if (orientation == RIGHT || orientation == LEFT) { + centerPoint.setLocation(node.getCenterX() + (num-1-2*pos) * distance / 2, node.getCenterY()); + } + else { + centerPoint.setLocation(node.getCenterX(),node.getCenterY() + (num-1-2*pos) * distance / 2); + } + } } } + + /** + * + */ + private void center() { + double x=0, y=0; + int num = assignedElements.size(); + + for (Iterator iter = assignedElements.iterator(); iter.hasNext();) { + Node node = (Node) iter.next(); + x += node.getCenterX()/num; + y += node.getCenterY()/num; + } + + centerPoint.setLocation(x,y); + + centered = true; + + } ! long getRelativeValue(String str) { ! long val = 0; ! if ((datatype == TIME) || (datatype == DATE)) { ! Date date; ! try { ! date = DateFormat.getDateInstance().parse(str); ! } ! catch (ParseException pex) { ! return 0; ! } ! ! if (datatype == TIME) { ! return date.getTime(); ! } ! else { ! Calendar cal = Calendar.getInstance(); ! cal.setTime(date); ! return cal.get(Calendar.YEAR) * 365 + cal.get(Calendar.DAY_OF_YEAR); ! } ! } ! else if (datatype == STRING) { ! // TODO (2, 1h) improve this ! val = str.charAt(0) * 256 * 256 + str.charAt(1) * 256 + str.charAt(2); ! } ! ! return val; ! } ! ! /** ! * ! */ ! private void sortList() { ! Collections.sort(assignedElements, comparator); ! sorted = true; ! } ! ! /* * @see org.mediavirus.graphl.view.Facet#hasVisualController() */ *************** *** 152,167 **** } - /** - * @return Returns the align. - */ public boolean isAlign() { return align; } ! /** ! * @param align The align to set. ! */ public void setAlign(boolean align) { this.align = align; } /** * @return Returns the orientation. --- 205,216 ---- } public boolean isAlign() { return align; } ! public void setAlign(boolean align) { this.align = align; } + /** * @return Returns the orientation. *************** *** 176,190 **** this.orientation = orientation; } ! /** ! * @return Returns the proportional. ! */ public boolean isProportional() { return proportional; } ! /** ! * @param proportional The proportional to set. ! */ ! public void setProportional(boolean relative) { ! this.proportional = relative; } /* --- 225,235 ---- this.orientation = orientation; } ! public boolean isProportional() { return proportional; } ! ! public void setProportional(boolean proportional) { ! this.proportional = proportional; } /* *************** *** 222,225 **** --- 267,272 ---- public void setProperty(String property) { this.property = property; + comparator.setProperty(property); + sortList(); } /** *************** *** 229,237 **** return distance; } /** * @param distance The distance to set. */ ! public void setDistance(float scaleFactor) { ! this.distance = scaleFactor; } /** --- 276,304 ---- return distance; } + /** * @param distance The distance to set. */ ! public void setDistance(float distance) { ! this.distance = distance; ! } ! ! /** ! * @see org.mediavirus.graphl.view.Facet#assignElement(org.mediavirus.graphl.graph.GraphElement) ! */ ! ! public void assignElement(GraphElement element) { ! sorted = false; ! centered = false; ! super.assignElement(element); ! } ! ! /** ! * @see org.mediavirus.graphl.view.Facet#unassignElement(org.mediavirus.graphl.graph.GraphElement) ! */ ! ! public void unassignElement(GraphElement element) { ! centered = false; ! super.unassignElement(element); } /** *************** *** 257,273 **** str = node.getProperty("http://www.mediavirus.org/graphl#orientation"); if (str != null) { ! if (str.equalsIgnoreCase("TOPTOBOTTOM")) { ! setOrientation(TOPTOBOTTOM); } ! else if (str.equalsIgnoreCase("BOTTOMTOTOP")) { ! setOrientation(BOTTOMTOTOP); } ! else if (str.equalsIgnoreCase("LEFTTORIGHT")) { ! setOrientation(LEFTTORIGHT); } ! else if (str.equalsIgnoreCase("RIGHTTOLEFT")) { ! setOrientation(RIGHTTOLEFT); } } } } --- 324,377 ---- str = node.getProperty("http://www.mediavirus.org/graphl#orientation"); if (str != null) { ! if (str.equalsIgnoreCase("DOWN")) { ! setOrientation(DOWN); } ! else if (str.equalsIgnoreCase("UP")) { ! setOrientation(UP); } ! else if (str.equalsIgnoreCase("RIGHT")) { ! setOrientation(RIGHT); } ! else if (str.equalsIgnoreCase("LEFT")) { ! setOrientation(LEFT); } } } + + public class SortedNodeLayouterComparator implements Comparator { + + private String property = null; + + public SortedNodeLayouterComparator() {} + + public SortedNodeLayouterComparator(String property) { + this.property = property; + } + + /** + * @return Returns the property. + */ + public String getProperty() { + return property; + } + /** + * @param property The property to set. + */ + public void setProperty(String property) { + this.property = property; + } + + public int compare(Object o1, Object o2) { + Node n1 = (Node)o1; + Node n2 = (Node)o2; + + if (property != null) { + String val1 = n1.getProperty(property, "").toLowerCase(); + String val2 = n2.getProperty(property, "").toLowerCase(); + return val1.compareTo(val2); + } + else return 0; + } + + } } |
From: Flo L. <fl...@us...> - 2005-09-05 15:48:07
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15108/src/org/mediavirus/graphl/layout Modified Files: RepulsionNodeLayouter.java SortedNodeLayouter.java Log Message: changed some task priorities Index: RepulsionNodeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/RepulsionNodeLayouter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RepulsionNodeLayouter.java 24 Aug 2005 16:05:54 -0000 1.9 --- RepulsionNodeLayouter.java 5 Sep 2005 15:47:59 -0000 1.10 *************** *** 36,40 **** Node node2 = (Node)nodes.next(); if (node2 != node) { ! //TODO (2) see if node is in same subgraph, otherwise do not repulse NodeMovement movement2 = graphManager.getNodeMovement(node2); if (movement2 != null) { --- 36,40 ---- Node node2 = (Node)nodes.next(); if (node2 != node) { ! //TODO (3) see if node is in same subgraph, otherwise do not repulse NodeMovement movement2 = graphManager.getNodeMovement(node2); if (movement2 != null) { Index: SortedNodeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/SortedNodeLayouter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SortedNodeLayouter.java 17 Aug 2005 15:52:49 -0000 1.8 --- SortedNodeLayouter.java 5 Sep 2005 15:47:59 -0000 1.9 *************** *** 177,181 **** } else if (datatype == STRING) { ! // TODO (2, 1h) improve this val = str.charAt(0) * 256 * 256 + str.charAt(1) * 256 + str.charAt(2); } --- 177,181 ---- } else if (datatype == STRING) { ! // TODO (X, 1h) improve this val = str.charAt(0) * 256 * 256 + str.charAt(1) * 256 + str.charAt(2); } |