summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bbox.js15
-rw-r--r--src/element.js29
2 files changed, 26 insertions, 18 deletions
diff --git a/src/bbox.js b/src/bbox.js
index ee101b2..22c5bcf 100644
--- a/src/bbox.js
+++ b/src/bbox.js
@@ -1,15 +1,16 @@
SVG.BBox = function(element) {
- /* actual, native bounding box */
var box
+
+ /* actual, native bounding box */
try {
box = element.node.getBBox()
- } catch(err) {
+ } catch(e) {
box = {
- x: element.node.clientLeft,
- y: element.node.clientTop,
- width: element.node.clientWidth,
- height: element.node.clientHeight
+ x: element.node.clientLeft
+ , y: element.node.clientTop
+ , width: element.node.clientWidth
+ , height: element.node.clientHeight
}
}
@@ -18,7 +19,7 @@ SVG.BBox = function(element) {
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 */
diff --git a/src/element.js b/src/element.js
index 83e106c..fcf8f3c 100644
--- a/src/element.js
+++ b/src/element.js
@@ -178,7 +178,11 @@ SVG.extend(SVG.Element, {
}
// 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]
@@ -196,6 +200,15 @@ SVG.extend(SVG.Element, {
/* 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)
@@ -217,13 +230,8 @@ SVG.extend(SVG.Element, {
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)
@@ -245,9 +253,8 @@ SVG.extend(SVG.Element, {
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
}