d3#interpolate TypeScript Examples
The following examples show how to use
d3#interpolate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AniCreator.ts From anichart.js with MIT License | 6 votes |
getComponent(sec: number): Component | null {
// [0, 3, 6]
let rIdx = bisectLeft(this.keyTimes, sec);
if (rIdx >= this.keyFrames.length) {
rIdx = this.keyFrames.length - 1;
}
const lIdx = rIdx - 1;
if (lIdx < 0) {
return null;
}
const eIdx = lIdx >= this.eases.length ? this.eases.length - 1 : lIdx;
const scale = scaleLinear(
[this.keyTimes[lIdx], this.keyTimes[rIdx]],
[this.keyFrames[lIdx], this.keyFrames[rIdx]]
)
.interpolate(easeInterpolate(this.eases[eIdx]))
.clamp(true);
return scale(sec);
}
Example #2
Source File: AniCreator.ts From anichart.js with MIT License | 6 votes |
export function easeInterpolate<T extends Component | number>(
e: (i: number) => number
) {
return (a: T, b: T) => {
const i = interpolate(a, b as any);
return (t: number): T => {
return i(e(t));
};
};
}
Example #3
Source File: AniCreator.ts From anichart.js with MIT License | 6 votes |
export function createAni<T extends Component>(
keyFrames: T[],
keyTimes: number[] = [0, 1],
ease: (n: number) => number = easeLinear
): Ani {
const scale = scaleLinear(keyTimes, keyFrames)
.interpolate(easeInterpolate(ease))
.clamp(true);
const ani = new Ani();
ani.getComponent = (i) => {
return scale(i);
};
return ani;
}