Debian Codegraph @

dojox/drawing/util/positioning.js

raw symbols SCIP
1 define(['./common'], function(common){
2
3 var textOffset = 4; // distance from line to text box
4 var textYOffset = 20; // height of text box
5
6 var positioning = {};
7 positioning.label = function(/*Object*/start, /*Object*/end){
8 // summary:
9 // Returns the optimal text positions for annotations.Label.
10
11 // label at middle of vector
12 var x = 0.5*(start.x+end.x);
13 var y = 0.5*(start.y+end.y);
14
15 // move label a set distance from the line
16 var slope = common.slope(start, end);
17 var deltay = textOffset/Math.sqrt(1.0+slope*slope);
18
19 if(end.y>start.y && end.x>start.x || end.y<start.y && end.x<start.x){
20 // Position depending on quadrant. Y offset
21 // positions box aligned vertically from top
22 deltay = -deltay;
23 y -= textYOffset;
24 }
25 x += -deltay*slope;
26 y += deltay;
27
28 // want text to be away from start of vector
29 // This will make force diagrams less crowded
30 var align = end.x<start.x ? "end" : "start";
31
32 return { x:x, y:y, foo:"bar", align:align}; // Object
33 };
34
35 positioning.angle = function(/*Object*/start, /*Object*/end){
36 // summary:
37 // Returns the optimal position for annotations.Angle.
38
39 // angle at first third of vector
40 var x = 0.7*start.x+0.3*end.x;
41 var y = 0.7*start.y+0.3*end.y;
42
43 // move label a set distance from the line
44 var slope = common.slope(start, end);
45 var deltay = textOffset/Math.sqrt(1.0+slope*slope);
46
47 if(end.x<start.x){deltay = -deltay;}
48 x += -deltay * slope;
49 y += deltay;
50
51 // want text to be clockwise from vector
52 // to match angle measurement from x-axis
53 var align = end.y>start.y ? "end" : "start";
54 // box vertical aligned from middle
55 y += end.x > start.x ? 0.5*textYOffset : -0.5*textYOffset;
56
57 return { x:x, y:y, align:align}; // Object
58 };
59
60 return positioning;
61 });
62