Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / drawing / tools / custom / Axes.js

History | View | Annotate | Download (9.43 KB)

1 9 andrej.cim
/*
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.drawing.tools.custom.Axes"]){
9
dojo._hasResource["dojox.drawing.tools.custom.Axes"]=true;
10
dojo.provide("dojox.drawing.tools.custom.Axes");
11
dojo.require("dojox.drawing.stencil.Path");
12
dojox.drawing.tools.custom.Axes=dojox.drawing.util.oo.declare(dojox.drawing.stencil.Path,function(_1){
13
this.closePath=false;
14
this.xArrow=new dojox.drawing.annotations.Arrow({stencil:this,idx1:0,idx2:1});
15
this.yArrow=new dojox.drawing.annotations.Arrow({stencil:this,idx1:2,idx2:1});
16
if(_1.data){
17
this.style.zAxisEnabled=_1.data.cosphi==1?true:false;
18
this.setData(_1.data);
19
}
20
if(this.style.zAxisEnabled){
21
this.data.cosphi=1;
22
var _2={};
23
dojo.mixin(_2,_1);
24
dojo.mixin(_2,{container:this.container.createGroup(),style:this.style,showAngle:false,label:null});
25
if(_1.data&&(!_2.data.radius||!_2.data.angle)){
26
_2.data.x2=_2.data.x4;
27
_2.data.y2=_2.data.y4;
28
}
29
_2.style.zAxis=true;
30
this.zAxis=new dojox.drawing.tools.custom.Vector(_2);
31
this.zAxis.minimumSize=5;
32
this.connectMult([[this,"onChangeStyle",this.zAxis,"onChangeStyle"],[this,"select",this.zAxis,"select"],[this,"deselect",this.zAxis,"deselect"],[this,"onDelete",this.zAxis,"destroy"],[this,"onDrag",this,"zSet"],[this,"onTransform",this,"zSet"],[this.zAxis,"onBeforeRender",this,"zSet"],[this,"_onPostRender",this.zAxis,"render"]]);
33
}
34
if(this.points&&this.points.length){
35
this.setPoints=this._postSetPoints;
36
this.render();
37
_1.label&&this.setLabel(_1.label);
38
_1.shadow&&this.addShadow(_1.shadow);
39
}
40
},{draws:true,type:"dojox.drawing.tools.custom.Axes",minimumSize:30,showAngle:true,closePath:false,baseRender:false,zScale:0.5,zPoint:function(_3){
41
_3.radius=this.util.length(_3);
42
var pt=this.util.pointOnCircle(_3.start.x,_3.start.y,_3.radius*this.zScale,this.style.zAngle);
43
return {x:pt.x,y:pt.y,skip:true,noAnchor:true};
44
},zSet:function(){
45
if(!this.zAxis){
46
return;
47
}
48
var c=this.points[1];
49
var z=this.points[3];
50
var p=[{x:c.x,y:c.y},{x:z.x,y:z.y}];
51
var _4=this.util.length({start:{x:c.x,y:c.y},x:z.x,y:z.y});
52
_4>this.zAxis.minimumSize?this.zAxis.setPoints(p):false;
53
this.zAxis.cosphi=1;
54
},createLabels:function(){
55
var _5={align:"middle",valign:"middle",util:this.util,annotation:true,container:this.container,mouse:this.mouse,stencil:this};
56
this.labelX=new dojox.drawing.annotations.Label(dojo.mixin(_5,{labelPosition:this.setLabelX}));
57
this.labelY=new dojox.drawing.annotations.Label(dojo.mixin(_5,{labelPosition:this.setLabelY}));
58
if(this.style.zAxisEnabled){
59
this.labelZ=new dojox.drawing.annotations.Label(dojo.mixin(_5,{labelPosition:this.setLabelZ}));
60
}
61
},setLabelX:function(){
62
var ax=this.points[0];
63
var c=this.points[1];
64
var _6=40;
65
var _7=20;
66
var pt,px,py,_8;
67
pt=this.util.lineSub(c.x,c.y,ax.x,ax.y,_6);
68
px=pt.x+(pt.y-ax.y);
69
py=pt.y+(ax.x-pt.x);
70
_8=this.util.lineSub(pt.x,pt.y,px,py,(_6-_7));
71
return {x:_8.x,y:_8.y,width:20};
72
},setLabelY:function(){
73
var c=this.points[1];
74
var ay=this.points[2];
75
var _9=40;
76
var _a=20;
77
var pt,px,py,_b;
78
pt=this.util.lineSub(c.x,c.y,ay.x,ay.y,_9);
79
px=pt.x+(ay.y-pt.y);
80
py=pt.y+(pt.x-ay.x);
81
_b=this.util.lineSub(pt.x,pt.y,px,py,(_9-_a));
82
return {x:_b.x,y:_b.y,width:20};
83
},setLabelZ:function(){
84
var c=this.points[1];
85
var z=this.points[3];
86
var _c=40;
87
var _d=20;
88
var pt,px,py,_e;
89
pt=this.util.lineSub(c.x,c.y,z.x,z.y,_c);
90
px=pt.x+(pt.y-z.y);
91
py=pt.y+(z.x-pt.x);
92
_e=this.util.lineSub(pt.x,pt.y,px,py,(_c-_d));
93
return {x:_e.x,y:_e.y,width:20};
94
},setLabel:function(_f){
95
if(this._labelsCreated){
96
return;
97
}
98
!this.labelX&&this.createLabels();
99
var x="x";
100
var y="y";
101
var z="z";
102
if(_f){
103
if(this.labelZ){
104
var _10=_f.match(/(.*?)(and|&)(.*?)(and|&)(.*)/i);
105
if(_10.length>4){
106
x=_10[1].replace(/^\s+/,"").replace(/\s+$/,"");
107
y=_10[3].replace(/^\s+/,"").replace(/\s+$/,"");
108
z=_10[5].replace(/^\s+/,"").replace(/\s+$/,"");
109
}
110
}else{
111
var _10=_f.match(/(.*?)(and|&)(.*)/i);
112
if(_10.length>2){
113
x=_10[1].replace(/^\s+/,"").replace(/\s+$/,"");
114
y=_10[3].replace(/^\s+/,"").replace(/\s+$/,"");
115
}
116
}
117
}
118
this.labelX.setLabel(x);
119
this.labelY.setLabel(y);
120
if(this.labelZ){
121
this.labelZ.setLabel(z);
122
}
123
this._labelsCreated=true;
124
},getLabel:function(){
125
if(!this.labelX){
126
return null;
127
}
128
return {x:this.labelX.getText(),y:this.labelY.getText(),z:this.labelZ?this.labelZ.getText():null};
129
},anchorPositionCheck:function(x,y,_11){
130
var pm=this.container.getParent().getTransform();
131
var am=_11.shape.getTransform();
132
var p=this.points;
133
var o={x:am.dx+_11.org.x+pm.dx,y:am.dy+_11.org.y+pm.dy};
134
var c={x:p[1].x+pm.dx,y:p[1].y+pm.dy};
135
var ox=c.x-(c.y-o.y);
136
var oy=c.y-(o.x-c.x);
137
return {x:ox,y:oy};
138
},onTransformBegin:function(_12){
139
this._isBeingModified=true;
140
},onTransformEnd:function(_13){
141
if(!_13){
142
return;
143
}
144
this._isBeingModified=false;
145
this._toggleSelected();
146
var o=this.points[0];
147
var c=this.points[1];
148
var obj={start:{x:c.x,y:c.y},x:o.x,y:o.y};
149
var pt=this.util.constrainAngle(obj,0,89);
150
var zpt=this.style.zAxisEnabled?this.zPoint(obj):null;
151
if(pt.x==o.x&&pt.y==o.y){
152
pt=this.util.snapAngle(obj,this.angleSnap/180);
153
obj.x=pt.x;
154
obj.y=pt.y;
155
var ox=obj.start.x-(obj.start.y-obj.y);
156
var oy=obj.start.y-(obj.x-obj.start.x);
157
if(ox<0||oy<0){
158
console.warn("AXES ERROR LESS THAN ZERO - ABORT");
159
return;
160
}
161
this.points=[{x:obj.x,y:obj.y},{x:obj.start.x,y:obj.start.y,noAnchor:true}];
162
this.points.push({x:ox,y:oy,noAnchor:true});
163
if(zpt){
164
this.points.push(zpt);
165
}
166
this.setPoints(this.points);
167
this.onModify(this);
168
return;
169
}
170
this.points[0].x=pt.x;
171
this.points[0].y=pt.y;
172
o=this.points[0];
173
var ox=c.x-(c.y-o.y);
174
var oy=c.y-(o.x-c.x);
175
this.points[2]={x:ox,y:oy,noAnchor:true};
176
if(zpt){
177
this.points.push(zpt);
178
}
179
this.setPoints(this.points);
180
this.labelX.setLabel();
181
this.labelY.setLabel();
182
if(this.labelZ){
183
this.labelZ.setLabel();
184
}
185
this.onModify(this);
186
},getBounds:function(_14){
187
var px=this.points[0],pc=this.points[1],py=this.points[2];
188
if(this.style.zAxisEnabled){
189
var pz=this.points[3];
190
}
191
if(_14){
192
var _15={x:pc.x,y:pc.y,x1:pc.x,y1:pc.y,x2:px.x,y2:px.y,x3:py.x,y3:py.y};
193
if(this.style.zAxisEnabled){
194
_15.x4=pz.x;
195
_15.y4=pz.y;
196
}
197
return _15;
198
}
199
var x1=this.style.zAxisEnabled?(py.x<pz.x?py.x:pz.x):py.x;
200
y1=py.y<px.y?py.y:px.y,x2=px.x,y2=this.style.zAxisEnabled?pz.y:pc.y;
201
return {x1:x1,y1:y1,x2:x2,y2:y2,x:x1,y:y1,w:x2-x1,h:y2-y1};
202
},_postSetPoints:function(pts){
203
this.points[0]=pts[0];
204
if(this.pointsToData){
205
this.data=this.pointsToData();
206
}
207
},onTransform:function(_16){
208
var o=this.points[0];
209
var c=this.points[1];
210
var ox=c.x-(c.y-o.y);
211
var oy=c.y-(o.x-c.x);
212
this.points[2]={x:ox,y:oy,noAnchor:true};
213
if(this.style.zAxisEnabled){
214
this.points[3]=this.zPoint({start:{x:c.x,y:c.y},x:o.x,y:o.y});
215
}
216
this.setPoints(this.points);
217
if(!this._isBeingModified){
218
this.onTransformBegin();
219
}
220
this.render();
221
},pointsToData:function(){
222
var p=this.points;
223
var d={x1:p[1].x,y1:p[1].y,x2:p[0].x,y2:p[0].y,x3:p[2].x,y3:p[2].y};
224
if(this.style.zAxisEnabled){
225
d.x4=p[3].x;
226
d.y4=p[3].y;
227
d.cosphi=1;
228
}
229
return d;
230
},getRadius:function(){
231
var p=this.points;
232
var _17={start:{x:p[1].x,y:p[1].y},x:p[0].x,y:p[0].y};
233
return this.util.length(_17);
234
},dataToPoints:function(o){
235
o=o||this.data;
236
if(o.radius||o.angle){
237
var pt=this.util.pointOnCircle(o.x,o.y,o.radius,o.angle),zpt;
238
var ox=o.x-(o.y-pt.y);
239
var oy=o.y-(pt.x-o.x);
240
if((o.cosphi&&o.cosphi==1)||this.style.zAxisEnabled){
241
this.style.zAxisEnabled=true;
242
zpt=this.util.pointOnCircle(o.x,o.y,o.radius*this.zScale,this.style.zAngle);
243
}
244
this.data=o={x1:o.x,y1:o.y,x2:pt.x,y2:pt.y,x3:ox,y3:oy};
245
if(this.style.zAxisEnabled){
246
this.data.x4=o.x4=zpt.x;
247
this.data.y4=o.y4=zpt.y;
248
this.data.cosphi=1;
249
}
250
}
251
this.points=[{x:o.x2,y:o.y2},{x:o.x1,y:o.y1,noAnchor:true},{x:o.x3,y:o.y3,noAnchor:true}];
252
if(this.style.zAxisEnabled){
253
this.points.push({x:o.x4,y:o.y4,skip:true,noAnchor:true});
254
}
255
return this.points;
256
},onDrag:function(obj){
257
var pt=this.util.constrainAngle(obj,0,89);
258
obj.x=pt.x;
259
obj.y=pt.y;
260
var ox=obj.start.x-(obj.start.y-obj.y);
261
var oy=obj.start.y-(obj.x-obj.start.x);
262
if(ox<0||oy<0){
263
return;
264
}
265
this.points=[{x:obj.x,y:obj.y},{x:obj.start.x,y:obj.start.y,noAnchor:true}];
266
this.points.push({x:ox,y:oy,noAnchor:true});
267
if(this.style.zAxisEnabled){
268
var zpt=this.zPoint(obj);
269
this.points.push(zpt);
270
}
271
this.render();
272
},onUp:function(obj){
273
if(!this._downOnCanvas){
274
return;
275
}
276
this._downOnCanvas=false;
277
var p=this.points;
278
if(!p.length){
279
var s=obj.start,d=100;
280
this.points=[{x:s.x+d,y:s.y+d},{x:s.x,y:s.y+d,noAnchor:true},{x:s.x,y:s.y,noAnchor:true}];
281
if(this.style.zAxisEnabled){
282
var zpt=this.zPoint({start:{x:s.x,y:s.y+d},x:s.x+d,y:s.y+d});
283
this.points.push(zpt);
284
}
285
this.setPoints=this._postSetPoints;
286
this.pointsToData();
287
this.render();
288
this.onRender(this);
289
return;
290
}
291
var len=this.util.distance(p[1].x,p[1].y,p[0].x,p[0].y);
292
if(!p||!p.length){
293
return;
294
}else{
295
if(len<this.minimumSize){
296
this.remove(this.shape,this.hit);
297
this.xArrow.remove(this.xArrow.shape,this.xArrow.hit);
298
this.yArrow.remove(this.yArrow.shape,this.yArrow.hit);
299
if(this.zArrow){
300
this.zArrow.remove(this.zArrow.shape,this.zArrow.hit);
301
}
302
return;
303
}
304
}
305
var o=p[0];
306
var c=p[1];
307
obj={start:{x:c.x,y:c.y},x:o.x,y:o.y};
308
var pt=this.util.snapAngle(obj,this.angleSnap/180);
309
obj.x=pt.x;
310
obj.y=pt.y;
311
var ox=obj.start.x-(obj.start.y-obj.y);
312
var oy=obj.start.y-(obj.x-obj.start.x);
313
if(ox<0||oy<0){
314
return;
315
}
316
this.points=[{x:obj.x,y:obj.y},{x:obj.start.x,y:obj.start.y,noAnchor:true}];
317
this.points.push({x:ox,y:oy,noAnchor:true});
318
if(this.style.zAxisEnabled){
319
this.points.push(this.zPoint(obj));
320
}
321
this.onRender(this);
322
this.setPoints=this._postSetPoints;
323
}});
324
dojox.drawing.tools.custom.Axes.setup={name:"dojox.drawing.tools.custom.Axes",tooltip:"Axes Tool",iconClass:"iconAxes"};
325
dojox.drawing.register(dojox.drawing.tools.custom.Axes.setup,"tool");
326
}