aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-05-30 08:54:00 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-05-30 08:54:00 +0200
commit599ab86152869496f71ef2a4b3af2d695140fcdf (patch)
tree49b352e0278bbb88ad04cfca5b5499bae29f1ec7 /src
parentc59a502dc7cd58030983d1271cd9f3a8f8128a91 (diff)
downloadsvg.js-599ab86152869496f71ef2a4b3af2d695140fcdf.tar.gz
svg.js-599ab86152869496f71ef2a4b3af2d695140fcdf.zip
fixed declaritive again, fromArray now works on all object instances
Diffstat (limited to 'src')
-rw-r--r--src/array.js3
-rw-r--r--src/boxes.js3
-rw-r--r--src/matrix.js4
-rw-r--r--src/morph.js40
-rw-r--r--src/number.js5
-rw-r--r--src/patharray.js3
-rw-r--r--src/pointarray.js4
-rw-r--r--src/runner.js31
8 files changed, 39 insertions, 54 deletions
diff --git a/src/array.js b/src/array.js
index ebfe1b2..aa43d5c 100644
--- a/src/array.js
+++ b/src/array.js
@@ -61,9 +61,6 @@ SVG.extend(SVG.Array, {
toArray: function () {
return this.value
},
- fromArray: function (a) {
- return new SVG.Array(a)
- },
// Convert array to string
toString: function () {
return this.value.join(' ')
diff --git a/src/boxes.js b/src/boxes.js
index 7e270bf..a9247ef 100644
--- a/src/boxes.js
+++ b/src/boxes.js
@@ -71,9 +71,6 @@ SVG.Box = SVG.invent({
toArray: function () {
return [this.x, this.y, this.width, this.height]
},
- fromArray: function (a) {
- return new SVG.Box(a)
- },
morph: function (x, y, width, height) {
this.destination = new SVG.Box(x, y, width, height)
return this
diff --git a/src/matrix.js b/src/matrix.js
index 4ddb43d..a8e92aa 100644
--- a/src/matrix.js
+++ b/src/matrix.js
@@ -331,10 +331,6 @@ SVG.Matrix = SVG.invent({
toArray: function () {
return [this.a, this.b, this.c, this.d, this.e, this.f]
- },
-
- fromArray: function (a) {
- return new SVG.Matrix(a)
}
},
diff --git a/src/morph.js b/src/morph.js
index 87f82e0..cf674bf 100644
--- a/src/morph.js
+++ b/src/morph.js
@@ -9,6 +9,7 @@ SVG.Morphable = SVG.invent({
this._type = null
this._context = null
this.modifier = function(arr) { return arr }
+ this._morphObj = null
},
extend: {
@@ -81,6 +82,7 @@ SVG.Morphable = SVG.invent({
}
var result = (new this._type(value)).toArray()
+ this._morphObj = this._morphObj || new this._type()
this._context = this._context
|| Array.apply(null, Array(result.length)).map(Object)
return result
@@ -106,7 +108,7 @@ SVG.Morphable = SVG.invent({
// arr.push(this.stepper(this._from[i], this._to[i]))
// }
- return this._type.prototype.fromArray(
+ return this._morphObj.fromArray(
this.modifier(
this._from.map(function (i, index) {
return _this._stepper.step(i, _this._to[index], pos, _this._context[index], _this._context)
@@ -123,6 +125,7 @@ SVG.Morphable = SVG.invent({
SVG.Morphable.NonMorphable = SVG.invent({
create: function (val) {
+ val = Array.isArray(val) ? val[0] : val
this.value = val
},
@@ -133,22 +136,28 @@ SVG.Morphable.NonMorphable = SVG.invent({
toArray: function () {
return [this.value]
- },
-
- fromArray: function (arr) {
- return new SVG.Morphable.NonMorphable(arr[0])
}
}
})
SVG.Morphable.TransformBag = SVG.invent({
create: function (obj) {
+ if(Array.isArray(obj)) {
+ obj = {
+ scaleX: arr[0],
+ scaleY: arr[1],
+ shear: arr[2],
+ rotate: arr[3],
+ translateX: arr[4],
+ translateY: arr[5]
+ }
+ }
this.value = new SVG.Matrix(obj)
},
extend: {
valueOf: function () {
- return this.value
+ return this.valueW
},
toArray: function (){
@@ -162,17 +171,6 @@ SVG.Morphable.TransformBag = SVG.invent({
v.translateX,
v.translateY
]
- },
-
- fromArray: function (arr) {
- return new SVG.Morphable.TransformBag({
- scaleX: arr[0],
- scaleY: arr[1],
- shear: arr[2],
- rotate: arr[3],
- translateX: arr[4],
- translateY: arr[5]
- })
}
}
})
@@ -213,10 +211,6 @@ SVG.Morphable.ObjectBag = SVG.invent({
toArray: function (){
return this.values
- },
-
- fromArray: function (arr) {
- return new SVG.Morphable.ObjectBag(arr)
}
}
})
@@ -241,6 +235,10 @@ SVG.extend(SVG.MorphableTypes, {
.from(this.valueOf())
.to(val, args)
},
+ fromArray: function () {
+ this.constructor.apply(this, arguments)
+ return this
+ }
})
diff --git a/src/number.js b/src/number.js
index f1ad9e0..1a24954 100644
--- a/src/number.js
+++ b/src/number.js
@@ -3,6 +3,8 @@
SVG.Number = SVG.invent({
// Initialize
create: function (value, unit) {
+ value = Array.isArray(value) ? value[0] : value
+
// initialize defaults
this.value = 0
this.unit = unit || ''
@@ -48,9 +50,6 @@ SVG.Number = SVG.invent({
toArray: function () {
return [this.value]
},
- fromArray: function (val) {
- return new SVG.Number(val[0])
- },
valueOf: function () {
return this.value
},
diff --git a/src/patharray.js b/src/patharray.js
index cbb4ced..4432df3 100644
--- a/src/patharray.js
+++ b/src/patharray.js
@@ -92,9 +92,6 @@ SVG.extend(SVG.PathArray, {
return [].concat.call(prev, curr)
}, [])
},
- fromArray: function (a) {
- return new SVG.PathArray(a)
- },
// Move path string
move: function (x, y) {
// get bounding box of current situation
diff --git a/src/pointarray.js b/src/pointarray.js
index f80911a..aa5f84a 100644
--- a/src/pointarray.js
+++ b/src/pointarray.js
@@ -25,10 +25,6 @@ SVG.extend(SVG.PointArray, {
}, [])
},
- fromArray: function (a) {
- return new SVG.PointArray(a)
- },
-
// Convert array to line object
toLine: function () {
return {
diff --git a/src/runner.js b/src/runner.js
index 4431f4f..1b0ce90 100644
--- a/src/runner.js
+++ b/src/runner.js
@@ -168,6 +168,7 @@ SVG.Runner = SVG.invent({
return this
},
+ // FIXME: When not using queue the example is not working anymore
during: function (fn) {
return this.on('during', fn, this)
},
@@ -195,19 +196,23 @@ SVG.Runner = SVG.invent({
// positive always, so if its negative, we ignore it.
if (this._isDeclarative && dt < 0) return this
- // If the user gives us a huge dt, figure out how many full loops
- // have passed during this time. A full loop is the time required to
- var absolute = this._time + dt + this._wait
- var period = this._duration + this._wait
- var nPeriods = Math.floor(absolute / period)
- this._loopsDone += nPeriods
- this._time = ((absolute % period) + period) % period - this._wait
-
- // FIXME: Without that it loops forever even without trying to loop
- if(this._loopsDone >= this._times) this._time = Infinity
-
- // Make sure we reverse the code if we had an odd number of loops
- this.reversed = (nPeriods % 2 === 0) ? this.reversed : !this.reversed
+ // When no duration is set, all numbers including this._time end up NaN
+ // and that makes step returning at the first check
+ if(!this._isDeclarative) {
+ // If the user gives us a huge dt, figure out how many full loops
+ // have passed during this time. A full loop is the time required to
+ var absolute = this._time + dt + this._wait
+ var period = this._duration + this._wait
+ var nPeriods = Math.floor(absolute / period)
+ this._loopsDone += nPeriods
+ this._time = ((absolute % period) + period) % period - this._wait
+
+ // FIXME: Without that it loops forever even without trying to loop
+ if(this._loopsDone >= this._times) this._time = Infinity
+
+ // Make sure we reverse the code if we had an odd number of loops
+ this.reversed = (nPeriods % 2 === 0) ? this.reversed : !this.reversed
+ }
// Increment the time and read out the parameters
// this._time += dt