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

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

// Add circle-specific functions
SVG.extend(SVG.Circle, {
  
  // custom move function
  move: function(x, y) {
    this.attrs.x = x;
    this.attrs.y = y;
    
    return this.center();
  },

  // custom size function (no height value here!)
  size: function(w) {
    return this.attr('r', w / 2).center();
  },

  // position element by its center
  center: function(x, y) {
    var r = this.attrs.r || 0;

    return this.attr({
      cx: (x || ((this.attrs.x || 0) + r)),
      cy: (y || ((this.attrs.y || 0) + r))
    });
  }
  
});