summaryrefslogtreecommitdiffstats
path: root/src/transform.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-07-11 23:36:17 +0200
committerwout <wout@impinc.co.uk>2014-07-11 23:36:17 +0200
commit462d2cd3738c904db0be7086878d1fcc17b79553 (patch)
treeafabf22b2f46e5432dc0d56219872f590eb19892 /src/transform.js
parent7cc2d3635b8ed513e0f4e5be0a1823c1a6ad93dc (diff)
downloadsvg.js-462d2cd3738c904db0be7086878d1fcc17b79553.tar.gz
svg.js-462d2cd3738c904db0be7086878d1fcc17b79553.zip
Completely reworked transform system
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