-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [#187401278] Feature: Components animate into position and size * [#187401278] Feature: Components animate into position and size * chore: code review: use CSS transition rather than JS animation * * Fix remaining issues that occur when a new graph is created * chore: fix map cypress tests
- Loading branch information
Showing
14 changed files
with
111 additions
and
70 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export const kDefaultAnimationDuration = 500 | ||
export interface ComponentRect { | ||
x: number | ||
y: number | ||
width: number | ||
height: number | ||
[key: string]: number | ||
} | ||
|
||
export const interpolateEaseInOut = <T extends Record<string, number>>(duration: number, from: T, to: T) => { | ||
return (time: number) => { | ||
const t = Math.min(1, time / duration) | ||
const ease = 0.5 - 0.5 * Math.cos(Math.PI * t) | ||
const result: Partial<T> = {} | ||
for (const key in from) { | ||
result[key] = (from[key] + (to[key] - from[key]) * ease) as T[typeof key] | ||
} | ||
return result as T | ||
} | ||
} | ||
|
||
// This function takes a duration, a <from> object, a <to> object and a callback function. It calls | ||
// interpolateEaseInOut repeatedly and calls the callback with the result each time through the loop. | ||
// The loop runs until the elapsed time is greater than the duration. | ||
export const animateEaseInOut = <T extends Record<string, number>>(duration: number, from: T, to: T, | ||
callback: (result: T) => void) => { | ||
const interpolate = interpolateEaseInOut(duration, from, to) | ||
const startTime = Date.now() | ||
const step = () => { | ||
const time = Date.now() - startTime | ||
if (time < duration) { | ||
callback(interpolate(time)) | ||
requestAnimationFrame(step) | ||
} else { | ||
callback(to) | ||
} | ||
} | ||
requestAnimationFrame(step) | ||
} |