1 | dojo.provide("dojox.drawing.stencil.Line"); |
---|
2 | |
---|
3 | dojox.drawing.stencil.Line = dojox.drawing.util.oo.declare( |
---|
4 | // summary: |
---|
5 | // Creates a dojox.gfx Line based on data or points provided. |
---|
6 | // |
---|
7 | dojox.drawing.stencil._Base, |
---|
8 | function(options){ |
---|
9 | // summary: |
---|
10 | // constructor |
---|
11 | }, |
---|
12 | { |
---|
13 | type:"dojox.drawing.stencil.Line", |
---|
14 | anchorType: "single", |
---|
15 | baseRender:true, |
---|
16 | |
---|
17 | /*===== |
---|
18 | StencilData: { |
---|
19 | // summary: |
---|
20 | // The data used to create the dojox.gfx Shape |
---|
21 | // x1: Number |
---|
22 | // First point x |
---|
23 | // y1: Number |
---|
24 | // First point y |
---|
25 | // x2: Number |
---|
26 | // Second point x |
---|
27 | // y2: Number |
---|
28 | // Second point y |
---|
29 | |
---|
30 | // ALTERNATIVE: |
---|
31 | |
---|
32 | // x: Number |
---|
33 | // First point x |
---|
34 | // y: Number |
---|
35 | // First point y |
---|
36 | // angle: Number |
---|
37 | // angle of line |
---|
38 | // radius: Number |
---|
39 | // length of line |
---|
40 | }, |
---|
41 | |
---|
42 | StencilPoints: [ |
---|
43 | // summary: |
---|
44 | // An Array of dojox.__StencilPoint objects that describe the Stencil |
---|
45 | // 0: Object |
---|
46 | // First point |
---|
47 | // 1: Object |
---|
48 | // Second point |
---|
49 | ], |
---|
50 | =====*/ |
---|
51 | |
---|
52 | dataToPoints: function(o){ |
---|
53 | //summary: |
---|
54 | // Converts data to points. |
---|
55 | o = o || this.data; |
---|
56 | if(o.radius || o.angle){ |
---|
57 | // instead of using x1,x2,y1,y1, |
---|
58 | // it's been set as x,y,angle,radius |
---|
59 | |
---|
60 | var pt = this.util.pointOnCircle(o.x,o.y,o.radius,o.angle); |
---|
61 | //console.log(" ---- pts:", pt.x, pt.y); |
---|
62 | this.data = o = { |
---|
63 | x1:o.x, |
---|
64 | y1:o.y, |
---|
65 | x2:pt.x, |
---|
66 | y2:pt.y |
---|
67 | } |
---|
68 | |
---|
69 | } |
---|
70 | this.points = [ |
---|
71 | {x:o.x1, y:o.y1}, |
---|
72 | {x:o.x2, y:o.y2} |
---|
73 | ]; |
---|
74 | return this.points; |
---|
75 | }, |
---|
76 | pointsToData: function(p){ |
---|
77 | // summary: |
---|
78 | // Converts points to data |
---|
79 | p = p || this.points; |
---|
80 | this.data = { |
---|
81 | x1: p[0].x, |
---|
82 | y1: p[0].y, |
---|
83 | x2: p[1].x, |
---|
84 | y2: p[1].y |
---|
85 | }; |
---|
86 | return this.data; |
---|
87 | }, |
---|
88 | |
---|
89 | _create: function(/*String*/shp, /*StencilData*/d, /*Object*/sty){ |
---|
90 | // summary: |
---|
91 | // Creates a dojox.gfx.shape based on passed arguments. |
---|
92 | // Can be called many times by implementation to create |
---|
93 | // multiple shapes in one stencil. |
---|
94 | // |
---|
95 | this.remove(this[shp]); |
---|
96 | this[shp] = this.container.createLine(d) |
---|
97 | .setStroke(sty); |
---|
98 | this._setNodeAtts(this[shp]); |
---|
99 | }, |
---|
100 | |
---|
101 | render: function(){ |
---|
102 | // summary: |
---|
103 | // Renders the 'hit' object (the shape used for an expanded |
---|
104 | // hit area and for highlighting) and the'shape' (the actual |
---|
105 | // display object). |
---|
106 | // |
---|
107 | this.onBeforeRender(this); |
---|
108 | this.renderHit && this._create("hit", this.data, this.style.currentHit); |
---|
109 | this._create("shape", this.data, this.style.current); |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | } |
---|
114 | ); |
---|
115 | |
---|
116 | dojox.drawing.register({ |
---|
117 | name:"dojox.drawing.stencil.Line" |
---|
118 | }, "stencil"); |
---|