aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/SpecRunner.html6
-rw-r--r--spec/spec/animator.js2
-rw-r--r--spec/spec/morphing.js6
-rw-r--r--spec/spec/runner.js18
-rw-r--r--src/morph.js119
-rw-r--r--src/runner.js2
6 files changed, 83 insertions, 70 deletions
diff --git a/spec/SpecRunner.html b/spec/SpecRunner.html
index efc58a3..2a9b8d8 100644
--- a/spec/SpecRunner.html
+++ b/spec/SpecRunner.html
@@ -84,7 +84,7 @@
<script src="spec/line.js"></script>
<script src="spec/marker.js"></script>
<script src="spec/mask.js"></script>-->
- <script src="spec/matrix.js"></script>
+ <!--<script src="spec/matrix.js"></script>-->
<!--<script src="spec/number.js"></script>
<script src="spec/path.js"></script>
<script src="spec/pattern.js"></script>
@@ -105,8 +105,8 @@
<script src="spec/utils.js"></script>
<script src="spec/viewbox.js"></script> -->
- <!-- <script src="spec/morphing.js"></script>
+ <script src="spec/morphing.js"></script>
<script src="spec/animator.js"></script>
- <script src="spec/runner.js"></script> -->
+ <script src="spec/runner.js"></script>
</body>
</html>
diff --git a/spec/spec/animator.js b/spec/spec/animator.js
index a331c16..a36408c 100644
--- a/spec/spec/animator.js
+++ b/spec/spec/animator.js
@@ -27,7 +27,7 @@ describe('SVG.Animator', function () {
it('cancels a timeout which was created with timeout()', function () {
var spy = jasmine.createSpy('tester')
var id = SVG.Animator.timeout(spy, 100)
- SVG.Animator.cancelTimeout(id)
+ SVG.Animator.clearTimeout(id)
expect(spy).not.toHaveBeenCalled()
jasmine.RequestAnimationFrame.tick(100)
diff --git a/spec/spec/morphing.js b/spec/spec/morphing.js
index 63a6cf2..4074d7e 100644
--- a/spec/spec/morphing.js
+++ b/spec/spec/morphing.js
@@ -103,14 +103,14 @@ describe('Morphing', function () {
})
it(`Creates a morphable out of an SVG.Morphable.TransformBag`, function () {
- var morpher = new SVG.Morphable.TransformBag({}).to({rotate: 50, translateX: 20})
+ var morpher = new SVG.Morphable.TransformBag({rotate: 0, translateX: 0})
+ .to({rotate: 50, translateX: 20})
expect(morpher instanceof SVG.Morphable).toBe(true)
expect(morpher.type()).toBe(SVG.Morphable.TransformBag)
expect(morpher.at(0.5) instanceof SVG.Morphable.TransformBag).toBe(true)
- // TODO: This fails because of roundingerrors and the FIXME above
- expect(morpher.at(0.5).valueOf().decompose()).toBe(jasmine.objectContaining({rotate: 25, translateX: 10}))
+ expect(morpher.at(0.5)).toEqual(jasmine.objectContaining({rotate: 25, translateX: 10}))
})
it(`Creates a morphable out of an SVG.Morphable.ObjectBag`, function () {
diff --git a/spec/spec/runner.js b/spec/spec/runner.js
index 1b7ed41..c1c5972 100644
--- a/spec/spec/runner.js
+++ b/spec/spec/runner.js
@@ -125,10 +125,10 @@ describe('SVG.Runner', function () {
runner.queue(initFn, runFn, true)
expect(runner._queue[0]).toEqual(jasmine.objectContaining({
- alwaysInitialise: true,
initialiser: initFn,
initialised: false,
- runner: runFn
+ runner: runFn,
+ finished: false
}))
})
})
@@ -182,7 +182,7 @@ describe('SVG.Runner', function () {
expect(runner.step()).toBe(runner)
})
- it('calls initFn once and runFn at every step when alwaysInitialise is false', function() {
+ it('calls initFn once and runFn at every step', function() {
var runner = new SVG.Runner()
runner.queue(initFn, runFn, false)
@@ -195,8 +195,8 @@ describe('SVG.Runner', function () {
expect(runFn.calls.count()).toBe(2)
})
- it('calls initFn and runFn at every step when alwaysInitialise is true', function() {
- var runner = new SVG.Runner()
+ it('calls initFn on every step if its declaritive', function() {
+ var runner = new SVG.Runner(new SVG.Controller())
runner.queue(initFn, runFn, true)
runner.step()
@@ -775,13 +775,17 @@ describe('SVG.Runner', function () {
var runner = new SVG.Runner(1000)
var timeline = new SVG.Timeline()
- // FIXME: schedulung a runner on a timeline does not set the timeline for the runner!
runner.schedule(timeline)
- var runner2 = runner.animate(1000)
+ var runner2 = runner.animate(500, 1000)
expect(runner2.timeline()).toBe(timeline)
expect(runner2.time()).toBe(-1000)
+
+ expect(timeline.schedule()).toEqual(jasmine.objectContaining([
+ jasmine.objectContaining({start: 0, duration: 1000, end: 1000, runner: runner}),
+ jasmine.objectContaining({start: 1000, duration: 500, end: 1500, runner: runner2})
+ ]))
})
})
diff --git a/src/morph.js b/src/morph.js
index 6a9e651..bf94efc 100644
--- a/src/morph.js
+++ b/src/morph.js
@@ -21,12 +21,11 @@ SVG.Morphable = SVG.invent({
return this
},
- to: function (val, modifier) {
+ to: function (val) {
if(val == null)
return this._to
this._to = this._set(val)
- this.modifier = modifier || this.modifier
return this
},
@@ -131,7 +130,7 @@ SVG.Morphable.NonMorphable = SVG.invent({
}
})
-SVG.Morphable.TransformBag2 = SVG.invent({
+SVG.Morphable.TransformBag = SVG.invent({
create: function (obj) {
if(Array.isArray(obj)) {
obj = {
@@ -146,7 +145,7 @@ SVG.Morphable.TransformBag2 = SVG.invent({
}
}
- Object.assign(this, obj)
+ Object.assign(this, SVG.Morphable.TransformBag.defaults, obj)
},
extend: {
@@ -167,57 +166,68 @@ SVG.Morphable.TransformBag2 = SVG.invent({
}
})
-SVG.Morphable.TransformBag = SVG.invent({
- inherit: SVG.Matrix,
- create: function (obj) {
- if(Array.isArray(obj)) {
- obj = {
- scaleX: obj[0],
- scaleY: obj[1],
- shear: obj[2],
- rotate: obj[3],
- translateX: obj[4],
- translateY: obj[5],
- originX: obj[6],
- originY: obj[7]
- }
- }
-
- var data = {...(obj || {})}
-
- if (typeof data.origin == 'string') {
- delete data.origin
- }
-
- SVG.Matrix.call(this, data)
-
-
- if (data.origin) {
- data.originX = data.origin[0]
- data.originY = data.origin[1]
- }
-
- this.originX = data.originX || 0
- this.originY = data.originY || 0
- },
-
- extend: {
- toArray: function (){
- var v = this.decompose(this.originX, this.originY)
+SVG.Morphable.TransformBag.defaults = {
+ scaleX: 1,
+ scaleY: 1,
+ shear: 0,
+ rotate: 0,
+ translateX: 0,
+ translateY: 0,
+ originX: 0,
+ originY: 0
+}
- return [
- v.scaleX,
- v.scaleY,
- v.shear,
- v.rotate,
- v.translateX,
- v.translateY,
- v.originX,
- v.originY,
- ]
- }
- }
-})
+// SVG.Morphable.TransformBag = SVG.invent({
+// inherit: SVG.Matrix,
+// create: function (obj) {
+// if(Array.isArray(obj)) {
+// obj = {
+// scaleX: obj[0],
+// scaleY: obj[1],
+// shear: obj[2],
+// rotate: obj[3],
+// translateX: obj[4],
+// translateY: obj[5],
+// originX: obj[6],
+// originY: obj[7]
+// }
+// }
+//
+// var data = {...(obj || {})}
+//
+// if (typeof data.origin == 'string') {
+// delete data.origin
+// }
+//
+// SVG.Matrix.call(this, data)
+//
+//
+// if (data.origin) {
+// data.originX = data.origin[0]
+// data.originY = data.origin[1]
+// }
+//
+// this.originX = data.originX || 0
+// this.originY = data.originY || 0
+// },
+//
+// extend: {
+// toArray: function (){
+// var v = this.decompose(this.originX, this.originY)
+//
+// return [
+// v.scaleX,
+// v.scaleY,
+// v.shear,
+// v.rotate,
+// v.translateX,
+// v.translateY,
+// v.originX,
+// v.originY,
+// ]
+// }
+// }
+// })
SVG.Morphable.ObjectBag = SVG.invent({
@@ -264,7 +274,6 @@ SVG.MorphableTypes = [
SVG.PathArray,
SVG.Morphable.NonMorphable,
SVG.Morphable.TransformBag,
- SVG.Morphable.TransformBag2,
SVG.Morphable.ObjectBag,
]
diff --git a/src/runner.js b/src/runner.js
index 3af1ca1..788563c 100644
--- a/src/runner.js
+++ b/src/runner.js
@@ -688,7 +688,7 @@ SVG.extend(SVG.Runner, {
// Create a morepher and set its type
const morpher = new SVG.Morphable()
- .type( affine ? SVG.Morphable.TransformBag2 : SVG.Matrix )
+ .type( affine ? SVG.Morphable.TransformBag : SVG.Matrix )
.stepper(this._stepper)
let origin