summaryrefslogtreecommitdiffstats
path: root/src/transform.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/transform.js')
-rw-r--r--src/transform.js41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/transform.js b/src/transform.js
index ba4cdb9..d33a411 100644
--- a/src/transform.js
+++ b/src/transform.js
@@ -1,51 +1,56 @@
-SVG.extend(SVG.Element, {
+SVG.extend(SVG.Element, SVG.FX, {
// Add transformations
transform: function(o) {
- // Full getter
+ // get target in case of the fx module, otherwise reference this
+ var target = this.target || this
+
+ // full getter
if (o == null)
- return this.ctm().extract()
+ return target.ctm().extract()
- // Singular getter
+ // singular getter
else if (typeof o === 'string')
- return this.ctm().extract()[o]
+ return target.ctm().extract()[o]
- // Get current matrix
- var matrix = new SVG.Matrix(this)
+ // get current matrix
+ var matrix = new SVG.Matrix(target)
- // Act on matrix
+ // act on matrix
if (o.a != null)
matrix = matrix.multiply(new SVG.Matrix(o))
- // Act on rotate
+ // act on rotate
else if (o.rotation)
matrix = matrix.rotate(
o.rotation
- , o.cx == null ? this.bbox().cx : o.cx
- , o.cy == null ? this.bbox().cy : o.cy
+ , o.cx == null ? target.bbox().cx : o.cx
+ , o.cy == null ? target.bbox().cy : o.cy
)
- // Act on scale
+ // act on scale
else if (o.scale != null || o.scaleX != null || o.scaleY != null)
matrix = matrix.scale(
o.scale != null ? o.scale : o.scaleX != null ? o.scaleX : 1
, o.scale != null ? o.scale : o.scaleY != null ? o.scaleY : 1
- , o.cx != null ? o.cx : this.bbox().x
- , o.cy != null ? o.cy : this.bbox().y
+ , o.cx != null ? o.cx : target.bbox().x
+ , o.cy != null ? o.cy : target.bbox().y
)
- // Act on skew
+ // act on skew
else if (o.skewX || o.skewY)
matrix = matrix.skew(o.skewX, o.skewY)
- // Act on translate
+ // act on translate
else if (o.x || o.y)
matrix = matrix.translate(o.x, o.y)
return this.attr('transform', matrix)
}
+})
+
+SVG.extend(SVG.Element, {
// Reset all transformations
-, untransform: function() {
+ untransform: function() {
return this.attr('transform', null)
}
-
}) \ No newline at end of file