diff options
author | wout <wout@impinc.co.uk> | 2014-02-03 15:14:47 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-02-03 15:14:47 +0100 |
commit | e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a (patch) | |
tree | 2386e9f361d9c5fa1308387aeeaf33f00241b3c5 /src/path.js | |
parent | 7a29817ffd764cf7ab6906250b57f234801c94e0 (diff) | |
download | svg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.tar.gz svg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.zip |
Implemented SVG.invent function and bumped to v1.0rc3
Diffstat (limited to 'src/path.js')
-rwxr-xr-x | src/path.js | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/path.js b/src/path.js index 60e6c73..4ce57f6 100755 --- a/src/path.js +++ b/src/path.js @@ -1,49 +1,49 @@ -SVG.Path = function() { - this.constructor.call(this, SVG.create('path')) -} +SVG.Path = SVG.invent({ + // Initialize node + create: 'path' -// Inherit from SVG.Shape -SVG.Path.prototype = new SVG.Shape + // Inherit from +, inherit: SVG.Shape -SVG.extend(SVG.Path, { - // Plot new poly points - plot: function(p) { - return this.attr('d', (this.array = new SVG.PathArray(p, [{ type:'M',x:0,y:0 }]))) + // Add class methods +, extend: { + // Plot new poly points + plot: function(p) { + return this.attr('d', (this.array = new SVG.PathArray(p, [{ type:'M',x:0,y:0 }]))) + } + // Move by left top corner + , move: function(x, y) { + return this.attr('d', this.array.move(x, y)) + } + // Move by left top corner over x-axis + , x: function(x) { + return x == null ? this.bbox().x : this.move(x, this.bbox().y) + } + // Move by left top corner over y-axis + , y: function(y) { + return y == null ? this.bbox().y : this.move(this.bbox().x, y) + } + // Set element size to given width and height + , size: function(width, height) { + var p = this._proportionalSize(width, height) + + return this.attr('d', this.array.size(p.width, p.height)) + } + // Set width of element + , width: function(width) { + return width == null ? this.bbox().width : this.size(width, this.bbox().height) + } + // Set height of element + , height: function(height) { + return height == null ? this.bbox().height : this.size(this.bbox().width, height) + } + } + + // Add parent method +, construct: { + // Create a wrapped path element + path: function(d) { + return this.put(new SVG.Path).plot(d) + } } - // Move by left top corner -, move: function(x, y) { - return this.attr('d', this.array.move(x, y)) - } - // Move by left top corner over x-axis -, x: function(x) { - return x == null ? this.bbox().x : this.move(x, this.bbox().y) - } - // Move by left top corner over y-axis -, y: function(y) { - return y == null ? this.bbox().y : this.move(this.bbox().x, y) - } - // Set element size to given width and height -, size: function(width, height) { - var p = this._proportionalSize(width, height) - - return this.attr('d', this.array.size(p.width, p.height)) - } - // Set width of element -, width: function(width) { - return width == null ? this.bbox().width : this.size(width, this.bbox().height) - } - // Set height of element -, height: function(height) { - return height == null ? this.bbox().height : this.size(this.bbox().width, height) - } - -}) - -// -SVG.extend(SVG.Container, { - // Create a wrapped path element - path: function(d) { - return this.put(new SVG.Path).plot(d) - } - })
\ No newline at end of file |