summaryrefslogtreecommitdiffstats
path: root/src/ellipse.js
blob: f1638ee3c88b2185431a79db22d12bb8f68b5a9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
SVG.Ellipse = function Ellipse() {
  this.constructor.call(this, SVG.create('ellipse'));
};

// inherit from SVG.Shape
SVG.Ellipse.prototype = new SVG.Shape();

// Add ellipse-specific functions
SVG.extend(SVG.Ellipse, {
  
  // custom move function
  move: function(x, y) {
    this.attrs.x = x;
    this.attrs.y = y;
    this.center();

    return this;
  },

  // custom size function
  size: function(w, h) {
    this.attr('rx', w / 2);
    this.attr('ry', h / 2);
    this.center();

    return this; 
  },

  center: function(cx, cy) {
    this.attr('cx', cx || ((this.attrs.x || 0) + (this.attrs.rx || 0)));
    this.attr('cy', cy || ((this.attrs.y || 0) + (this.attrs.ry || 0)));
  }
  
});