summaryrefslogtreecommitdiffstats
path: root/src/transform.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/transform.js')
-rw-r--r--src/transform.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/transform.js b/src/transform.js
new file mode 100644
index 0000000..c78865d
--- /dev/null
+++ b/src/transform.js
@@ -0,0 +1,47 @@
+SVG.extend(SVG.Element, {
+ // Add transformations
+ transform: function(o) {
+ // Full getter
+ if (o == null)
+ return this.ctm().extract()
+
+ // Get current matrix
+ var matrix = new SVG.Matrix(this)
+
+ // Act on matrix
+ if (o.a != null)
+ matrix = matrix.multiply(new SVG.Matrix(o))
+
+ // 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
+ )
+
+ // 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
+ )
+
+ // Act on skew
+ else if (o.skewX || o.skewY)
+ matrix = matrix.skew(o.skewX, o.skewY)
+
+ // Act on translate
+ else if (o.x || o.y)
+ matrix = matrix.translate(o.x, o.y)
+console.log(o, matrix)
+ return this.attr('transform', matrix)
+ }
+ // Reset all transformations
+, untransform: function() {
+ return this.attr('transform', null)
+ }
+
+}) \ No newline at end of file