[graphl-cvs] graphl/src/org/mediavirus/graphl/layout SortedNodeLayouter.java DirectedEdgeLayouter.ja
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2005-12-18 11:11:53
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2618/src/org/mediavirus/graphl/layout Modified Files: SortedNodeLayouter.java DirectedEdgeLayouter.java SpringEdgeLayouter.java GraphlLayoutStrategy.java Log Message: - FEATURE: RXPath landed! you can assign properties of facets through XPath-like expressions based on the currently rendered node - CODE: Remove LabelGenerator classes - this can now done with RXPath - CODE: migrated to JDK 1.5, added class specifiers for all collections (generics) - CODE: added a singleton GraphlRegistry, currently only holding the vocabularyRegistry instance Index: GraphlLayoutStrategy.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/GraphlLayoutStrategy.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GraphlLayoutStrategy.java 24 Aug 2005 16:05:54 -0000 1.12 --- GraphlLayoutStrategy.java 18 Dec 2005 11:11:40 -0000 1.13 *************** *** 89,93 **** */ public void executeGraphLayoutStep() { ! long layoutStartTime=System.currentTimeMillis(); for (int i=0;i<10;i++) { layoutEdges(); --- 89,93 ---- */ public void executeGraphLayoutStep() { ! //long layoutStartTime=System.currentTimeMillis(); for (int i=0;i<10;i++) { layoutEdges(); *************** *** 95,99 **** damp(); } ! long layoutDuration = System.currentTimeMillis()-layoutStartTime; //if (layoutDuration > 0) System.out.println("layout time: " + layoutDuration + " FPS: " + 1000.0/layoutDuration); } --- 95,99 ---- damp(); } ! //long layoutDuration = System.currentTimeMillis()-layoutStartTime; //if (layoutDuration > 0) System.out.println("layout time: " + layoutDuration + " FPS: " + 1000.0/layoutDuration); } *************** *** 296,300 **** protected class GraphManager extends ListOfNodes { /** The node movement objects indexed by the node. */ ! protected Map nodeMovements; /** The maximum motion value after the last move. Used to see when the graph is stabilizinh. */ --- 296,300 ---- protected class GraphManager extends ListOfNodes { /** The node movement objects indexed by the node. */ ! protected Map<Node, NodeMovement> nodeMovements; /** The maximum motion value after the last move. Used to see when the graph is stabilizinh. */ *************** *** 302,306 **** public GraphManager() { ! nodeMovements=new HashMap(); } public SubGraph getFirstSubGraph() { --- 302,306 ---- public GraphManager() { ! nodeMovements=new HashMap<Node, NodeMovement>(); } public SubGraph getFirstSubGraph() { Index: DirectedEdgeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/DirectedEdgeLayouter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DirectedEdgeLayouter.java 17 Aug 2005 15:52:49 -0000 1.2 --- DirectedEdgeLayouter.java 18 Dec 2005 11:11:40 -0000 1.3 *************** *** 26,33 **** float length = 100.0f; - public double getLength(Edge edge) { - return edge.getLength(); - } - public void performLayoutStep(Edge edge, GraphManager manager) { Node from=edge.getFrom(); --- 26,29 ---- *************** *** 100,124 **** this.direction = direction; } - - /** - * @return Returns the length. - */ - public float getLength() { - return length; - } - /** - * @param length The length to set. - */ - public void setLength(float length) { - this.length = length; - } public void setConfigurationNode(Node node) { ! String str = node.getProperty(NS.graphl + "length"); ! if (str != null) { ! setLength(Float.parseFloat(str)); ! } ! str = node.getProperty(NS.graphl + "direction"); if ( str != null) { if (str.equalsIgnoreCase("up")) { --- 96,103 ---- this.direction = direction; } public void setConfigurationNode(Node node) { ! String str = node.getProperty(NS.graphl + "direction"); if ( str != null) { if (str.equalsIgnoreCase("up")) { Index: SpringEdgeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/SpringEdgeLayouter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SpringEdgeLayouter.java 17 Aug 2005 15:52:49 -0000 1.9 --- SpringEdgeLayouter.java 18 Dec 2005 11:11:40 -0000 1.10 *************** *** 2,8 **** * Created on 09.06.2004 by Flo Ledermann <led...@im...> */ ! package org.mediavirus.graphl.layout; import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; --- 2,12 ---- * Created on 09.06.2004 by Flo Ledermann <led...@im...> */ ! package org.mediavirus.graphl.layout; + import java.util.HashMap; + import java.util.Map; + + import org.apache.commons.jxpath.JXPathContext; import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; *************** *** 11,15 **** import org.mediavirus.graphl.vocabulary.NS; - /** * @author Flo Ledermann <led...@im...> --- 15,18 ---- *************** *** 19,66 **** float defaultLength = 40.0f; ! String lengthProperty = null; ! ! float lengthFactor = 1.0f; ! ! /** The rigidity has the same effect as the damper, except that it is a constant. */ ! float rigidity = 1.0f; ! /* ! * Overrides @see org.mediavirus.graphl.layout.EdgeLayouter#getLength(org.mediavirus.graphl.RDFEdge) ! */ ! public double getLength(Edge edge) { ! return edge.getLength(); } /* * Overrides @see org.mediavirus.graphl.layout.EdgeLayouter#relaxEdge(org.mediavirus.graphl.RDFEdge) */ public void performLayoutStep(Edge edge, GraphManager manager) { ! float length = defaultLength; ! if (lengthProperty != null) { ! String str = edge.getProperty(lengthProperty); ! if (str != null) { ! try { ! length = Float.parseFloat(str); } ! catch (NumberFormatException nfex) { ! // do nothing } } } ! Node from=edge.getFrom(); ! Node to=edge.getTo(); ! double deltaX=to.getCenterX()-from.getCenterX(); ! double deltaY=to.getCenterY()-from.getCenterY(); ! double currentLength=Math.sqrt(deltaX*deltaX+deltaY*deltaY); ! double factor=rigidity*currentLength/(length*100.0f*lengthFactor); ! double dx=deltaX*factor; ! double dy=deltaY*factor; // Edges pull directly in proportion to the distance between the nodes. This is good, // because we want the edges to be stretchy. The edges are ideal rubberbands. // They don't become springs when they are too short. That only causes the graph to oscillate. ! ! manager.getNodeMovement(from).applyDelta(dx,dy); ! manager.getNodeMovement(to).applyDelta(-dx,-dy); } --- 22,97 ---- float defaultLength = 40.0f; ! float defaultRigidity = 1.0f; ! String lengthExpr; ! String rigidityExpr; ! ! //TODO (3) this should be moved to EdgeView! ! class Spring { ! ! protected float length; ! protected float rigidity; ! ! protected Spring(float length, float rigidity) { ! ! this.length = length; ! this.rigidity = rigidity; ! } } + protected Map<Edge, Spring> springCache = new HashMap<Edge, Spring>(); + /* * Overrides @see org.mediavirus.graphl.layout.EdgeLayouter#relaxEdge(org.mediavirus.graphl.RDFEdge) */ public void performLayoutStep(Edge edge, GraphManager manager) { ! ! Spring spring = springCache.get(edge); ! ! if (spring == null) { ! float length = defaultLength; ! float rigidity = defaultRigidity; ! ! if (lengthExpr != null || rigidityExpr != null) { ! JXPathContext context = JXPathContext.newContext(edge); ! context.setLenient(true); ! if (lengthExpr != null) { ! Object lengthO = context.getValue(lengthExpr); ! try { ! length = ((Double) lengthO).floatValue(); ! } ! catch (Exception ex) { ! } } ! ! if (rigidityExpr != null) { ! Object rigidityO = context.getValue(rigidityExpr); ! try { ! rigidity = ((Double) rigidityO).floatValue(); ! } ! catch (Exception ex) { ! } } } + + spring = new Spring(length, rigidity); + springCache.put(edge, spring); + } ! ! Node from = edge.getFrom(); ! Node to = edge.getTo(); ! double deltaX = to.getCenterX() - from.getCenterX(); ! double deltaY = to.getCenterY() - from.getCenterY(); ! double currentLength = Math.sqrt(deltaX * deltaX + deltaY * deltaY); ! double factor = spring.rigidity * currentLength / (spring.length * 100.0f); ! double dx = deltaX * factor; ! double dy = deltaY * factor; // Edges pull directly in proportion to the distance between the nodes. This is good, // because we want the edges to be stretchy. The edges are ideal rubberbands. // They don't become springs when they are too short. That only causes the graph to oscillate. ! ! manager.getNodeMovement(from).applyDelta(dx, dy); ! manager.getNodeMovement(to).applyDelta(-dx, -dy); } *************** *** 73,77 **** public String toString() { ! return getName(); } --- 104,108 ---- public String toString() { ! return getName(); } *************** *** 83,86 **** --- 114,147 ---- } + + public float getDefaultRigidity() { + return defaultRigidity; + } + + + public void setDefaultRigidity(float defaultRigidity) { + this.defaultRigidity = defaultRigidity; + } + + + public String getLengthExpr() { + return lengthExpr; + } + + + public void setLengthExpr(String lengthExpr) { + this.lengthExpr = lengthExpr; + } + + + public String getRigidityExpr() { + return rigidityExpr; + } + + + public void setRigidityExpr(String rigidityExpr) { + this.rigidityExpr = rigidityExpr; + } + /* * Overrides @see org.mediavirus.graphl.Facet#isSameClass(java.lang.Object) *************** *** 94,106 **** */ public Object clone() { SpringEdgeLayouter l = new SpringEdgeLayouter(); l.setDefaultLength(defaultLength); ! l.setLengthFactor(lengthFactor); ! l.setLengthProperty(lengthProperty); ! l.setRigidity(rigidity); return l; } - - /** --- 155,168 ---- */ public Object clone() { + SpringEdgeLayouter l = new SpringEdgeLayouter(); + l.setDefaultLength(defaultLength); ! l.setDefaultRigidity(defaultRigidity); ! l.setLengthExpr(lengthExpr); ! l.setRigidityExpr(rigidityExpr); ! return l; } /** *************** *** 109,133 **** public void setConfigurationNode(Node node) { ! String str = node.getProperty(NS.graphl + "lengthFactor"); ! if (str != null) { ! setLengthFactor(Float.parseFloat(str)); ! } ! str = node.getProperty(NS.graphl + "lengthProperty"); ! if ( str != null) { ! setLengthProperty(str); ! } ! str = node.getProperty(NS.graphl + "defaultLength"); ! if (str != null) { ! setDefaultLength(Float.parseFloat(str)); ! } ! str = node.getProperty(NS.graphl + "rigidity"); ! if (str != null) { ! setRigidity(Float.parseFloat(str)); ! } ! } ! ! public String getName() { ! return "Spring"; ! } /** --- 171,193 ---- public void setConfigurationNode(Node node) { ! ! lengthExpr = node.getProperty(NS.graphl + "length"); ! rigidityExpr = node.getProperty(NS.graphl + "rigidity"); ! ! String str = node.getProperty(NS.graphl + "defaultLength"); ! if (str != null) { ! setDefaultLength(Float.parseFloat(str)); ! } ! ! str = node.getProperty(NS.graphl + "defaultRigidity"); ! if (str != null) { ! setDefaultRigidity(Float.parseFloat(str)); ! } ! ! } ! ! public String getName() { ! return "Spring"; ! } /** *************** *** 137,140 **** --- 197,201 ---- return defaultLength; } + /** * @param defaultLength The defaultLength to set. *************** *** 143,181 **** this.defaultLength = defaultLength; } ! /** ! * @return Returns the lengthFactor. ! */ ! public float getLengthFactor() { ! return lengthFactor; ! } ! /** ! * @param lengthFactor The lengthFactor to set. ! */ ! public void setLengthFactor(float lengthFactor) { ! this.lengthFactor = lengthFactor; ! } ! /** ! * @return Returns the lengthProperty. ! */ ! public String getLengthProperty() { ! return lengthProperty; ! } ! /** ! * @param lengthProperty The lengthProperty to set. ! */ ! public void setLengthProperty(String lengthProperty) { ! this.lengthProperty = lengthProperty; ! } ! /** ! * @return Returns the rigidity. ! */ ! public float getRigidity() { ! return rigidity; ! } ! /** ! * @param rigidity The rigidity to set. ! */ ! public void setRigidity(float rigidity) { ! this.rigidity = rigidity; ! } } --- 204,207 ---- this.defaultLength = defaultLength; } ! } Index: SortedNodeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/SortedNodeLayouter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SortedNodeLayouter.java 5 Sep 2005 15:47:59 -0000 1.9 --- SortedNodeLayouter.java 18 Dec 2005 11:11:40 -0000 1.10 *************** *** 64,67 **** --- 64,68 ---- int num = assignedElements.size(); + int pos = Collections.binarySearch(assignedElements, node, comparator); *************** *** 340,344 **** } ! public class SortedNodeLayouterComparator implements Comparator { private String property = null; --- 341,346 ---- } ! // TODO this should be Comparator<Node>, generics have to be fixed in AbstractFacet etc. ! public class SortedNodeLayouterComparator implements Comparator<GraphElement> { private String property = null; *************** *** 363,378 **** } ! 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; } ! } } --- 365,377 ---- } ! public int compare(GraphElement n1, GraphElement n2) { if (property != null) { ! String val1 = ((Node)n1).getProperty(property, "").toLowerCase(); ! String val2 = ((Node)n2).getProperty(property, "").toLowerCase(); return val1.compareTo(val2); } else return 0; } ! } } |