root / trunk / web / dojo / dojox / sketch / LeadAnnotation.js @ 9
History | View | Annotate | Download (4.5 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.sketch.LeadAnnotation"]){ |
9 |
dojo._hasResource["dojox.sketch.LeadAnnotation"]=true; |
10 |
dojo.provide("dojox.sketch.LeadAnnotation");
|
11 |
dojo.require("dojox.sketch.Annotation");
|
12 |
dojo.require("dojox.sketch.Anchor");
|
13 |
(function(){
|
14 |
var ta=dojox.sketch;
|
15 |
ta.LeadAnnotation=function(_1,id){ |
16 |
ta.Annotation.call(this,_1,id);
|
17 |
this.transform={dx:0,dy:0}; |
18 |
this.start={x:0,y:0}; |
19 |
this.control={x:100,y:-50}; |
20 |
this.end={x:200,y:0}; |
21 |
this.textPosition={x:0,y:0}; |
22 |
this.textOffset=4; |
23 |
this.textYOffset=10; |
24 |
this.pathShape=null; |
25 |
this.labelShape=null; |
26 |
this.anchors.start=new ta.Anchor(this,"start"); |
27 |
this.anchors.control=new ta.Anchor(this,"control"); |
28 |
this.anchors.end=new ta.Anchor(this,"end"); |
29 |
}; |
30 |
ta.LeadAnnotation.prototype=new ta.Annotation;
|
31 |
var p=ta.LeadAnnotation.prototype;
|
32 |
p.constructor=ta.LeadAnnotation; |
33 |
p.type=function(){ |
34 |
return "Lead"; |
35 |
}; |
36 |
p.getType=function(){ |
37 |
return ta.LeadAnnotation;
|
38 |
}; |
39 |
p._pos=function(){ |
40 |
var _2=this.textOffset,x=0,y=0; |
41 |
var _3=this.calculate.slope(this.control,this.end); |
42 |
this.textAlign="middle"; |
43 |
if(Math.abs(_3)>=1){ |
44 |
x=this.end.x+this.calculate.dx(this.control,this.end,_2); |
45 |
if(this.control.y>this.end.y){ |
46 |
y=this.end.y-_2;
|
47 |
}else{
|
48 |
y=this.end.y+_2+this.textYOffset; |
49 |
} |
50 |
}else{
|
51 |
if(_3==0){ |
52 |
x=this.end.x+_2;
|
53 |
y=this.end.y+this.textYOffset; |
54 |
}else{
|
55 |
if(this.start.x>this.end.x){ |
56 |
x=this.end.x-_2;
|
57 |
this.textAlign="end"; |
58 |
}else{
|
59 |
x=this.end.x+_2;
|
60 |
this.textAlign="start"; |
61 |
} |
62 |
if(this.start.y<this.end.y){ |
63 |
y=this.end.y+this.calculate.dy(this.control,this.end,_2)+this.textYOffset; |
64 |
}else{
|
65 |
y=this.end.y+this.calculate.dy(this.control,this.end,-_2); |
66 |
} |
67 |
} |
68 |
} |
69 |
this.textPosition={x:x,y:y}; |
70 |
}; |
71 |
p.apply=function(_4){ |
72 |
if(!_4){
|
73 |
return;
|
74 |
} |
75 |
if(_4.documentElement){
|
76 |
_4=_4.documentElement; |
77 |
} |
78 |
this.readCommonAttrs(_4);
|
79 |
for(var i=0;i<_4.childNodes.length;i++){ |
80 |
var c=_4.childNodes[i];
|
81 |
if(c.localName=="text"){ |
82 |
this.property("label",c.childNodes.length?c.childNodes[0].nodeValue:""); |
83 |
}else{
|
84 |
if(c.localName=="path"){ |
85 |
var d=c.getAttribute("d").split(" "); |
86 |
var s=d[0].split(","); |
87 |
this.start.x=parseFloat(s[0].substr(1),10); |
88 |
this.start.y=parseFloat(s[1],10); |
89 |
s=d[1].split(","); |
90 |
this.control.x=parseFloat(s[0].substr(1),10); |
91 |
this.control.y=parseFloat(s[1],10); |
92 |
s=d[2].split(","); |
93 |
this.end.x=parseFloat(s[0],10); |
94 |
this.end.y=parseFloat(s[1],10); |
95 |
var _5=this.property("stroke"); |
96 |
var _6=c.getAttribute("style"); |
97 |
var m=_6.match(/stroke:([^;]+);/); |
98 |
if(m){
|
99 |
_5.color=m[1];
|
100 |
this.property("fill",m[1]); |
101 |
} |
102 |
m=_6.match(/stroke-width:([^;]+);/);
|
103 |
if(m){
|
104 |
_5.width=m[1];
|
105 |
} |
106 |
this.property("stroke",_5); |
107 |
} |
108 |
} |
109 |
} |
110 |
}; |
111 |
p.initialize=function(_7){ |
112 |
this.apply(_7);
|
113 |
this._pos();
|
114 |
this.shape=this.figure.group.createGroup(); |
115 |
this.shape.getEventSource().setAttribute("id",this.id); |
116 |
this.pathShape=this.shape.createPath("M"+this.start.x+","+this.start.y+" Q"+this.control.x+","+this.control.y+" "+this.end.x+","+this.end.y+" l0,0"); |
117 |
this.labelShape=this.shape.createText({x:this.textPosition.x,y:this.textPosition.y,text:this.property("label"),align:this.textAlign}); |
118 |
this.labelShape.getEventSource().setAttribute("id",this.id+"-labelShape"); |
119 |
this.draw();
|
120 |
}; |
121 |
p.destroy=function(){ |
122 |
if(!this.shape){ |
123 |
return;
|
124 |
} |
125 |
this.shape.remove(this.pathShape); |
126 |
this.shape.remove(this.labelShape); |
127 |
this.figure.group.remove(this.shape); |
128 |
this.shape=this.pathShape=this.labelShape=null; |
129 |
}; |
130 |
p.getBBox=function(){ |
131 |
var x=Math.min(this.start.x,this.control.x,this.end.x); |
132 |
var y=Math.min(this.start.y,this.control.y,this.end.y); |
133 |
var w=Math.max(this.start.x,this.control.x,this.end.x)-x; |
134 |
var h=Math.max(this.start.y,this.control.y,this.end.y)-y; |
135 |
return {x:x,y:y,width:w,height:h}; |
136 |
}; |
137 |
p.draw=function(_8){ |
138 |
this.apply(_8);
|
139 |
this._pos();
|
140 |
this.shape.setTransform(this.transform); |
141 |
this.pathShape.setShape("M"+this.start.x+","+this.start.y+" Q"+this.control.x+","+this.control.y+" "+this.end.x+","+this.end.y+" l0,0"); |
142 |
this.labelShape.setShape({x:this.textPosition.x,y:this.textPosition.y,text:this.property("label")}).setFill(this.property("fill")); |
143 |
this.zoom();
|
144 |
}; |
145 |
p.serialize=function(){ |
146 |
var _9=this.property("stroke"); |
147 |
return "<g "+this.writeCommonAttrs()+">"+"<path style=\"stroke:"+_9.color+";stroke-width:"+_9.width+";fill:none;\" d=\""+"M"+this.start.x+","+this.start.y+" "+"Q"+this.control.x+","+this.control.y+" "+this.end.x+","+this.end.y+"\" />"+"<text style=\"fill:"+_9.color+";text-anchor:"+this.textAlign+"\" font-weight=\"bold\" "+"x=\""+this.textPosition.x+"\" "+"y=\""+this.textPosition.y+"\">"+this.property("label")+"</text>"+"</g>"; |
148 |
}; |
149 |
ta.Annotation.register("Lead");
|
150 |
})(); |
151 |
} |