aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaivan <savian@me.com>2018-09-17 14:50:56 +1000
committerSaivan <savian@me.com>2018-09-17 14:50:56 +1000
commita8373f5ee8902089d5ab3a915eb5a31b568d3728 (patch)
tree87607ae35c7f2b11da55fd8b69c3e800d5cfefbe
parent791bb2bab91a022d1b5265b40faa997ad9938ad7 (diff)
downloadsvg.js-a8373f5ee8902089d5ab3a915eb5a31b568d3728.tar.gz
svg.js-a8373f5ee8902089d5ab3a915eb5a31b568d3728.zip
Refactored the getOrigin helper to help fix the relative affine animations
This commit refactors the getOrigin helper, in order to send the origin to the correct space. The origin should be expressed in the space of the last animation. Changes ======= - Refactored the getOrigin helper - Added a simple example to the dirty file to test multiple transformations
-rw-r--r--dirty.html55
-rw-r--r--src/helpers.js7
-rw-r--r--src/runner.js14
3 files changed, 38 insertions, 38 deletions
diff --git a/dirty.html b/dirty.html
index f7542e6..68a9aa8 100644
--- a/dirty.html
+++ b/dirty.html
@@ -305,40 +305,31 @@ let wait = 1000
let rAnim = r.clone().attr('fill', '#f00').animate(wait).attr('fill', '#0f0')
let rDecl = r.clone().attr('fill', 'blue').animate(new SVG.Spring(wait, 15))
-// // Move once
-// setTimeout(() => {
-// let trans = {tx: 500, ty: 300}
-// r.transform(trans, true)
-// // rAnim.animate(wait, 0, 'start').transform(trans, true)
-// rDecl.transform(trans, true)
-// }, wait)
-
-// Move again
-setTimeout(() => {
- let transform = {
- origin: 'top-left',
- translate: [530, 250],
- rotate: 300,
- scale: 2,
- shear: 1,
+let runTransformation = (transform) => {
+ return () => {
+ let relative = false
+ let affine = false
+ r.transform(transform, relative)
+ rAnim.animate(wait).transform(transform, relative, affine)
+ rDecl.transform(transform, relative, affine)
}
- let relative = true
- let affine = false
- r.transform(transform, relative)
- rAnim.animate(wait).transform(transform, relative, affine)
- rDecl.transform(transform, relative, affine)
-}, 0.1 * wait )
-
-
-// declaritive relative (affine/nonaffine)
-// declaritive absolute non affine
-// normal non affine relative
-
-// D N
-// R
-// A
-
+}
+setTimeout(runTransformation({
+ origin: 'top-left',
+ translate: [530, 250],
+ rotate: 300,
+ scale: 2,
+ shear: 1,
+}), 0.1 * wait )
+
+// setTimeout(runTransformation({
+// origin: 'top-left',
+// translate: [530, 250],
+// rotate: 800,
+// scale: 2,
+// shear: 1,
+// }), wait )
diff --git a/src/helpers.js b/src/helpers.js
index 44bce72..7860048 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -249,7 +249,7 @@ function formatTransforms (o) {
}
-function getOrigin (o, element, relative) {
+function getOrigin (o, element, inSpace) {
// Allow origin or around as the names
let origin = o.around == null ? o.origin : o.around
let ox, oy
@@ -279,9 +279,8 @@ function getOrigin (o, element, relative) {
}
// Transform the origin into the current reference frame
- if ( relative ) {
- let matrix = new SVG.Matrix(element)
- let originRelative = new SVG.Point( ox, oy ).transform(matrix)
+ if ( inSpace ) {
+ let originRelative = new SVG.Point( ox, oy ).transform(inSpace)
ox = originRelative.x
oy = originRelative.y
}
diff --git a/src/runner.js b/src/runner.js
index 881efd4..298db36 100644
--- a/src/runner.js
+++ b/src/runner.js
@@ -653,9 +653,19 @@ SVG.extend(SVG.Runner, {
// make sure element and origin is defined
element = element || this.element()
- origin = origin || getOrigin(transforms, element, relative)
-this.element().parent().ellipse(50, 50).center(...origin)
+ // TODO: Give me all matricies concatenated, up until this matrix,
+ // for example, if I have M = E D C B A
+ // If I'm about to run D, I want transform space to be
+ // C * B * A
+ // Where C B and A are the current morpher targets
+ // The solution I've added here won't work if we interrupt an animation
+ // mid-animation (try turning on the second animation in dirty)
+
+ let transformSpace = relative
+ ? new SVG.Matrix(element)
+ : undefined
+ origin = origin || getOrigin(transforms, element, transformSpace)
// add the runner to the element so it can merge transformations
element.addRunner(this)