Skip to content

Commit

Permalink
Quiz exercises: Fix an issue with drag and drop positioning (#8265)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaslehnertum authored and beyzaaltuntas committed Apr 2, 2024
1 parent 3b543b8 commit 1df595b
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,19 @@ async function generateDragAndDropItemForRelationship(
*
* @return {DropLocation} A Drag and Drop Quiz Exercise `DropLocation`.
*/
function computeDropLocation(elementLocation: { x: number; y: number; width: number; height: number }, totalSize: { width: number; height: number }): DropLocation {
function computeDropLocation(
elementLocation: { x: number; y: number; width: number; height: number },
totalSize: { x?: number; y?: number; width: number; height: number },
): DropLocation {
console.log('elementLocation', elementLocation);
console.log('totalSize', totalSize);
const dropLocation = new DropLocation();
// on quiz exercise generation, svg exports adds 15px padding
elementLocation.x += 15;
elementLocation.y += 15;
// round to second decimal
dropLocation.posX = round((elementLocation.x / totalSize.width) * MAX_SIZE_UNIT, 2);
dropLocation.posY = round((elementLocation.y / totalSize.height) * MAX_SIZE_UNIT, 2);
dropLocation.posX = round(((elementLocation.x - (totalSize.x ?? 0)) / totalSize.width) * MAX_SIZE_UNIT, 2);
dropLocation.posY = round(((elementLocation.y - (totalSize.y ?? 0)) / totalSize.height) * MAX_SIZE_UNIT, 2);
dropLocation.width = round((elementLocation.width / totalSize.width) * MAX_SIZE_UNIT, 2);
dropLocation.height = round((elementLocation.height / totalSize.height) * MAX_SIZE_UNIT, 2);
return dropLocation;
Expand Down

0 comments on commit 1df595b

Please sign in to comment.