diff options
author | wout <wout@impinc.co.uk> | 2014-06-25 15:05:03 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-06-25 15:05:03 +0200 |
commit | e567c774c17e6649041d4972defd1232ab602012 (patch) | |
tree | 05140fe4715a652c99f15672e1d56c0fc8426824 /src/ellipse.js | |
parent | ec21f496bddc588e2113fd5418d713ce8ae78f39 (diff) | |
download | svg.js-e567c774c17e6649041d4972defd1232ab602012.tar.gz svg.js-e567c774c17e6649041d4972defd1232ab602012.zip |
Added SVG.Circle, removed structural internal references
Diffstat (limited to 'src/ellipse.js')
-rwxr-xr-x | src/ellipse.js | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/src/ellipse.js b/src/ellipse.js index 0d23e6e..aab8087 100755 --- a/src/ellipse.js +++ b/src/ellipse.js @@ -1,3 +1,30 @@ +SVG.Circle = SVG.invent({ + // Initialize node + create: 'circle' + + // Inherit from +, inherit: SVG.Shape + + // Add parent method +, construct: { + // Create circle element, based on ellipse + circle: function(size) { + return this.put(new SVG.Circle).rx(new SVG.Number(size).divide(2)).move(0, 0) + } + } +}) + +SVG.extend(SVG.Circle, SVG.FX, { + // Radius x value + rx: function(rx) { + return this.attr('r', rx) + } + // Alias radius x value +, ry: function(ry) { + return this.rx(ry) + } +}) + SVG.Ellipse = SVG.invent({ // Initialize node create: 'ellipse' @@ -5,15 +32,35 @@ SVG.Ellipse = SVG.invent({ // Inherit from , inherit: SVG.Shape - // Add class methods -, extend: { + // Add parent method +, construct: { + // Create an ellipse + ellipse: function(width, height) { + return this.put(new SVG.Ellipse).size(width, height).move(0, 0) + } + } +}) + +SVG.extend(SVG.Ellipse, SVG.Rect, SVG.FX, { + // Radius x value + rx: function(rx) { + return this.attr('rx', rx) + } + // Radius y value +, ry: function(ry) { + return this.attr('ry', ry) + } +}) + +// Add common method +SVG.extend(SVG.Circle, SVG.Ellipse, { // Move over x-axis x: function(x) { - return x == null ? this.cx() - this.attr('rx') : this.cx(x + this.attr('rx')) + return x == null ? this.cx() - this.rx() : this.cx(x + this.rx()) } // Move over y-axis , y: function(y) { - return y == null ? this.cy() - this.attr('ry') : this.cy(y + this.attr('ry')) + return y == null ? this.cy() - this.ry() : this.cy(y + this.ry()) } // Move by center over x-axis , cx: function(x) { @@ -25,35 +72,18 @@ SVG.Ellipse = SVG.invent({ } // Set width of element , width: function(width) { - return width == null ? this.attr('rx') * 2 : this.attr('rx', new SVG.Number(width).divide(2)) + return width == null ? this.rx() * 2 : this.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)) + return height == null ? this.ry() * 2 : this.ry(new SVG.Number(height).divide(2)) } // Custom size function , size: function(width, height) { var p = proportionalSize(this.bbox(), width, height) - return this.attr({ - rx: new SVG.Number(p.width).divide(2) - , ry: new SVG.Number(p.height).divide(2) - }) - } - - } - - // Add parent method -, construct: { - // Create circle element, based on ellipse - circle: function(size) { - return this.ellipse(size, size) + return this + .rx(new SVG.Number(p.width).divide(2)) + .ry(new SVG.Number(p.height).divide(2)) } - // Create an ellipse - , ellipse: function(width, height) { - return this.put(new SVG.Ellipse).size(width, height).move(0, 0) - } - - } - })
\ No newline at end of file |