From bd7e10cb46e0cb113983c69f4f48c7a42a776809 Mon Sep 17 00:00:00 2001 From: wout Date: Thu, 30 Jan 2014 19:44:40 +0100 Subject: Added `relative()`method for relative translations --- src/relative.js | 28 ++++++++++++++++++++++++++++ src/set.js | 22 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/relative.js (limited to 'src') diff --git a/src/relative.js b/src/relative.js new file mode 100644 index 0000000..2d02c08 --- /dev/null +++ b/src/relative.js @@ -0,0 +1,28 @@ +// +SVG.extend(SVG.Element, SVG.FX, { + // Relative methods + relative: function() { + var b, e = this + + return { + // Move over x axis + x: function(x) { + b = e.bbox() + + return e.x(b.x + (x || 0)) + } + // Move over y axis + , y: function(y) { + b = e.bbox() + + return e.y(b.y + (y || 0)) + } + // Move over x and y axes + , move: function(x, y) { + this.x(x) + return this.y(y) + } + } + } + +}) \ No newline at end of file diff --git a/src/set.js b/src/set.js index 1fba388..3808a91 100755 --- a/src/set.js +++ b/src/set.js @@ -56,6 +56,28 @@ SVG.extend(SVG.Set, { , valueOf: function() { return this.members } + // Get the bounding box of all members included or empty box if set has no items +, bbox: function(){ + var box = new SVG.BBox() + + /* return an empty box of there are no members */ + if (this.members.length == 0) + return box + + /* get the first rbox and update the target bbox */ + var rbox = this.members[0].rbox() + box.x = rbox.x + box.y = rbox.y + box.width = rbox.width + box.height = rbox.height + + this.each(function() { + /* user rbox for correct position and visual representation */ + box = box.merge(this.rbox()) + }) + + return box + } }) -- cgit v1.2.3