diff options
author | wout <wout@impinc.co.uk> | 2014-01-29 21:20:58 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-01-29 21:20:58 +0100 |
commit | 5b6736666dd85f8a063b87e6c6483ea47be4391c (patch) | |
tree | 139b35c98807ac36cad095af13ef45495958b78f /src/path.js | |
parent | 9688054367938f1e9240c2d8572e94bb0149bc77 (diff) | |
download | svg.js-5b6736666dd85f8a063b87e6c6483ea47be4391c.tar.gz svg.js-5b6736666dd85f8a063b87e6c6483ea47be4391c.zip |
Added SVG.PathArray, updated data() and bumped to v1.0rc1
Diffstat (limited to 'src/path.js')
-rwxr-xr-x | src/path.js | 76 |
1 files changed, 25 insertions, 51 deletions
diff --git a/src/path.js b/src/path.js index e9f4735..60e6c73 100755 --- a/src/path.js +++ b/src/path.js @@ -1,75 +1,49 @@ -SVG.Path = function(unbiased) { +SVG.Path = function() { this.constructor.call(this, SVG.create('path')) - - this.unbiased = !!unbiased } // Inherit from SVG.Shape SVG.Path.prototype = new SVG.Shape SVG.extend(SVG.Path, { - // Move over x-axis - x: function(x) { - return x == null ? this.bbox().x : this.transform('x', x) + // Plot new poly points + plot: function(p) { + return this.attr('d', (this.array = new SVG.PathArray(p, [{ type:'M',x:0,y:0 }]))) } - // Move over y-axis -, y: function(y) { - return y == null ? this.bbox().y : this.transform('y', y) + // Move by left top corner +, move: function(x, y) { + return this.attr('d', this.array.move(x, y)) } - // Set width of element -, width: function(width) { - var b = this.bbox() - - return width == null ? b.width : this.size(width, b.height) + // Move by left top corner over x-axis +, x: function(x) { + return x == null ? this.bbox().x : this.move(x, this.bbox().y) } - // Set height of element -, height: function(height) { - var b = this.bbox() - - return height == null ? b.height : this.size(b.width, height) + // Move by left top corner over y-axis +, y: function(y) { + return y == null ? this.bbox().y : this.move(this.bbox().x, y) } - // Set the actual size in pixels + // Set element size to given width and height , size: function(width, height) { - var scale = width / this._offset.width + var p = this._proportionalSize(width, height) - return this.transform({ - scaleX: scale - , scaleY: height != null ? height / this._offset.height : scale - }) + return this.attr('d', this.array.size(p.width, p.height)) } - // Set path data -, plot: function(data) { - var x = this.trans.scaleX - , y = this.trans.scaleY - - /* native plot */ - this._plot(data) - - /* store offset */ - this._offset = this.transform({ scaleX: 1, scaleY: 1 }).bbox() - - /* get and store the actual offset of the element */ - if (this.unbiased) { - this._offset.x = this._offset.y = 0 - } else { - this._offset.x -= this.trans.x - this._offset.y -= this.trans.y - } - - return this.transform({ scaleX: x, scaleY: y }) + // Set width of element +, width: function(width) { + return width == null ? this.bbox().width : this.size(width, this.bbox().height) } - // Private: Native plot -, _plot: function(data) { - return this.attr('d', data || 'M0,0') + // 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(data, unbiased) { - return this.put(new SVG.Path(unbiased)).plot(data) + path: function(d) { + return this.put(new SVG.Path).plot(d) } })
\ No newline at end of file |