Ellipse.js 2.5 KB

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