Version 3.18.1
Show:

File: graphics/js/SVGEllipse.js

  1. /**
  2. * <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Ellipse.html">`Ellipse`</a> class.
  3. * `SVGEllipse` is not intended to be used directly. Instead, use the <a href="Ellipse.html">`Ellipse`</a> class.
  4. * If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Ellipse.html">`Ellipse`</a>
  5. * class will point to the `SVGEllipse` class.
  6. *
  7. * @module graphics
  8. * @class SVGEllipse
  9. * @constructor
  10. */
  11. SVGEllipse = function()
  12. {
  13. SVGEllipse.superclass.constructor.apply(this, arguments);
  14. };
  15. SVGEllipse.NAME = "ellipse";
  16. Y.extend(SVGEllipse, SVGShape, {
  17. /**
  18. * Indicates the type of shape
  19. *
  20. * @property _type
  21. * @type String
  22. * @private
  23. */
  24. _type: "ellipse",
  25. /**
  26. * Updates the shape.
  27. *
  28. * @method _draw
  29. * @private
  30. */
  31. _draw: function()
  32. {
  33. var node = this.node,
  34. w = this.get("width"),
  35. h = this.get("height"),
  36. x = this.get("x"),
  37. y = this.get("y"),
  38. xRadius = w * 0.5,
  39. yRadius = h * 0.5,
  40. cx = x + xRadius,
  41. cy = y + yRadius;
  42. node.setAttribute("rx", xRadius);
  43. node.setAttribute("ry", yRadius);
  44. node.setAttribute("cx", cx);
  45. node.setAttribute("cy", cy);
  46. this._fillChangeHandler();
  47. this._strokeChangeHandler();
  48. this._updateTransform();
  49. }
  50. });
  51. SVGEllipse.ATTRS = Y.merge(SVGShape.ATTRS, {
  52. /**
  53. * Horizontal radius for the ellipse.
  54. *
  55. * @config xRadius
  56. * @type Number
  57. */
  58. xRadius: {
  59. setter: function(val)
  60. {
  61. this.set("width", val * 2);
  62. },
  63. getter: function()
  64. {
  65. var val = this.get("width");
  66. if(val)
  67. {
  68. val *= 0.5;
  69. }
  70. return val;
  71. }
  72. },
  73. /**
  74. * Vertical radius for the ellipse.
  75. *
  76. * @config yRadius
  77. * @type Number
  78. * @readOnly
  79. */
  80. yRadius: {
  81. setter: function(val)
  82. {
  83. this.set("height", val * 2);
  84. },
  85. getter: function()
  86. {
  87. var val = this.get("height");
  88. if(val)
  89. {
  90. val *= 0.5;
  91. }
  92. return val;
  93. }
  94. }
  95. });
  96. Y.SVGEllipse = SVGEllipse;