diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-04-30 22:29:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-30 22:29:10 +0200 |
commit | bd04216e0b13114e985ad144d5ca006c5a6a0087 (patch) | |
tree | 93fdcad68b1bf662c95d520a642cb66ad4f5f53c | |
parent | 0ba5e1f394911c66441ea770e09338e82fb6ef49 (diff) | |
download | svg.js-bd04216e0b13114e985ad144d5ca006c5a6a0087.tar.gz svg.js-bd04216e0b13114e985ad144d5ca006c5a6a0087.zip |
Adds the intended functionality to call animate functions with multiple parameter (#671)
e.g. `el.animate().zoom(level, point)`
-rw-r--r-- | spec/spec/fx.js | 4 | ||||
-rw-r--r-- | src/fx.js | 36 | ||||
-rw-r--r-- | src/textpath.js | 3 |
3 files changed, 31 insertions, 12 deletions
diff --git a/spec/spec/fx.js b/spec/spec/fx.js index e17cb95..d6d87f2 100644 --- a/spec/spec/fx.js +++ b/spec/spec/fx.js @@ -2547,7 +2547,7 @@ describe('FX', function() { spyOn(fx, 'add') fx.plot('5 5 30 29 40 19 12 30') - expect(fx.add).toHaveBeenCalledWith('plot', '5 5 30 29 40 19 12 30') + expect(fx.add).toHaveBeenCalledWith('plot', new SVG.PointArray('5 5 30 29 40 19 12 30')) }) it('also accept parameter list', function() { @@ -2556,7 +2556,7 @@ describe('FX', function() { spyOn(fx, 'add') fx.plot(5, 5, 10, 10) - expect(fx.add).toHaveBeenCalledWith('plot', [5, 5, 10, 10]) + expect(fx.add).toHaveBeenCalledWith('plot', new SVG.PointArray([5, 5, 10, 10])) }) }) @@ -214,7 +214,7 @@ SVG.FX = SVG.invent({ // updates all animations to the current state of the element // this is important when one property could be changed from another property , initAnimations: function() { - var i, source + var i, j, source var s = this.situation if(s.init) return this @@ -222,12 +222,26 @@ SVG.FX = SVG.invent({ for(i in s.animations){ source = this.target()[i]() - // The condition is because some methods return a normal number instead - // of a SVG.Number - if(s.animations[i] instanceof SVG.Number) - source = new SVG.Number(source) + if(!Array.isArray(source)) { + source = [source] + } + + if(!Array.isArray(s.animations[i])) { + s.animations[i] = [s.animations[i]] + } + + //if(s.animations[i].length > source.length) { + // source.concat = source.concat(s.animations[i].slice(source.length, s.animations[i].length)) + //} - s.animations[i] = source.morph(s.animations[i]) + for(j = source.length; j--;) { + // The condition is because some methods return a normal number instead + // of a SVG.Number + if(s.animations[i][j] instanceof SVG.Number) + source[j] = new SVG.Number(source[j]) + + s.animations[i][j] = source[j].morph(s.animations[i][j]) + } } for(i in s.attrs){ @@ -845,9 +859,13 @@ SVG.extend(SVG.FX, { return this } // Add animatable plot -, plot: function() { - // We use arguments here since SVG.Line's plot method can be passed 4 parameters - return this.add('plot', arguments.length > 1 ? [].slice.call(arguments) : arguments[0]) +, plot: function(a, b, c, d) { + // Lines can be plotted with 4 arguments + if(arguments.length == 4) { + return this.plot([a, b, c, d]) + } + + return this.add('plot', new (this.target().morphArray)(a)) } // Add leading method , leading: function(value) { diff --git a/src/textpath.js b/src/textpath.js index 4750310..18e2149 100644 --- a/src/textpath.js +++ b/src/textpath.js @@ -10,8 +10,9 @@ SVG.TextPath = SVG.invent({ // Add parent method , construct: { + morphArray: SVG.PathArray // Create path for text to run on - path: function(d) { + , path: function(d) { // create textPath element var path = new SVG.TextPath , track = this.doc().defs().path(d) |