summaryrefslogtreecommitdiffstats
path: root/src/ellipse.js
blob: ad3e02ec0e66d03a850d0dba45c73226978b47d6 (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
36
//
SVG.Ellipse = function Ellipse() {
  this.constructor.call(this, SVG.create('ellipse'));
};

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

//
SVG.extend(SVG.Ellipse, {
  // Custom move function
  move: function(x, y) {
    this.attrs.x = x;
    this.attrs.y = y;
    
    return this.center();
  },
  // Custom size function
  size: function(width, height) {
    return this.
      attr({ rx: width / 2, ry: (height != null ? height : width) / 2 }).
      center();
  },
  // Custom center function
  center: function(x, y) {
    return this.attr({
      cx: x || (this.attrs.x || 0) + (this.attrs.rx || 0),
      cy: y || (this.attrs.y || 0) + (this.attrs.ry || 0)
    });
  }
  
});

// Usage:

//     draw.ellipse(200, 100);