Skip to content

Instantly share code, notes, and snippets.

@valterbarros
Created February 7, 2024 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valterbarros/61b0ebd1704fd1adc720778e68bebc1d to your computer and use it in GitHub Desktop.
Save valterbarros/61b0ebd1704fd1adc720778e68bebc1d to your computer and use it in GitHub Desktop.
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