Ellipse.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // wrapped by build app
  2. define("dojox/drawing/stencil/Ellipse", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.stencil.Ellipse");
  4. /*=====
  5. __StencilData = {
  6. // summary:
  7. // the data used to create the dojox.gfx Shape
  8. //
  9. // cx: Number
  10. // Center point x
  11. cx:0,
  12. // cy: Number
  13. // Center point y
  14. cy:0,
  15. // rx: Number
  16. // Horizontal radius
  17. rx:0,
  18. // ry: Number
  19. // Vertical radius
  20. ry:0
  21. }
  22. =====*/
  23. dojox.drawing.stencil.Ellipse = dojox.drawing.util.oo.declare(
  24. // summary:
  25. // Creates a dojox.gfx Ellipse based on data or points provided.
  26. //
  27. dojox.drawing.stencil._Base,
  28. function(options){
  29. // summary:
  30. // constructor
  31. },
  32. {
  33. type:"dojox.drawing.stencil.Ellipse",
  34. anchorType: "group",
  35. baseRender:true,
  36. dataToPoints: function(/*Object*/o){
  37. //summary:
  38. // Converts data to points.
  39. o = o || this.data;
  40. var x = o.cx - o.rx,
  41. y = o.cy - o.ry,
  42. w = o.rx*2,
  43. h = o.ry*2
  44. this.points = [
  45. {x:x, y:y}, // TL
  46. {x:x+w, y:y}, // TR
  47. {x:x+w, y:y+h}, // BR
  48. {x:x, y:y+h} // BL
  49. ];
  50. return this.points; //Array
  51. },
  52. pointsToData: function(/*Array*/p){
  53. // summary:
  54. // Converts points to data
  55. p = p || this.points;
  56. var s = p[0];
  57. var e = p[2];
  58. this.data = {
  59. cx: s.x + (e.x - s.x)/2,
  60. cy: s.y + (e.y - s.y)/2,
  61. rx: (e.x - s.x)*.5,
  62. ry: (e.y - s.y)*.5
  63. };
  64. return this.data; //Object
  65. },
  66. _create: function(/*String*/shp, /*__StencilData*/d, /*Object*/sty){
  67. // summary:
  68. // Creates a dojox.gfx.shape based on passed arguments.
  69. // Can be called many times by implementation to create
  70. // multiple shapes in one stencil.
  71. //
  72. this.remove(this[shp]);
  73. this[shp] = this.container.createEllipse(d)
  74. .setStroke(sty)
  75. .setFill(sty.fill);
  76. this._setNodeAtts(this[shp]);
  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. dojox.drawing.register({
  91. name:"dojox.drawing.stencil.Ellipse"
  92. }, "stencil");
  93. });