diff options
author | wout <wout@impinc.co.uk> | 2013-03-12 13:31:09 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-03-12 13:31:09 +0100 |
commit | 4bd21ec64a0e3c1d4d0acf5685b2230285c7c16b (patch) | |
tree | 0300a47ca1b263ae0cd0fdb5fe76218ceb9aa745 /src/line.js | |
parent | 6c6c82ed59533f44f8754b69d47e3b11cd6dd129 (diff) | |
download | svg.js-4bd21ec64a0e3c1d4d0acf5685b2230285c7c16b.tar.gz svg.js-4bd21ec64a0e3c1d4d0acf5685b2230285c7c16b.zip |
Added x(), y(), cx(), cy() and matrix
Diffstat (limited to 'src/line.js')
-rw-r--r-- | src/line.js | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/line.js b/src/line.js index 0712f1e..7407983 100644 --- a/src/line.js +++ b/src/line.js @@ -3,45 +3,43 @@ SVG.Line = function() { } // Inherit from SVG.Shape -SVG.Line.prototype = new SVG.Shape() +SVG.Line.prototype = new SVG.Shape // Add required methods SVG.extend(SVG.Line, { - // Move line - move: function(x, y) { - var bbox = this.bbox() + // Move over x-axis + x: function(x) { + var b = this.bbox() return this.attr({ - x1: this.attr('x1') - bbox.x + x - , y1: this.attr('y1') - bbox.y + y - , x2: this.attr('x2') - bbox.x + x - , y2: this.attr('y2') - bbox.y + y + x1: this.attrs.x1 - b.x + x + , x2: this.attrs.x2 - b.x + x }) } - // Move element by its center -, center: function(x, y) { - var bbox = this.bbox() + // Move over y-axis +, y: function(y) { + var b = this.bbox() - return this.move(x - bbox.width / 2, y - bbox.height / 2) + return this.attr({ + y1: this.attrs.y1 - b.y + y + , y2: this.attrs.y2 - b.y + y + }) + } + // Move by center over x-axis +, cx: function(x) { + return this.x(x - this.bbox().width / 2) + } + // Move by center over y-axis +, cy: function(y) { + return this.y(y - this.bbox().height / 2) } // Set line size by width and height , size: function(width, height) { - var bbox = this.bbox() + var b = this.bbox() return this - .attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', bbox.x + width) - .attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', bbox.y + height) - } -}) - -// Extend all container modules -SVG.extend(SVG.Container, { - line: function(x1, y1, x2, y2) { - return this.put(new SVG.Line().attr({ - x1: x1 - , y1: y1 - , x2: x2 - , y2: y2 - })) + .attr(this.attrs.x1 < this.attrs.x2 ? 'x2' : 'x1', b.x + width) + .attr(this.attrs.y1 < this.attrs.y2 ? 'y2' : 'y1', b.y + height) } + })
\ No newline at end of file |