aboutsummaryrefslogtreecommitdiffstats
path: root/src/ellipse.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
committerwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
commite2304534e0cfb6f6f4ab8c37ea5275ae26cd455a (patch)
tree2386e9f361d9c5fa1308387aeeaf33f00241b3c5 /src/ellipse.js
parent7a29817ffd764cf7ab6906250b57f234801c94e0 (diff)
downloadsvg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.tar.gz
svg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.zip
Implemented SVG.invent function and bumped to v1.0rc3
Diffstat (limited to 'src/ellipse.js')
-rwxr-xr-xsrc/ellipse.js107
1 files changed, 52 insertions, 55 deletions
diff --git a/src/ellipse.js b/src/ellipse.js
index 237a5ca..d84f988 100755
--- a/src/ellipse.js
+++ b/src/ellipse.js
@@ -1,62 +1,59 @@
-//
-SVG.Ellipse = function() {
- this.constructor.call(this, SVG.create('ellipse'))
-}
+SVG.Ellipse = SVG.invent({
+ // Initialize node
+ create: 'ellipse'
-// Inherit from SVG.Shape
-SVG.Ellipse.prototype = new SVG.Shape
+ // Inherit from
+, inherit: SVG.Shape
-//
-SVG.extend(SVG.Ellipse, {
- // Move over x-axis
- x: function(x) {
- return x == null ? this.cx() - this.attr('rx') : this.cx(x + this.attr('rx'))
- }
- // Move over y-axis
-, y: function(y) {
- return y == null ? this.cy() - this.attr('ry') : this.cy(y + this.attr('ry'))
- }
- // Move by center over x-axis
-, cx: function(x) {
- return x == null ? this.attr('cx') : this.attr('cx', new SVG.Number(x).divide(this.trans.scaleX))
- }
- // Move by center over y-axis
-, cy: function(y) {
- return y == null ? this.attr('cy') : this.attr('cy', new SVG.Number(y).divide(this.trans.scaleY))
- }
- // Set width of element
-, width: function(width) {
- return width == null ? this.attr('rx') * 2 : this.attr('rx', new SVG.Number(width).divide(2))
- }
- // Set height of element
-, height: function(height) {
- return height == null ? this.attr('ry') * 2 : this.attr('ry', new SVG.Number(height).divide(2))
- }
- // Custom size function
-, size: function(width, height) {
- var p = this._proportionalSize(width, height)
+ // Add class methods
+, extend: {
+ // Move over x-axis
+ x: function(x) {
+ return x == null ? this.cx() - this.attr('rx') : this.cx(x + this.attr('rx'))
+ }
+ // Move over y-axis
+ , y: function(y) {
+ return y == null ? this.cy() - this.attr('ry') : this.cy(y + this.attr('ry'))
+ }
+ // Move by center over x-axis
+ , cx: function(x) {
+ return x == null ? this.attr('cx') : this.attr('cx', new SVG.Number(x).divide(this.trans.scaleX))
+ }
+ // Move by center over y-axis
+ , cy: function(y) {
+ return y == null ? this.attr('cy') : this.attr('cy', new SVG.Number(y).divide(this.trans.scaleY))
+ }
+ // Set width of element
+ , width: function(width) {
+ return width == null ? this.attr('rx') * 2 : this.attr('rx', new SVG.Number(width).divide(2))
+ }
+ // Set height of element
+ , height: function(height) {
+ return height == null ? this.attr('ry') * 2 : this.attr('ry', new SVG.Number(height).divide(2))
+ }
+ // Custom size function
+ , size: function(width, height) {
+ var p = this._proportionalSize(width, height)
- return this.attr({
- rx: new SVG.Number(p.width).divide(2)
- , ry: new SVG.Number(p.height).divide(2)
- })
+ return this.attr({
+ rx: new SVG.Number(p.width).divide(2)
+ , ry: new SVG.Number(p.height).divide(2)
+ })
+ }
+
}
-
-})
-//
-SVG.extend(SVG.Container, {
- // Create circle element, based on ellipse
- circle: function(size) {
- return this.ellipse(size, size)
+ // Add parent method
+, construct: {
+ // Create circle element, based on ellipse
+ circle: function(size) {
+ return this.ellipse(size, size)
+ }
+ // Create an ellipse
+ , ellipse: function(width, height) {
+ return this.put(new SVG.Ellipse).size(width, height).move(0, 0)
+ }
+
}
- // Create an ellipse
-, ellipse: function(width, height) {
- return this.put(new SVG.Ellipse).size(width, height).move(0, 0)
- }
-
-})
-
-// Usage:
-// draw.ellipse(200, 100) \ No newline at end of file
+}) \ No newline at end of file