From 2f3a0af268e042ada54e713207e8d5a529436123 Mon Sep 17 00:00:00 2001 From: Matthias Lehner Date: Wed, 27 Mar 2024 22:38:26 +0100 Subject: [PATCH 1/3] Hotfix quiz exercises --- .../exercise-generation/quiz-exercise-generator.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts b/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts index e1f3b38dd281..d2c499ed2155 100644 --- a/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts +++ b/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts @@ -216,14 +216,17 @@ 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 { 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) / totalSize.width) * MAX_SIZE_UNIT, 2); + dropLocation.posY = round(((elementLocation.y - totalSize.y) / 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; From c837318e872213ebda22bda72a08506adafbe447 Mon Sep 17 00:00:00 2001 From: Matthias Lehner Date: Wed, 27 Mar 2024 22:49:51 +0100 Subject: [PATCH 2/3] Ensure x and y are optional on the total size parameter --- .../exercise-generation/quiz-exercise-generator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts b/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts index d2c499ed2155..5f8bd506cc7f 100644 --- a/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts +++ b/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts @@ -218,15 +218,15 @@ async function generateDragAndDropItemForRelationship( */ function computeDropLocation( elementLocation: { x: number; y: number; width: number; height: number }, - totalSize: { x: number; y: number; width: number; height: number }, + totalSize: { x?: number; y?: number; width: number; height: number }, ): DropLocation { 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.x) / totalSize.width) * MAX_SIZE_UNIT, 2); - dropLocation.posY = round(((elementLocation.y - totalSize.y) / totalSize.height) * MAX_SIZE_UNIT, 2); + dropLocation.posX = round((((elementLocation.x ?? 0) - (totalSize.x ?? 0)) / totalSize.width) * MAX_SIZE_UNIT, 2); + dropLocation.posY = round((((elementLocation.y ?? 0) - (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; From a85a1f52d8bc7ac7baeb2baec373863056f2e27f Mon Sep 17 00:00:00 2001 From: Matthias Lehner Date: Thu, 28 Mar 2024 12:37:16 +0100 Subject: [PATCH 3/3] Remove redundant default value --- .../exercise-generation/quiz-exercise-generator.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts b/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts index 5f8bd506cc7f..3f6fe982436f 100644 --- a/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts +++ b/src/main/webapp/app/exercises/quiz/manage/apollon-diagrams/exercise-generation/quiz-exercise-generator.ts @@ -220,13 +220,15 @@ 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 ?? 0) - (totalSize.x ?? 0)) / totalSize.width) * MAX_SIZE_UNIT, 2); - dropLocation.posY = round((((elementLocation.y ?? 0) - (totalSize.y ?? 0)) / 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;