How do I get the return value of d3.ease?
I am using d3 Version 3 and I am trying to use d3 function for animation. According to the function definition, it has a return value
function ease(type: 'cubic-in'): (t: number) => number;
I am expecting a number as a return value to use in my calculations. But now how can I pass the return value of the ease function to a number. Is there any other way to achieve this?
Thank.
source to share
d3.ease
already returns a number.
You just need to pass the value you want d3.ease
:
d3.ease(type)(value);
Here is a demo with "cubic-in"
, as in your question:
function ease(value) {
return d3.ease("cubic-in")(value);
}
console.log("ease for 0.1: " + ease(4));
console.log("ease for 0.5: " + ease(0.5));
console.log("ease for 0.8: " + ease(0.8));
console.log("ease for 0.95: " + ease(0.95));
<script src="https://d3js.org/d3.v3.min.js"></script>
Remember that the passed value and the return value are between 0
and 1
. According to the API :
The attenuation function takes the currently parameterized time value
t
in the domain[0,1]
and compares it to another value in the same range.
source to share