Author: kono
Date: 2012-01-03 19:45:28 -0800 (Tue, 03 Jan 2012)
New Revision: 27907
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
Log:
Handle location calculation modified.
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
2012-01-03 21:40:30 UTC (rev 27906)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/HandleImpl.java
2012-01-04 03:45:28 UTC (rev 27907)
@@ -12,117 +12,108 @@
*/
public class HandleImpl implements Handle {
-// private static final double MIN = Double.MIN_VALUE;
-// private static final double MAX = Double.MAX_VALUE;
-
private double x;
private double y;
-
- private Point2D ratio;
+ private double[] orthVector;
+ private double originalDist;
+ private double positionRatioOnEdge;
+
public HandleImpl(DGraphView graphView, DEdgeView view, final double x,
final double y) {
this.x = x;
- this.y = y;
+ this.y = y;
}
-// @Override
-// public double getXFraction(DGraphView graphView, DEdgeView view) {
-//
-// System.out.println("!!!!!! Get X called: " + x);
-// if(ratio == null)
-// return x;
-// else
-// return convertToAbsolute(true);
-// }
-//
-// @Override
-// public double getYFraction() {
-// System.out.println("!!!!!! Get Y called: " + y);
-// if(ratio == null)
-// return y;
-// else
-// return convertToAbsolute(false);
-// }
-
@Override
public Point2D getPoint(DGraphView graphView, DEdgeView view) {
return convertToAbsolute(graphView, view);
}
-
private Point2D convertToAbsolute(DGraphView graphView, DEdgeView view)
{
final CyNode source = view.getModel().getSource();
final CyNode target = view.getModel().getTarget();
final View<CyNode> sourceView = graphView.getNodeView(source);
final View<CyNode> targetView = graphView.getNodeView(target);
- final Double sourceX = sourceView
+ final Double sX = sourceView
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double sourceY = sourceView
+ final Double sY = sourceView
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
- final Double targetX = targetView
+ final Double tX = targetView
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double targetY = targetView
+ final Double tY = targetView
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
final Point2D newPoint = new Point2D.Double();
- if(ratio != null) {
- double newX = getAbsolute(sourceX, targetX, ratio.getX());
- double newY = getAbsolute(sourceY, targetY, ratio.getY());
- newPoint.setLocation(newX, newY);
+ if (orthVector != null) {
+ final double newDist = Math.sqrt(Math.pow(tX - sX, 2) +
Math.pow(tY - sY, 2));
+ final double newRatio = newDist / originalDist;
+ final double[] newOrth = new double[2];
+ newOrth[0] = orthVector[0] * newRatio;
+ newOrth[1] = orthVector[1] * newRatio;
+
+ final double newX = newOrth[0] + positionRatioOnEdge *
(tX - sX) + sX;
+ final double newY = newOrth[1] + positionRatioOnEdge *
(tY - sY) + sY;
+
+ newPoint.setLocation(newX, newY);
} else {
newPoint.setLocation(x, y);
}
-
+
return newPoint;
}
- private Point2D convertToRatio(DGraphView graphView, DEdgeView view,
final Point2D absolutePoint) {
- final Point2D relativePoint = new Point2D.Float();
+ private void convertToRatio(DGraphView graphView, DEdgeView view,
+ final Point2D absolutePoint) {
+ orthVector = new double[2];
+
final CyNode source = view.getModel().getSource();
final CyNode target = view.getModel().getTarget();
final View<CyNode> sourceView = graphView.getNodeView(source);
final View<CyNode> targetView = graphView.getNodeView(target);
- final Double sourceX = sourceView
+ final Double sX = sourceView
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double sourceY = sourceView
+ final Double sY = sourceView
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
- final Double targetX = targetView
+ final Double tX = targetView
.getVisualProperty(DVisualLexicon.NODE_X_LOCATION);
- final Double targetY = targetView
+ final Double tY = targetView
.getVisualProperty(DVisualLexicon.NODE_Y_LOCATION);
- final double xRatio = getRatio(sourceX, targetX,
absolutePoint.getX());
- final double yRatio = getRatio(sourceY, targetY,
absolutePoint.getY());
-
- relativePoint.setLocation(xRatio, yRatio);
-
- return relativePoint;
- }
+ final double hX = absolutePoint.getX();
+ final double hY = absolutePoint.getY();
- private double getRatio(double p1, double p2, double p) {
- final double distance = Math.abs(p2-p1);
- if(distance == 0)
- return 0.5;
- else
- return (p-p1)/distance;
+ final double oX;
+ final double oY;
+ final double k;
+
+ // Solved the equation to find orthogonal vector manually...
Can be replaced once we find better 2D Vector library.
+ k = -((tX - sY) * (sX - tX) + (tY - sY) * (sY - tY))
+ / (hX * tX - hX * sX + hY * tY - hY * sY + sX *
sX - sX * tX
+ + sY * sY - sY * tY);
+ oX = (tX - sX + k * sX) / k;
+ oY = (tY - sY + k * sY) / k;
+
+ orthVector[0] = hX - oX;
+ orthVector[1] = hY - oY;
+
+ originalDist = Math.sqrt(Math.pow(tX - sX, 2) + Math.pow(tY -
sY, 2));
+ positionRatioOnEdge = Math.sqrt(Math.pow(oX - sX, 2)
+ + Math.pow(oY - sY, 2))
+ / originalDist;
}
-
- private double getAbsolute(double p1, double p2, double r) {
- final double distance = Math.abs(p2-p1);
- return p1 + (distance * r);
- }
@Override
- public void setPoint(DGraphView graphView, DEdgeView view, double x,
double y) {
+ public void setPoint(DGraphView graphView, DEdgeView view, double x,
+ double y) {
this.x = x;
this.y = y;
- ratio = convertToRatio(graphView, view, new Point2D.Double(x,
y));
+ convertToRatio(graphView, view, new Point2D.Double(x, y));
}
}
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
2012-01-03 21:40:30 UTC (rev 27906)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/editor/EdgeBendValueEditor.java
2012-01-04 03:45:28 UTC (rev 27907)
@@ -39,7 +39,7 @@
private static final long serialVersionUID = 9145223127932839836L;
- private static final Dimension DEF_PANEL_SIZE = new Dimension(600, 300);
+ private static final Dimension DEF_PANEL_SIZE = new Dimension(600, 350);
private static final Color NODE_COLOR = Color.gray;
private static final Color EDGE_COLOR = Color.BLACK;
@@ -101,6 +101,12 @@
sourceView.setVisualProperty(RichVisualLexicon.NODE_FILL_COLOR,
NODE_COLOR);
targetView.setVisualProperty(RichVisualLexicon.NODE_FILL_COLOR,
NODE_COLOR);
+
sourceView.setVisualProperty(RichVisualLexicon.NODE_LABEL_COLOR, Color.WHITE);
+
targetView.setVisualProperty(RichVisualLexicon.NODE_LABEL_COLOR, Color.WHITE);
+
sourceView.setVisualProperty(RichVisualLexicon.NODE_LABEL_FONT_SIZE, 16);
+
targetView.setVisualProperty(RichVisualLexicon.NODE_LABEL_FONT_SIZE, 16);
+ sourceView.setVisualProperty(RichVisualLexicon.NODE_LABEL, "S");
+ targetView.setVisualProperty(RichVisualLexicon.NODE_LABEL, "T");
sourceView.setVisualProperty(RichVisualLexicon.NODE_SHAPE,
NodeShapeVisualProperty.ELLIPSE);
targetView.setVisualProperty(RichVisualLexicon.NODE_SHAPE,
NodeShapeVisualProperty.ELLIPSE);
@@ -114,6 +120,7 @@
edgeView.setVisualProperty(RichVisualLexicon.EDGE_WIDTH, 4d);
edgeView.setVisualProperty(RichVisualLexicon.EDGE_TARGET_ARROW_SHAPE,
ArrowShapeVisualProperty.ARROW);
edgeView.setVisualProperty(DVisualLexicon.EDGE_TARGET_ARROW_UNSELECTED_PAINT,
EDGE_COLOR);
+ edgeView.setVisualProperty(DVisualLexicon.EDGE_CURVED, true);
final Bend newBend = new BendImpl();
edgeView.setVisualProperty(DVisualLexicon.EDGE_BEND, newBend);
@@ -121,7 +128,7 @@
dummyview.getNodeView(source).setVisualProperty(NODE_X_LOCATION, 0d);
dummyview.getNodeView(source).setVisualProperty(NODE_Y_LOCATION, 20d);
-
dummyview.getNodeView(target).setVisualProperty(NODE_X_LOCATION, 200d);
+
dummyview.getNodeView(target).setVisualProperty(NODE_X_LOCATION, 300d);
dummyview.getNodeView(target).setVisualProperty(NODE_Y_LOCATION, 0d);
innerPanel.setBackground(BACKGROUND_COLOR);
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.