diff options
author | wout <wout@impinc.co.uk> | 2012-12-27 19:08:25 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-27 19:08:25 +0100 |
commit | 92628abe74749f8106ec271368c87df6b6f3c134 (patch) | |
tree | 1ae95b4f2ef1555d7ebfed618a6eff8125753226 /src/element.js | |
parent | 76af3112c3f3778eb0dfcbaf4517a7b46a3fb403 (diff) | |
download | svg.js-92628abe74749f8106ec271368c87df6b6f3c134.tar.gz svg.js-92628abe74749f8106ec271368c87df6b6f3c134.zip |
Bug fix in bbox()
Diffstat (limited to 'src/element.js')
-rw-r--r-- | src/element.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/element.js b/src/element.js index 33813c4..5a4d4ed 100644 --- a/src/element.js +++ b/src/element.js @@ -28,6 +28,13 @@ SVG.extend(SVG.Element, { return this.attr({ width: w, height: h }); }, + // position element by its center + center: function(x, y) { + var b = this.bbox(); + + return this.move(x - b.width / 2, y - b.height / 2); + }, + // remove element remove: function() { return this.parent != null ? this.parent.remove(this) : void 0; @@ -130,10 +137,10 @@ SVG.extend(SVG.Element, { return { // include translations on x an y x: b.x + this.trans.x, - y: b.x + this.trans.y, + y: b.y + this.trans.y, // add the center cx: b.x + this.trans.x + b.width / 2, - cy: b.x + this.trans.y + b.height / 2, + cy: b.y + this.trans.y + b.height / 2, // plain width and height width: b.width, height: b.height |