-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fox #13 - adopt an easing interface.
Rather than expose bare easing functions, this module now exports instances of an easing interface: object.ease(t). For example: var te = d3.easeCubicIn(t); // BEFORE var te = d3.easeCubicIn.ease(t); // AFTER The primary motivation of this change is to allow D3 transitions to differ- entiate between an easing type and a function that returns an easing type, as when the easing type should be determined separately for each selected element. Also, it means you can use a class to implement a configurable easing type, if you want, rather than a closure. This commit also changes how optional parameters are specified for configurable easing types. Rather than binding optional arguments to the easing function, create a new instance using method chaining. For example, to create a cubic easing instance using generic polynomial easing: var cubicIn = d3.easeBind(d3.easePolyIn, 3); // BEFORE var cubicIn = d3.easePolyIn.exponent(3); // AFTER Equivalently, to call the function directly: var te = d3.easePolyIn(t, 3); // BEFORE var te = d3.easePolyIn.exponent(3).ease(t); // AFTER By giving the parameters explicit names, usage is now self-documenting! Also, we can eliminate d3.easeBind and easing functions are slightly faster.
- Loading branch information
Showing
26 changed files
with
763 additions
and
772 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
export function backIn(t, s) { | ||
s = s == null ? 1.70158 : +s; | ||
return t * t * ((s + 1) * t - s); | ||
} | ||
var overshoot = 1.70158; | ||
|
||
export function backOut(t, s) { | ||
s = s == null ? 1.70158 : +s; | ||
return --t * t * ((s + 1) * t + s) + 1; | ||
} | ||
export var backIn = (function backIn(s) { | ||
return s = +s, { | ||
overshoot: backIn, | ||
ease: function(t) { | ||
return t * t * ((s + 1) * t - s); | ||
} | ||
}; | ||
})(overshoot); | ||
|
||
export function backInOut(t, s) { | ||
s = s == null ? 1.70158 : +s; | ||
return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2; | ||
} | ||
export var backOut = (function backOut(s) { | ||
return s = +s, { | ||
overshoot: backOut, | ||
ease: function(t) { | ||
return --t * t * ((s + 1) * t + s) + 1; | ||
} | ||
}; | ||
})(overshoot); | ||
|
||
export var backInOut = (function backInOut(s) { | ||
return s = +s, { | ||
overshoot: backInOut, | ||
ease: function(t) { | ||
return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2; | ||
} | ||
}; | ||
})(overshoot); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
export function circleIn(t) { | ||
return 1 - Math.sqrt(1 - t * t); | ||
} | ||
export var circleIn = { | ||
ease: function(t) { | ||
return 1 - Math.sqrt(1 - t * t); | ||
} | ||
}; | ||
|
||
export function circleOut(t) { | ||
return Math.sqrt(1 - --t * t); | ||
} | ||
export var circleOut = { | ||
ease: function(t) { | ||
return Math.sqrt(1 - --t * t); | ||
} | ||
}; | ||
|
||
export function circleInOut(t) { | ||
return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2; | ||
} | ||
export var circleInOut = { | ||
ease: function(t) { | ||
return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
export function cubicIn(t) { | ||
return t * t * t; | ||
} | ||
export var cubicIn = { | ||
ease: function(t) { | ||
return t * t * t; | ||
} | ||
}; | ||
|
||
export function cubicOut(t) { | ||
return --t * t * t + 1; | ||
} | ||
export var cubicOut = { | ||
ease: function(t) { | ||
return --t * t * t + 1; | ||
} | ||
}; | ||
|
||
export function cubicInOut(t) { | ||
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2; | ||
} | ||
export var cubicInOut = { | ||
ease: function(t) { | ||
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
var tau = 2 * Math.PI; | ||
var tau = 2 * Math.PI, | ||
amplitude = 1, | ||
period = 0.3; | ||
|
||
export function elasticIn(t, a, p) { | ||
a = a == null ? 1 : Math.max(1, a); | ||
p = (p == null ? 0.3 : p) / tau; | ||
return a * Math.pow(2, 10 * --t) * Math.sin((p * Math.asin(1 / a) - t) / p); | ||
} | ||
export var elasticIn = (function elasticIn(a, p) { | ||
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau); | ||
return { | ||
amplitude: function(a) { return elasticIn(a, p * tau); }, | ||
period: function(p) { return elasticIn(a, p); }, | ||
ease: function(t) { | ||
return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p); | ||
} | ||
}; | ||
})(amplitude, period); | ||
|
||
export function elasticOut(t, a, p) { | ||
a = a == null ? 1 : Math.max(1, a); | ||
p = (p == null ? 0.3 : p) / tau; | ||
return 1 - a * Math.pow(2, -10 * t) * Math.sin((+t + p * Math.asin(1 / a)) / p); | ||
} | ||
export var elasticOut = (function elasticOut(a, p) { | ||
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau); | ||
return { | ||
amplitude: function(a) { return elasticOut(a, p * tau); }, | ||
period: function(p) { return elasticOut(a, p); }, | ||
ease: function(t) { | ||
return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p); | ||
} | ||
}; | ||
})(amplitude, period); | ||
|
||
export function elasticInOut(t, a, p) { | ||
a = a == null ? 1 : Math.max(1, a); | ||
p = (p == null ? 0.3 : p) / tau; | ||
var s = p * Math.asin(1 / a); | ||
return ((t = t * 2 - 1) < 0 | ||
? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p) | ||
: 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2; | ||
} | ||
export var elasticInOut = (function elasticInOut(a, p) { | ||
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau); | ||
return { | ||
amplitude: function(a) { return elasticInOut(a, p * tau); }, | ||
period: function(p) { return elasticInOut(a, p); }, | ||
ease: function(t) { | ||
return ((t = t * 2 - 1) < 0 | ||
? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p) | ||
: 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2; | ||
} | ||
}; | ||
})(amplitude, period); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
export function expIn(t) { | ||
return Math.pow(2, 10 * t - 10); | ||
} | ||
export var expIn = { | ||
ease: function(t) { | ||
return Math.pow(2, 10 * t - 10); | ||
} | ||
}; | ||
|
||
export function expOut(t) { | ||
return 1 - Math.pow(2, -10 * t); | ||
} | ||
export var expOut = { | ||
ease: function(t) { | ||
return 1 - Math.pow(2, -10 * t); | ||
} | ||
}; | ||
|
||
export function expInOut(t) { | ||
return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2; | ||
} | ||
export var expInOut = { | ||
ease: function(t) { | ||
return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
export function polyIn(t, e) { | ||
if (e == null) e = 3; | ||
return Math.pow(t, e); | ||
} | ||
var exponent = 3; | ||
|
||
export function polyOut(t, e) { | ||
if (e == null) e = 3; | ||
return 1 - Math.pow(1 - t, e); | ||
} | ||
export var polyIn = (function polyIn(e) { | ||
return e = +e, { | ||
exponent: polyIn, | ||
ease: function(t) { | ||
return Math.pow(t, e); | ||
} | ||
}; | ||
})(exponent); | ||
|
||
export function polyInOut(t, e) { | ||
if (e == null) e = 3; | ||
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2; | ||
} | ||
export var polyOut = (function polyOut(e) { | ||
return e = +e, { | ||
exponent: polyOut, | ||
ease: function(t) { | ||
return 1 - Math.pow(1 - t, e); | ||
} | ||
}; | ||
})(exponent); | ||
|
||
export var polyInOut = (function polyInOut(e) { | ||
return e = +e, { | ||
exponent: polyInOut, | ||
ease: function(t) { | ||
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2; | ||
} | ||
}; | ||
})(exponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
export function quadIn(t) { | ||
return t * t; | ||
} | ||
export var quadIn = { | ||
ease: function(t) { | ||
return t * t; | ||
} | ||
}; | ||
|
||
export function quadOut(t) { | ||
return t * (2 - t); | ||
} | ||
export var quadOut = { | ||
ease: function(t) { | ||
return t * (2 - t); | ||
} | ||
}; | ||
|
||
export function quadInOut(t) { | ||
return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2; | ||
} | ||
export var quadInOut = { | ||
ease: function(t) { | ||
return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
var pi = Math.PI, | ||
halfPi = pi / 2; | ||
|
||
export function sinIn(t) { | ||
return 1 - Math.cos(t * halfPi); | ||
} | ||
export var sinIn = { | ||
ease: function(t) { | ||
return 1 - Math.cos(t * halfPi); | ||
} | ||
}; | ||
|
||
export function sinOut(t) { | ||
return Math.sin(t * halfPi); | ||
} | ||
export var sinOut = { | ||
ease: function(t) { | ||
return Math.sin(t * halfPi); | ||
} | ||
}; | ||
|
||
export function sinInOut(t) { | ||
return (1 - Math.cos(pi * t)) / 2; | ||
} | ||
export var sinInOut = { | ||
ease: function(t) { | ||
return (1 - Math.cos(pi * t)) / 2; | ||
} | ||
}; |
Oops, something went wrong.