1 | dojo.provide("dojox.drawing.annotations.Arrow"); |
---|
2 | dojo.require("dojox.drawing.stencil.Path"); |
---|
3 | |
---|
4 | dojox.drawing.annotations.Arrow = dojox.drawing.util.oo.declare( |
---|
5 | // summary: |
---|
6 | // An annotation called internally to put an arrowhead |
---|
7 | // on ether end of a Line. Initiated in Arrow (and Vector) |
---|
8 | // with the optional params: arrowStart and arrowEnd. Both |
---|
9 | // default true for Axes. |
---|
10 | // |
---|
11 | dojox.drawing.stencil.Path, |
---|
12 | function(/* dojox.__stencilArgs */options){ |
---|
13 | // arguments: See stencil._Base |
---|
14 | this.stencil.connectMult([ |
---|
15 | [this.stencil, "select", this, "select"], |
---|
16 | [this.stencil, "deselect", this, "deselect"], |
---|
17 | [this.stencil, "render", this, "render"], |
---|
18 | [this.stencil, "onDelete", this, "destroy"] |
---|
19 | ]); |
---|
20 | |
---|
21 | this.connect("onBeforeRender", this, function(){ |
---|
22 | var o = this.stencil.points[this.idx1]; |
---|
23 | var c = this.stencil.points[this.idx2]; |
---|
24 | if(this.stencil.getRadius() >= this.minimumSize){ |
---|
25 | this.points = this.arrowHead(c.x, c.y, o.x, o.y, this.style); |
---|
26 | }else{ |
---|
27 | this.points = []; |
---|
28 | } |
---|
29 | }); |
---|
30 | |
---|
31 | }, |
---|
32 | { |
---|
33 | idx1:0, |
---|
34 | idx2:1, |
---|
35 | |
---|
36 | subShape:true, |
---|
37 | minimumSize:30, |
---|
38 | //annotation:true, NOT! |
---|
39 | |
---|
40 | arrowHead: function(x1, y1, x2, y2, style){ |
---|
41 | // summary: |
---|
42 | // Creates data used to draw arrow head. |
---|
43 | // |
---|
44 | var obj = { |
---|
45 | start:{ |
---|
46 | x:x1, |
---|
47 | y:y1 |
---|
48 | }, |
---|
49 | x:x2, |
---|
50 | y:y2 |
---|
51 | } |
---|
52 | var angle = this.util.angle(obj); |
---|
53 | |
---|
54 | var lineLength = this.util.length(obj); |
---|
55 | var al = style.arrows.length; |
---|
56 | var aw = style.arrows.width/2; |
---|
57 | if(lineLength<al){ |
---|
58 | al = lineLength/2; |
---|
59 | } |
---|
60 | var p1 = this.util.pointOnCircle(x2, y2, -al, angle-aw); |
---|
61 | var p2 = this.util.pointOnCircle(x2, y2, -al, angle+aw); |
---|
62 | |
---|
63 | return [ |
---|
64 | {x:x2, y:y2}, |
---|
65 | p1, |
---|
66 | p2 |
---|
67 | ]; |
---|
68 | } |
---|
69 | |
---|
70 | } |
---|
71 | ); |
---|