diff options
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 |