diff options
author | Rémi Tétreault <tetreault.remi@gmail.com> | 2017-04-15 22:38:22 -0400 |
---|---|---|
committer | Rémi Tétreault <tetreault.remi@gmail.com> | 2017-04-15 22:38:22 -0400 |
commit | 35ff6ba258986c508f706009f39c12b667e3a2f2 (patch) | |
tree | 02eb9141323d2b46a24eaf0647ac8b7e8b736da6 /src/transform.js | |
parent | 82f60c4d8a3c6ee5cf877b5e971f6180289f98b2 (diff) | |
download | svg.js-35ff6ba258986c508f706009f39c12b667e3a2f2.tar.gz svg.js-35ff6ba258986c508f706009f39c12b667e3a2f2.zip |
Fix the flip transform on both axis
This fix the bug that made calling flip without any argument (`element.flip()`)
not work.
Diffstat (limited to 'src/transform.js')
-rw-r--r-- | src/transform.js | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/transform.js b/src/transform.js index 0643a8a..b738603 100644 --- a/src/transform.js +++ b/src/transform.js @@ -3,7 +3,7 @@ SVG.extend(SVG.Element, { transform: function(o, relative) { // get target in case of the fx module, otherwise reference this var target = this - , matrix + , matrix, bbox // act as a getter if (typeof o !== 'object') { @@ -76,10 +76,19 @@ SVG.extend(SVG.Element, { // act on flip } else if (o.flip) { - matrix = matrix.flip( - o.flip - , o.offset == null ? target.bbox()['c' + o.flip] : o.offset - ) + if(o.flip == 'x' || o.flip == 'y') { + o.offset = o.offset == null ? target.bbox()['c' + o.flip] : o.offset + } else { + if(o.offset == null) { + bbox = target.bbox() + o.flip = bbox.cx + o.offset = bbox.cy + } else { + o.flip = o.offset + } + } + + matrix = new SVG.Matrix().flip(o.flip, o.offset) // act on translate } else if (o.x != null || o.y != null) { @@ -101,7 +110,7 @@ SVG.extend(SVG.FX, { transform: function(o, relative) { // get target in case of the fx module, otherwise reference this var target = this.target() - , matrix + , matrix, bbox // act as a getter if (typeof o !== 'object') { @@ -150,10 +159,19 @@ SVG.extend(SVG.FX, { // act on flip } else if (o.flip) { - matrix = new SVG.Matrix().flip( - o.flip - , o.offset == null ? target.bbox()['c' + o.flip] : o.offset - ) + if(o.flip == 'x' || o.flip == 'y') { + o.offset = o.offset == null ? target.bbox()['c' + o.flip] : o.offset + } else { + if(o.offset == null) { + bbox = target.bbox() + o.flip = bbox.cx + o.offset = bbox.cy + } else { + o.flip = o.offset + } + } + + matrix = new SVG.Matrix().flip(o.flip, o.offset) // act on translate } else if (o.x != null || o.y != null) { |