diff options
Diffstat (limited to 'dist/svg.js')
-rw-r--r-- | dist/svg.js | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/dist/svg.js b/dist/svg.js index 4aebf60..8925ec5 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -1,4 +1,4 @@ -/* svg.js v0.12-14-g6117eb4 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ +/* svg.js v0.13-1-g9aa9472 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ ;(function() { this.SVG = function(element) { @@ -370,15 +370,26 @@ }) SVG.BBox = function(element) { + var box + /* actual, native bounding box */ - var box = element.node.getBBox() + try { + box = element.node.getBBox() + } catch(e) { + box = { + x: element.node.clientLeft + , y: element.node.clientTop + , width: element.node.clientWidth + , height: element.node.clientHeight + } + } /* include translations on x an y */ this.x = box.x + element.trans.x this.y = box.y + element.trans.y /* plain width and height */ - this.width = box.width * element.trans.scaleX + this.width = box.width * element.trans.scaleX this.height = box.height * element.trans.scaleY /* add the center */ @@ -563,7 +574,11 @@ } // Manage transformations , transform: function(o, v) { - if (typeof o === 'string') { + if (arguments.length == 0) { + /* act as a getter if no argument is given */ + return this.trans + + } else if (typeof o === 'string') { /* act as a getter if only one string argument is given */ if (arguments.length < 2) return this.trans[o] @@ -581,6 +596,15 @@ /* parse matrix */ o = this._parseMatrix(o) + /* ensure correct rotation center point */ + if (o.rotation != null) { + if (o.cx == null) + o.cx = this.bbox().cx + + if (o.cy == null) + o.cy = this.bbox().cy + } + /* merge values */ for (v in o) if (o[v] != null) @@ -602,13 +626,8 @@ transform.push('matrix(' + o.matrix + ')') /* add rotation */ - if (o.rotation != 0) { - transform.push( - 'rotate(' + o.rotation + ',' - + (o.cx != null ? o.cx : this.bbox().cx) + ',' - + (o.cy != null ? o.cy : this.bbox().cy) + ')' - ) - } + if (o.rotation != 0) + transform.push('rotate(' + o.rotation + ',' + o.cx + ',' + o.cy + ')') /* add scale */ if (o.scaleX != 1 || o.scaleY != 1) @@ -630,9 +649,8 @@ if (this._offset) transform.push('translate(' + (-this._offset.x) + ',' + (-this._offset.y) + ')') - /* add only te required transformations */ - if (transform.length > 0) - this.node.setAttribute('transform', transform.join(' ')) + /* update transformations, even if there are none */ + this.node.setAttribute('transform', transform.join(' ')) return this } |