aboutsummaryrefslogtreecommitdiffstats
path: root/src/ellipse.js
blob: 6ff56083b1932ff9255f3afd4d1aa54d22dfd1ff (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() {
  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 != null ? x : (this.attrs.x || 0) + (this.attrs.rx || 0)
    , cy: y != null ? y : (this.attrs.y || 0) + (this.attrs.ry || 0)
    })
  }
  
})

// Usage:

//     draw.ellipse(200, 100)