summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/drawing/annotations/Angle.js
blob: 6f09f2a6228b4abf9b1021f79011a3803a5a2a71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//>>built
// wrapped by build app
define("dojox/drawing/annotations/Angle", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
dojo.provide("dojox.drawing.annotations.Angle");

dojox.drawing.annotations.Angle = dojox.drawing.util.oo.declare(
	// summary:
	//	When initiated, an HTML box will hover near the Stencil,
	//	displaying it's angle while drawn or modified. Currently
	//	only works with Vector, Line, Arrow, and Axes.
	// description:
	//	Annotation is positioned with dojox.drawing.util.positioning.angle
	//	That method should be overwritten for custom placement.
	//	Called internally. To initiaize:
	//	TODO: currently always on
	//
	function(/*Object*/options){
		// arguments:
		//	options: Object
		//		One key value: the stencil that called this.
		//
		this.stencil = options.stencil;
		this.util = options.stencil.util;
		this.mouse = options.stencil.mouse;

		this.stencil.connectMult([
			["onDrag", this, "showAngle"],
			["onUp", this, "hideAngle"],
			["onTransformBegin", this, "showAngle"],
			["onTransform", this, "showAngle"],
			["onTransformEnd", this, "hideAngle"]
		]);
	},
	{
		type:"dojox.drawing.tools.custom",
		angle:0,

		showAngle: function(){
			//	summary:
			//		Called to display angle
			//
			if(!this.stencil.selected && this.stencil.created){ return; }
			if(this.stencil.getRadius() < this.stencil.minimumSize){
				this.hideAngle();
				return;
			}
			var node = this.getAngleNode();
			var d = this.stencil.pointsToData();
			var pt = dojox.drawing.util.positioning.angle({x:d.x1,y:d.y1},{x:d.x2,y:d.y2});
			var sc = this.mouse.scrollOffset();
			var mx = this.stencil.getTransform();
			var dx = mx.dx / this.mouse.zoom;
			var dy = mx.dy / this.mouse.zoom;
			pt.x /= this.mouse.zoom;
			pt.y /= this.mouse.zoom;

			// adding _offX & _offY since this is HTML
			// and we are from the page corner, not
			// the canvas corner
			var x = this.stencil._offX + pt.x - sc.left + dx;
			var y = this.stencil._offY + pt.y - sc.top + dy;
			dojo.style(node, {
				left:  	x + "px",
				top: 	y + "px",
				align:pt.align
			});

			var angle=this.stencil.getAngle();
			if(this.stencil.style.zAxis && this.stencil.shortType=="vector"){
			  node.innerHTML = this.stencil.data.cosphi > 0 ? "out of" : "into";
			}else if(this.stencil.shortType=="line"){
			  node.innerHTML = this.stencil.style.zAxis?"out of":Math.ceil(angle%180);
			}else{
			  node.innerHTML = Math.ceil(angle);
			}
		},

		getAngleNode: function(){
			//	summary:
			//		Gets or creates HTMLNode used for display
			if(!this._angleNode){
				this._angleNode = dojo.create("span", null, dojo.body());
				dojo.addClass(this._angleNode, "textAnnotation");
				dojo.style(this._angleNode, "opacity", 1);
			}
			return this._angleNode; //HTMLNode
		},

		hideAngle: function(){
			//	summary:
			//		Turns display off.
			//
			if(this._angleNode && dojo.style(this._angleNode, "opacity")>0.9){

				dojo.fadeOut({node:this._angleNode,
					duration:500,
					onEnd: function(node){
						dojo.destroy(node);
					}
				}).play();
				this._angleNode = null;
			}

		}
	}

);
});