aboutsummaryrefslogtreecommitdiffstats
path: root/src/ellipse.js
blob: 018cd4f2812083cf7b2c3ee24b022de25cbe9e74 (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;
    
    return this.center();
  },

  // custom size function
  size: function(w, h) {
    return this.
      attr({ rx: w / 2, ry: (h != null ? h : w) / 2 }).
      center();
  },
  
  // position element by its center
  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)
    });
  }
  
});