diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/fx.js | 30 | ||||
-rw-r--r-- | src/helpers.js | 20 | ||||
-rw-r--r-- | src/matrix.js | 26 | ||||
-rwxr-xr-x | src/sugar.js | 4 |
4 files changed, 36 insertions, 44 deletions
@@ -226,26 +226,26 @@ SVG.FX = SVG.invent({ } // Add animatable transformations , transform: function(o, v) { - if (arguments.length == 1) { - /* parse matrix string */ - o = parseMatrix(o) + // if (arguments.length == 1) { + // /* parse matrix string */ + // o = parseMatrix(o) - /* dlete matrixstring from object */ - delete o.matrix + // /* dlete matrixstring from object */ + // delete o.matrix - /* store matrix values */ - for (v in o) - this.trans[v] = { from: this.target.trans[v], to: o[v] } + // /* store matrix values */ + // for (v in o) + // this.trans[v] = { from: this.target.trans[v], to: o[v] } - } else { - /* apply transformations as object if key value arguments are given*/ - var transform = {} - transform[o] = v + // } else { + // /* apply transformations as object if key value arguments are given*/ + // var transform = {} + // transform[o] = v - this.transform(transform) - } + // this.transform(transform) + // } - return this + // return this } // Add animatable styles , style: function(s, v) { diff --git a/src/helpers.js b/src/helpers.js index ae4eb04..15842b5 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -124,26 +124,6 @@ function fullBox(b) { return b } -// Parse a matrix string -function parseMatrix(o) { - if (o.matrix) { - // Split matrix string - var m = o.matrix.replace(/\s/g, '').split(',') - - // Pasrse values - if (m.length == 6) { - o.a = parseFloat(m[0]) - o.b = parseFloat(m[1]) - o.c = parseFloat(m[2]) - o.d = parseFloat(m[3]) - o.e = parseFloat(m[4]) - o.f = parseFloat(m[5]) - } - } - - return o -} - // Get id from reference string function idFromReference(url) { var m = url.toString().match(SVG.regex.reference) diff --git a/src/matrix.js b/src/matrix.js index 314e1e0..e2afbef 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -57,26 +57,36 @@ SVG.Matrix = SVG.invent({ } // Scale , scale: function(x, y, cx, cy) { - if (y == null) - return new SVG.Matrix(this.native().scale(x)) - else - return new SVG.Matrix(this.native().scaleNonUniform(x, y)) + // Support universal scale + if (arguments.length == 1 || arguments.length == 3) + y = x + if (arguments.length == 3) { + cy = cx + cx = y + } + + return this + .multiply(new SVG.Matrix(1, 0, 0, 1, cx || 0, cy || 0)) + .multiply(new SVG.Matrix(x, 0, 0, y, 0, 0)) + .multiply(new SVG.Matrix(1, 0, 0, 1, -cx || 0, -cy || 0)) } // Rotate - , rotate: function(d, x, y) { + , rotate: function(d, cx, cy) { // Convert degrees to radians d = SVG.utils.radians(d) - return new SVG.Matrix(1, 0, 0, 1, x, y) + return this + .multiply(new SVG.Matrix(1, 0, 0, 1, cx || 0, cy || 0)) .multiply(new SVG.Matrix(Math.cos(d), Math.sin(d), -Math.sin(d), Math.cos(d), 0, 0)) - .multiply(new SVG.Matrix(1, 0, 0, 1, -x, -y)) + .multiply(new SVG.Matrix(1, 0, 0, 1, -cx || 0, -cy || 0)) } // Flip , flip: function(a) { return new SVG.Matrix(this.native()['flip' + a.toUpperCase()]()) } // Skew - , skew: function(x, y) { + , skew: function(x, y, cx, cy) { + // IMPLEMENT SKEW CENTER POINT return new SVG.Matrix(this.native().skewX(x || 0).skewY(y || 0)) } // Convert this to SVGMatrix diff --git a/src/sugar.js b/src/sugar.js index e759812..cf19112 100755 --- a/src/sugar.js +++ b/src/sugar.js @@ -39,7 +39,9 @@ SVG.extend(SVG.Element, SVG.FX, { } // Scale , scale: function(x, y, cx, cy) { - return this.transform({ scaleX: x, scaleY: y, cx: cx, cy: cy }) + return arguments.length == 1 || arguments.length == 3 ? + this.transform({ scale: x, cx: y, cy: cx }) : + this.transform({ scaleX: x, scaleY: y, cx: cx, cy: cy }) } // Translate , translate: function(x, y) { |