Created
February 7, 2024 17:40
-
-
Save valterbarros/61b0ebd1704fd1adc720778e68bebc1d to your computer and use it in GitHub Desktop.
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
const sortSignaturesByDiagonalDistance = (a, b) => { | |
// await nextTick(); | |
console.log('sort'); | |
if (!a.signatureRef) return 0; | |
// Get the absolute position of the child relative to the parent | |
const { top: distanceFromTopA, left: distanceFromLeftA } = a.signatureRef.getBoundingClientRect(); | |
const { top: distanceFromTopB, left: distanceFromLeftB } = b.signatureRef.getBoundingClientRect(); | |
const aDistance = Math.sqrt(distanceFromTopA ** 2 + distanceFromLeftA ** 2); | |
const bDistance = Math.sqrt(distanceFromTopB ** 2 + distanceFromLeftB ** 2); | |
return aDistance - bDistance; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment