summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSaivan <savian@me.com>2018-06-28 23:05:16 +1000
committerSaivan <savian@me.com>2018-06-28 23:05:16 +1000
commitad2047507de85ca40b9a83b41bde5522a1aacb05 (patch)
treeb64f6c2ab32011ac6fc73954ff34daeb3e95ed43 /src
parent5836ecaba4d02bd2ff5c1ab727df5086911eda12 (diff)
downloadsvg.js-ad2047507de85ca40b9a83b41bde5522a1aacb05.tar.gz
svg.js-ad2047507de85ca40b9a83b41bde5522a1aacb05.zip
Modified the behaviour of absolute transforms
This commit slightly modifies the behaviour of absolute transforms, we will get them working soon :D
Diffstat (limited to 'src')
-rw-r--r--src/matrix.js13
-rw-r--r--src/morph.js4
-rw-r--r--src/runner.js27
-rw-r--r--src/transform.js4
4 files changed, 37 insertions, 11 deletions
diff --git a/src/matrix.js b/src/matrix.js
index 0d72fea..6947e7e 100644
--- a/src/matrix.js
+++ b/src/matrix.js
@@ -75,7 +75,7 @@ SVG.Matrix = SVG.invent({
},
// Applies a matrix defined by its affine parameters
- compose: function (o) {
+ compose: function (o, ox, oy) {
// Get the parameters
var sx = o.scaleX || 1
var sy = o.scaleY || 1
@@ -217,10 +217,13 @@ SVG.Matrix = SVG.invent({
// Translate matrix
translate: function (x, y) {
- var translation = new SVG.Matrix(this)
- translation.e += x || 0
- translation.f += y || 0
- return translation
+ return new SVG.Matrix(this).translateO(x, y)
+ },
+
+ translateO: function (x, y) {
+ this.e += x || 0
+ this.f += y || 0
+ return this
},
// Scale matrix
diff --git a/src/morph.js b/src/morph.js
index bea349d..543479b 100644
--- a/src/morph.js
+++ b/src/morph.js
@@ -157,6 +157,10 @@ SVG.Morphable.TransformBag = SVG.invent({
}
SVG.Matrix.call(this, obj)
+
+ if (obj && obj.origin){
+ this.translateO(-obj.origin[0], -obj.origin[1])
+ }
//this.value = new SVG.Matrix(obj)
},
diff --git a/src/runner.js b/src/runner.js
index c4fb418..4f8e5f3 100644
--- a/src/runner.js
+++ b/src/runner.js
@@ -672,16 +672,24 @@ SVG.extend(SVG.Runner, {
: SVG.Morphable.TransformBag
morpher = new SVG.Morphable().type(morphType)
- morpher.to(transforms)
-
morpher.stepper(this._stepper)
+ //morpher.to(transforms)
this.queue(function() {
let element = this.element()
element.addRunner(this)
- // If we have an absolute transform, it needs to over-ride any other
- // tranformations that are available on the element
+ if (!origin/* && affine*/) {
+ origin = getOrigin(transforms, element)
+ transforms.origin = origin
+
+ console.log('Affine Parameters:', transforms)
+
+ morpher.to(transforms)
+
+ console.log('End parameters:', morpher.to())
+ }
+
if (!relative && !this._isDeclarative) {
// Deactivate all transforms that have run so far if we are absolute
element._clearTransformRunnersBefore(this)
@@ -689,12 +697,23 @@ SVG.extend(SVG.Runner, {
// Define the starting point for the morpher
let startMatrix = new SVG.Matrix(relative ? undefined : element)
+
+ // make sure to add an origin if we morph affine
+ //if (affine) {
+ startMatrix = startMatrix.translate(-origin[0], -origin[1])
+ //}
+
+ // FIXME: correct the rotation so that it takes the shortest path
+
morpher.from(startMatrix)
+ console.log('Start Parameters:', morpher.from())
+
}, function (pos) {
if (!relative) this.clearTransform()
var matrix = morpher.at(pos)
+ // matrix = matrix.translate(origin[0], origin[1])
this.addTransform(matrix)
return morpher.done()
diff --git a/src/transform.js b/src/transform.js
index 881d80a..6b40161 100644
--- a/src/transform.js
+++ b/src/transform.js
@@ -58,11 +58,11 @@ SVG.extend(SVG.Element, {
}
// Set the origin according to the defined transform
- o.origin = setOrigin (o, element)
+ o.origin = getOrigin (o, this)
// The user can pass a boolean, an SVG.Element or an SVG.Matrix or nothing
var cleanRelative = relative === true ? this : (relative || false)
- var result = new SVG.Matrix(cleanRelative).transform(oWithOrigin)
+ var result = new SVG.Matrix(cleanRelative).transform(o)
return this.attr('transform', result)
}
})