summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/drawing/util/positioning.js
diff options
context:
space:
mode:
authorTristan Zur <tzur@web.web.ccwn.org>2014-03-27 22:27:47 +0100
committerTristan Zur <tzur@web.web.ccwn.org>2014-03-27 22:27:47 +0100
commitb62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch)
tree86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /js/dojo-1.6/dojox/drawing/util/positioning.js
Initial commit of intern.ccwn.org contentsHEADmaster
Diffstat (limited to 'js/dojo-1.6/dojox/drawing/util/positioning.js')
-rw-r--r--js/dojo-1.6/dojox/drawing/util/positioning.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/js/dojo-1.6/dojox/drawing/util/positioning.js b/js/dojo-1.6/dojox/drawing/util/positioning.js
new file mode 100644
index 0000000..6a0b1f9
--- /dev/null
+++ b/js/dojo-1.6/dojox/drawing/util/positioning.js
@@ -0,0 +1,75 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.drawing.util.positioning"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.drawing.util.positioning"] = true;
+dojo.provide("dojox.drawing.util.positioning");
+
+(function(){
+
+ var textOffset = 4; // distance from line to text box
+ var textYOffset = 20; // height of text box
+
+
+ dojox.drawing.util.positioning.label = function(/*Object*/start, /*Object*/end){
+ // summary:
+ // Returns the optimal text positions for annotations.Label.
+
+ // label at middle of vector
+ var x = 0.5*(start.x+end.x);
+ var y = 0.5*(start.y+end.y);
+
+ // move label a set distance from the line
+ var slope = dojox.drawing.util.common.slope(start, end);
+ var deltay = textOffset/Math.sqrt(1.0+slope*slope);
+
+ if(end.y>start.y && end.x>start.x || end.y<start.y && end.x<start.x){
+ // Position depending on quadrant. Y offset
+ // positions box aligned vertically from top
+ deltay = -deltay;
+ y -= textYOffset;
+ }
+ x += -deltay*slope;
+ y += deltay;
+
+ // want text to be away from start of vector
+ // This will make force diagrams less crowded
+ var align = end.x<start.x ? "end" : "start";
+
+ return { x:x, y:y, foo:"bar", align:align}; // Object
+ };
+
+ dojox.drawing.util.positioning.angle = function(/*Object*/start, /*Object*/end){
+ // summary:
+ // Returns the optimal position for annotations.Angle.
+ //
+ // angle at first third of vector
+ var x = 0.7*start.x+0.3*end.x;
+ var y = 0.7*start.y+0.3*end.y;
+ // move label a set distance from the line
+ var slope = dojox.drawing.util.common.slope(start, end);
+ var deltay = textOffset/Math.sqrt(1.0+slope*slope);
+
+ if(end.x<start.x){deltay = -deltay;}
+ x += -deltay * slope;
+ y += deltay;
+
+ // want text to be clockwise from vector
+ // to match angle measurement from x-axis
+ var align = end.y>start.y ? "end" : "start";
+ // box vertical aligned from middle
+ y += end.x > start.x ? 0.5*textYOffset : -0.5*textYOffset;
+
+ return { x:x, y:y, align:align}; // Object
+ }
+
+})();
+
+
+
+
+}