[483] | 1 | define(["dojo/_base/lang", "../util/oo", "./_Base", "../manager/_registry"], |
---|
| 2 | function(lang, oo, Base, registry){ |
---|
| 3 | |
---|
| 4 | /*===== |
---|
| 5 | var __StencilData = { |
---|
| 6 | // summary: |
---|
| 7 | // the data used to create the dojox.gfx Shape |
---|
| 8 | // cx: Number |
---|
| 9 | // Center point x |
---|
| 10 | // cy: Number |
---|
| 11 | // Center point y |
---|
| 12 | // rx: Number |
---|
| 13 | // Horizontal radius |
---|
| 14 | // ry: Number |
---|
| 15 | // Vertical radius |
---|
| 16 | }; |
---|
| 17 | =====*/ |
---|
| 18 | |
---|
| 19 | var Ellipse = oo.declare( |
---|
| 20 | Base, |
---|
| 21 | function(options){ |
---|
| 22 | // summary: |
---|
| 23 | // constructor |
---|
| 24 | }, |
---|
| 25 | { |
---|
| 26 | // summary: |
---|
| 27 | // Creates a dojox.gfx Ellipse based on data or points provided. |
---|
| 28 | |
---|
| 29 | type:"dojox.drawing.stencil.Ellipse", |
---|
| 30 | anchorType: "group", |
---|
| 31 | baseRender:true, |
---|
| 32 | dataToPoints: function(/*Object*/o){ |
---|
| 33 | // summary: |
---|
| 34 | // Converts data to points. |
---|
| 35 | o = o || this.data; |
---|
| 36 | var x = o.cx - o.rx, |
---|
| 37 | y = o.cy - o.ry, |
---|
| 38 | w = o.rx*2, |
---|
| 39 | h = o.ry*2 |
---|
| 40 | this.points = [ |
---|
| 41 | {x:x, y:y}, // TL |
---|
| 42 | {x:x+w, y:y}, // TR |
---|
| 43 | {x:x+w, y:y+h}, // BR |
---|
| 44 | {x:x, y:y+h} // BL |
---|
| 45 | ]; |
---|
| 46 | return this.points; //Array |
---|
| 47 | }, |
---|
| 48 | |
---|
| 49 | pointsToData: function(/*Array*/p){ |
---|
| 50 | // summary: |
---|
| 51 | // Converts points to data |
---|
| 52 | p = p || this.points; |
---|
| 53 | var s = p[0]; |
---|
| 54 | var e = p[2]; |
---|
| 55 | this.data = { |
---|
| 56 | cx: s.x + (e.x - s.x)/2, |
---|
| 57 | cy: s.y + (e.y - s.y)/2, |
---|
| 58 | rx: (e.x - s.x)*.5, |
---|
| 59 | ry: (e.y - s.y)*.5 |
---|
| 60 | }; |
---|
| 61 | return this.data; //Object |
---|
| 62 | |
---|
| 63 | }, |
---|
| 64 | |
---|
| 65 | _create: function(/*String*/shp, /*__StencilData*/d, /*Object*/sty){ |
---|
| 66 | // summary: |
---|
| 67 | // Creates a dojox.gfx.shape based on passed arguments. |
---|
| 68 | // Can be called many times by implementation to create |
---|
| 69 | // multiple shapes in one stencil. |
---|
| 70 | |
---|
| 71 | this.remove(this[shp]); |
---|
| 72 | this[shp] = this.container.createEllipse(d) |
---|
| 73 | .setStroke(sty) |
---|
| 74 | .setFill(sty.fill); |
---|
| 75 | this._setNodeAtts(this[shp]); |
---|
| 76 | }, |
---|
| 77 | |
---|
| 78 | render: function(){ |
---|
| 79 | // summary: |
---|
| 80 | // Renders the 'hit' object (the shape used for an expanded |
---|
| 81 | // hit area and for highlighting) and the'shape' (the actual |
---|
| 82 | // display object). |
---|
| 83 | |
---|
| 84 | this.onBeforeRender(this); |
---|
| 85 | this.renderHit && this._create("hit", this.data, this.style.currentHit); |
---|
| 86 | this._create("shape", this.data, this.style.current); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | } |
---|
| 90 | ); |
---|
| 91 | |
---|
| 92 | lang.setObject("dojox.drawing.stencil.Ellipse", Ellipse); |
---|
| 93 | registry.register({ |
---|
| 94 | name:"dojox.drawing.stencil.Ellipse" |
---|
| 95 | }, "stencil"); |
---|
| 96 | |
---|
| 97 | return Ellipse; |
---|
| 98 | }); |
---|