-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1328 lines (1116 loc) · 53.2 KB
/
script.js
File metadata and controls
1328 lines (1116 loc) · 53.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
document.addEventListener('DOMContentLoaded', function() {
const skinfoldImage = document.getElementById('skinfoldImage');
const svgDotsContainer = document.getElementById('skinfoldDots');
const infoDisplay = document.getElementById('infoDisplay');
const infoTitle = document.getElementById('infoTitle');
const infoContent = document.getElementById('infoContent');
const closeButton = document.getElementById('closeButton');
const interactiveArea = document.querySelector('.interactive-area');
const detailsPanel = document.querySelector('.details-panel');
const taskSelectContainer = document.getElementById('taskSelectContainer');
const mainTitle = document.getElementById('mainTitle');
const taskDescription = document.getElementById('taskDescription');
let selectedDot = null;
let currentTask = 'basic';
// Quiz mode variables
let isQuizMode = false;
let currentQuizType = 'identification'; // 'identification' or 'multipleChoice'
let currentQuestions = [];
let currentQuestionIndex = 0;
let quizScore = { correct: 0, total: 0 };
let currentCorrectAnswer = null;
const videoPlayerContainer = document.getElementById('videoPlayerContainer');
const youtubePlayer = document.getElementById('youtubePlayer');
const closeVideoButton = document.getElementById('closeVideoButton');
const restartVideoButton = document.getElementById('restartVideoButton');
const videoId = "qZtZWQXZ9sI";
let currentVideoStartTime = 0;
let currentVideoEndTime = 0;
// Add coordinate finder functionality
let coordinateFindingMode = false;
const imageContainer = document.querySelector('.image-container');
// Developer mode variables
let developerMode = false;
let currentSiteIndex = 0;
let currentTaskSites = [];
const developerPanel = document.getElementById('developerPanel');
const currentSiteSpan = document.getElementById('currentSite');
const clickPromptSpan = document.getElementById('clickPrompt');
const prevSiteButton = document.getElementById('prevSite');
const nextSiteButton = document.getElementById('nextSite');
const outputCoordsButton = document.getElementById('outputCoords');
const hideOverlaysCheckbox = document.getElementById('hideOverlays');
const lockYAxisCheckbox = document.getElementById('lockYAxis');
const lockedYValueSpan = document.getElementById('lockedYValue');
const definitionText = document.getElementById('definitionText');
let alignmentCoordinates = {};
let lastYCoordinate = null;
let previewLine = null;
let isWaitingForEndPoint = false;
let startPoint = null;
// Tooltip functionality variables
const landmarkTooltip = document.getElementById('landmarkTooltip');
// Task descriptions for each type
const taskDescriptions = {
basic: "Learn the fundamental anthropometric measurements used in body composition assessment.",
landmarks: "Click on a marked point on the image to learn how to locate the anatomical landmark.",
skinfolds: "Click on a marked point on the image to learn how to measure the skinfold at that site.",
girths: "Click on a marked point on the image to learn how to measure body girths.",
lengths: "Click on a marked point on the image to learn how to measure body lengths.",
breadths: "Click on a marked point on the image to learn how to measure body breadths."
};
// Variable to store loaded anatomical data
let taskData = null;
// Quiz UI elements
const quizControls = document.getElementById('quizControls');
const learnModeBtn = document.getElementById('learnModeBtn');
const quizModeBtn = document.getElementById('quizModeBtn');
const quizTypeSelector = document.getElementById('quizTypeSelector');
const identificationQuizBtn = document.getElementById('identificationQuizBtn');
const multipleChoiceQuizBtn = document.getElementById('multipleChoiceQuizBtn');
const quizProgress = document.getElementById('quizProgress');
const quizQuestion = document.getElementById('quizQuestion');
const questionText = document.getElementById('questionText');
const multipleChoiceOptions = document.getElementById('multipleChoiceOptions');
const quizFeedback = document.getElementById('quizFeedback');
const nextQuestionBtn = document.getElementById('nextQuestionBtn');
const currentQuestionNum = document.getElementById('currentQuestionNum');
const totalQuestions = document.getElementById('totalQuestions');
const correctAnswers = document.getElementById('correctAnswers');
const totalAnswered = document.getElementById('totalAnswered');
// Function to load anatomical data from JSON file
async function loadAnatomicalData() {
try {
const response = await fetch('anatomical-data.json');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
taskData = await response.json();
console.log('Anatomical data loaded successfully');
// Initialize with the new default task after data is loaded
taskDescription.textContent = taskDescriptions[currentTask];
loadTaskData(currentTask);
} catch (error) {
console.error('Error loading anatomical data:', error);
// You could show a user-friendly error message here
alert('Failed to load measurement data. Please refresh the page and try again.');
}
}
// Add coordinate finder and developer mode event listeners
document.addEventListener('keydown', function(e) {
if (e.altKey && e.key.toLowerCase() === 'c') {
e.preventDefault();
coordinateFindingMode = !coordinateFindingMode;
document.body.style.cursor = coordinateFindingMode ? 'crosshair' : 'default';
// Hide/show measurement elements when coordinate finding mode is toggled
const allMeasurementElements = svgDotsContainer.querySelectorAll('.measurement-element, .measurement-dot');
allMeasurementElements.forEach(element => {
if (coordinateFindingMode) {
element.style.display = 'none';
} else {
element.style.display = '';
}
});
// Add visual feedback to indicate coordinate finding mode is active
if (coordinateFindingMode) {
// Add a subtle overlay or indicator
document.body.classList.add('coordinate-finding-active');
console.log('Coordinate finding mode: ON - All measurement elements hidden');
} else {
document.body.classList.remove('coordinate-finding-active');
console.log('Coordinate finding mode: OFF - Measurement elements restored');
}
}
// Toggle developer mode with Alt+D
if (e.altKey && e.key.toLowerCase() === 'd') {
e.preventDefault();
toggleDeveloperMode();
}
});
imageContainer.addEventListener('click', function(e) {
if (!coordinateFindingMode && !developerMode) return;
const rect = skinfoldImage.getBoundingClientRect();
const x = ((e.clientX - rect.left) / rect.width * 100).toFixed(1);
const y = ((e.clientY - rect.top) / rect.height * 100).toFixed(1);
if (coordinateFindingMode) {
// Original coordinate finding functionality
const tempDot = document.createElementNS("http://www.w3.org/2000/svg", "circle");
tempDot.setAttribute("cx", x + "%");
tempDot.setAttribute("cy", y + "%");
tempDot.setAttribute("r", "1.3%");
tempDot.setAttribute("fill", "yellow");
tempDot.setAttribute("stroke", "black");
svgDotsContainer.appendChild(tempDot);
console.log(`Coordinates: x: "${x}%", y: "${y}%"`);
setTimeout(() => {
svgDotsContainer.removeChild(tempDot);
}, 2000);
} else if (developerMode && currentTaskSites.length > 0) {
// Developer mode alignment functionality
const currentSite = currentTaskSites[currentSiteIndex];
if (!alignmentCoordinates[currentTask]) {
alignmentCoordinates[currentTask] = {};
}
// Apply Y-axis lock if enabled - use first click's Y if no previous Y is set
let finalY = y;
if (lockYAxisCheckbox.checked) {
if (lastYCoordinate !== null) {
finalY = lastYCoordinate;
} else {
// First click of the site - this will become the locked Y value
lastYCoordinate = y;
updateLockedYDisplay();
}
}
// Store coordinates for current site
const siteData = taskData[currentTask][currentSite];
if (siteData.type === "line") {
// For lines, determine if this is start or end point based on clicks
if (!alignmentCoordinates[currentTask][currentSite]) {
alignmentCoordinates[currentTask][currentSite] = { startX: x + "%", startY: finalY + "%" };
lastYCoordinate = finalY;
updateLockedYDisplay();
clickPromptSpan.textContent = `${currentSite} - Click END point`;
// Set up preview line
startPoint = { x: parseFloat(x), y: parseFloat(finalY) };
isWaitingForEndPoint = true;
createPreviewLine();
} else {
alignmentCoordinates[currentTask][currentSite].endX = x + "%";
alignmentCoordinates[currentTask][currentSite].endY = finalY + "%";
lastYCoordinate = finalY;
updateLockedYDisplay();
// Clean up preview line
removePreviewLine();
isWaitingForEndPoint = false;
startPoint = null;
nextSite();
}
} else if (siteData.type === "ellipse") {
// For ellipses, get center point first, then radius points
if (!alignmentCoordinates[currentTask][currentSite]) {
alignmentCoordinates[currentTask][currentSite] = { centerX: x + "%", centerY: finalY + "%" };
lastYCoordinate = finalY;
updateLockedYDisplay();
clickPromptSpan.textContent = `${currentSite} - Click edge for radius`;
} else {
const centerX = parseFloat(alignmentCoordinates[currentTask][currentSite].centerX);
const centerY = parseFloat(alignmentCoordinates[currentTask][currentSite].centerY);
const radiusX = Math.abs(parseFloat(x) - centerX).toFixed(1);
const radiusY = Math.abs(parseFloat(y) - centerY).toFixed(1);
alignmentCoordinates[currentTask][currentSite].radiusX = radiusX + "%";
alignmentCoordinates[currentTask][currentSite].radiusY = radiusY + "%";
nextSite();
}
} else {
// Regular dots
alignmentCoordinates[currentTask][currentSite] = { x: x + "%", y: finalY + "%" };
lastYCoordinate = finalY;
updateLockedYDisplay();
nextSite();
}
// Show temporary marker (use finalY to show where the point was actually placed)
const tempDot = document.createElementNS("http://www.w3.org/2000/svg", "circle");
tempDot.setAttribute("cx", x + "%");
tempDot.setAttribute("cy", finalY + "%");
tempDot.setAttribute("r", "1.0%");
tempDot.setAttribute("fill", lockYAxisCheckbox.checked ? "#00BFFF" : "#FF4444");
tempDot.setAttribute("stroke", "#000000");
tempDot.setAttribute("stroke-width", "2");
svgDotsContainer.appendChild(tempDot);
setTimeout(() => {
if (svgDotsContainer.contains(tempDot)) {
svgDotsContainer.removeChild(tempDot);
}
}, 1000);
}
});
// Mouse move event for preview line
imageContainer.addEventListener('mousemove', function(e) {
if (!developerMode || !isWaitingForEndPoint || !startPoint) return;
const rect = skinfoldImage.getBoundingClientRect();
const x = ((e.clientX - rect.left) / rect.width * 100).toFixed(1);
let y = ((e.clientY - rect.top) / rect.height * 100).toFixed(1);
// Apply Y-axis lock if enabled
if (lockYAxisCheckbox.checked && lastYCoordinate !== null) {
y = lastYCoordinate;
}
updatePreviewLine(parseFloat(x), parseFloat(y));
});
// Function to handle collapsible sections
function setupCollapsibleSections() {
document.querySelectorAll('.collapsible-header').forEach(header => {
header.classList.add('collapsed');
});
document.querySelectorAll('.collapsible-content').forEach(content => {
content.classList.add('collapsed');
});
document.querySelectorAll('.collapsible-header').forEach(header => {
header.addEventListener('click', function() {
this.classList.toggle('collapsed');
const content = this.nextElementSibling;
if (content && content.classList.contains('collapsible-content')) {
content.classList.toggle('collapsed');
}
});
});
}
function createMeasurementElement(siteKey, siteData, taskType) {
const element = document.createElementNS("http://www.w3.org/2000/svg", "g");
element.setAttribute("data-site", siteKey);
element.setAttribute("data-task", taskType);
element.classList.add("measurement-element", `${taskType}-element`);
if (siteData.type === "line") {
// Create line with endpoints for lengths and breadths
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
line.setAttribute("x1", siteData.startX);
line.setAttribute("y1", siteData.startY);
line.setAttribute("x2", siteData.endX);
line.setAttribute("y2", siteData.endY);
line.classList.add("measurement-line");
element.appendChild(line);
// Create endpoint circles
const startCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
startCircle.setAttribute("cx", siteData.startX);
startCircle.setAttribute("cy", siteData.startY);
startCircle.setAttribute("r", "1.0%");
startCircle.classList.add("measurement-endpoint");
element.appendChild(startCircle);
const endCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
endCircle.setAttribute("cx", siteData.endX);
endCircle.setAttribute("cy", siteData.endY);
endCircle.setAttribute("r", "1.0%");
endCircle.classList.add("measurement-endpoint");
element.appendChild(endCircle);
} else if (siteData.type === "ellipse") {
// Create dashed arc (half-ellipse) for girths - only show front portion
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
// Parse the percentage values
const centerX = parseFloat(siteData.centerX);
const centerY = parseFloat(siteData.centerY);
const radiusX = parseFloat(siteData.radiusX);
const radiusY = parseFloat(siteData.radiusY);
// Calculate arc endpoints
const startX = centerX - radiusX;
const startY = centerY;
const endX = centerX + radiusX;
const endY = centerY;
// Create an arc that curves downward (front of body)
// Using a more pronounced curve by adjusting the control point
const pathData = `M ${startX} ${startY} Q ${centerX} ${centerY + radiusY} ${endX} ${endY}`;
path.setAttribute("d", pathData);
path.classList.add("measurement-arc");
// Apply rotation if specified
if (siteData.rotationAngle !== undefined) {
path.setAttribute("transform", `rotate(${siteData.rotationAngle} ${centerX} ${centerY})`);
}
element.appendChild(path);
} else {
// Fallback to dot for landmarks and skinfolds
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circle.setAttribute("cx", siteData.x);
circle.setAttribute("cy", siteData.y);
circle.setAttribute("r", "1.3%");
circle.setAttribute("data-site", siteKey);
circle.setAttribute("data-task", taskType);
circle.classList.add("measurement-dot", `${taskType}-dot`);
element.appendChild(circle);
}
svgDotsContainer.appendChild(element);
// Add tooltip functionality to all measurement elements
addTooltipToElement(element, siteKey, siteData, taskType);
return element;
}
function clearAllElements() {
const elements = svgDotsContainer.querySelectorAll('.measurement-element, .measurement-dot');
elements.forEach(element => element.remove());
// Remove basic measurements container if it exists
const basicContainer = document.getElementById('basicMeasurementsList');
if (basicContainer) {
basicContainer.remove();
}
// Gap spacing
interactiveArea.style.gap = '1.5rem';
// Show silhouette image and SVG container (will be hidden again if switching to basic tab)
skinfoldImage.style.display = 'block';
svgDotsContainer.style.display = 'block';
selectedDot = null;
}
function loadTaskData(taskType) {
clearAllElements();
hideInfoPanel();
// Handle basic measurements differently - no silhouette needed
if (taskType === 'basic') {
handleBasicMeasurements();
return;
}
if (taskType === 'breadths') {
skinfoldImage.src = 'Blank-Sillouette-With-Side.png';
} else {
skinfoldImage.src = 'Blank-Sillouette.png';
}
if (!taskData) return;
const data = taskData[taskType];
if (!data) return;
// Create elements for the current task
for (const siteKey in data) {
if (data.hasOwnProperty(siteKey)) {
const site = data[siteKey];
let element;
if (taskType === 'lengths' || taskType === 'breadths' || taskType === 'girths') {
element = createMeasurementElement(siteKey, site, taskType);
} else {
// For skinfolds and landmarks, use the original dot creation
if (site.x && site.y) {
element = createDot(siteKey, site, taskType);
}
}
if (element) {
element.addEventListener('click', function(event) {
// If in quiz mode, don't show the learning panel
if (isQuizMode) {
return; // Quiz click handler will handle this
}
if (selectedDot) {
selectedDot.classList.remove('element-selected');
}
this.classList.add('element-selected');
selectedDot = this;
const clickedSiteKey = this.dataset.site;
const currentTaskData = taskData[currentTask];
const siteData = currentTaskData[clickedSiteKey];
if (siteData) {
showInfoPanel(siteData);
}
});
}
}
}
}
function handleBasicMeasurements() {
// Hide the silhouette image and show a list of basic measurements instead
if (skinfoldImage) {
skinfoldImage.style.display = 'none';
}
// Hide SVG container to prevent interference
if (svgDotsContainer) {
svgDotsContainer.style.display = 'none';
}
// Keep the same proportions as landmarks tab (45% width)
// Don't modify the imageContainer styling - keep it as is
// Add extra spacing for basic measurements only
interactiveArea.style.gap = '4rem';
// Create a list container for basic measurements
let basicContainer = document.getElementById('basicMeasurementsList');
if (!basicContainer) {
basicContainer = document.createElement('div');
basicContainer.id = 'basicMeasurementsList';
basicContainer.style.cssText = `
padding: 20px;
background: #f9f9f9;
border-radius: 8px;
margin: 0;
margin-right: 20px;
width: 100%;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
height: fit-content;
`;
imageContainer.appendChild(basicContainer);
}
basicContainer.innerHTML = '';
if (!taskData || !taskData.basic) {
// Show a loading message
basicContainer.innerHTML = '<p style="text-align: center; color: #666;">Loading basic measurements...</p>';
return;
}
const basicData = taskData.basic;
// Create title
const title = document.createElement('h2');
title.textContent = 'Basic Anthropometric Measurements';
title.style.cssText = 'margin-bottom: 20px; color: #333; text-align: center;';
basicContainer.appendChild(title);
// Create measurement cards
for (const measurementKey in basicData) {
const measurement = basicData[measurementKey];
const card = document.createElement('div');
card.style.cssText = `
background: white;
border: 2px solid #ddd;
border-radius: 8px;
padding: 15px;
margin: 10px 0;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
pointer-events: auto;
position: relative;
z-index: 1;
`;
card.addEventListener('mouseenter', () => {
card.style.borderColor = '#007bff';
card.style.boxShadow = '0 4px 8px rgba(0,0,0,0.15)';
});
card.addEventListener('mouseleave', () => {
card.style.borderColor = '#ddd';
card.style.boxShadow = '0 2px 4px rgba(0,0,0,0.1)';
});
const cardTitle = document.createElement('h3');
cardTitle.textContent = measurement.title;
cardTitle.style.cssText = 'margin: 0 0 10px 0; color: #007bff; font-size: 18px;';
const cardDescription = document.createElement('p');
cardDescription.textContent = measurement.measurement.definition;
cardDescription.style.cssText = 'margin: 0; color: #666; line-height: 1.4;';
card.appendChild(cardTitle);
card.appendChild(cardDescription);
// Add click handler
card.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
if (selectedDot) {
selectedDot.classList.remove('element-selected');
}
card.classList.add('element-selected');
selectedDot = card;
showInfoPanel(measurement);
});
basicContainer.appendChild(card);
}
}
// Tooltip functionality functions
function showTooltip(element, text, event) {
if (!landmarkTooltip) return;
landmarkTooltip.textContent = text;
landmarkTooltip.classList.add('visible');
// Position tooltip above the cursor
const rect = imageContainer.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
landmarkTooltip.style.left = (x - landmarkTooltip.offsetWidth / 2) + 'px';
landmarkTooltip.style.top = (y - landmarkTooltip.offsetHeight - 10) + 'px';
}
function hideTooltip() {
if (!landmarkTooltip) return;
landmarkTooltip.classList.remove('visible');
}
function addTooltipToElement(element, siteKey, siteData, taskType) {
// Add tooltip functionality for all task types
element.addEventListener('mouseenter', function(event) {
if (isQuizMode) return; // Don't show tooltip in quiz mode
showTooltip(element, siteData.title, event);
});
element.addEventListener('mouseleave', hideTooltip);
element.addEventListener('mousemove', function(event) {
if (isQuizMode) return;
if (landmarkTooltip.classList.contains('visible')) {
const rect = imageContainer.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
landmarkTooltip.style.left = (x - landmarkTooltip.offsetWidth / 2) + 'px';
landmarkTooltip.style.top = (y - landmarkTooltip.offsetHeight - 10) + 'px';
}
});
}
function createDot(siteKey, siteData, taskType) {
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circle.setAttribute("cx", siteData.x);
circle.setAttribute("cy", siteData.y);
circle.setAttribute("r", "1.3%");
circle.setAttribute("data-site", siteKey);
circle.setAttribute("data-task", taskType);
circle.classList.add("measurement-dot", `${taskType}-dot`);
svgDotsContainer.appendChild(circle);
// Add tooltip functionality for all dot-based measurements
addTooltipToElement(circle, siteKey, siteData, taskType);
return circle;
}
function generateInstructionsHTML(data) {
let html = '';
// Generate HTML based on the data structure
if (data.identification) {
// For skinfolds and landmarks - they have identification sections
const sectionType = currentTask === 'skinfolds' ? 'Site Identification' : 'Landmark Identification';
const isCollapsed = currentTask === 'skinfolds' ? ' collapsed' : '';
html += `<div class="collapsible-section">`;
html += `<h4 class="collapsible-header${isCollapsed}">${data.title} ${sectionType}</h4>`;
html += `<div class="collapsible-content${isCollapsed}">`;
html += `<p><strong>Definition:</strong> ${data.identification.definition}</p>`;
html += `<p><strong>Subject position${currentTask === 'skinfolds' ? ' for site marking' : ''}:</strong> ${data.identification.subjectPosition}</p>`;
if (data.identification.location) {
html += `<p><strong>Location of ${currentTask === 'skinfolds' ? 'skinfold site' : 'landmark'}:</strong> ${data.identification.location}</p>`;
}
if (data.identification.technique) {
html += `<p><strong>Palpation technique:</strong> ${data.identification.technique}</p>`;
}
if (data.identification.nomenclatureNote) {
html += `<p><strong>Nomenclature Note:</strong> ${data.identification.nomenclatureNote}</p>`;
}
html += `</div></div>`;
}
if (data.measurement) {
// For anything with measurement procedures
const sectionTitle = currentTask === 'skinfolds' ? 'Measurement Procedure' :
currentTask === 'lengths' ? 'Length Measurement' :
currentTask === 'girths' ? 'Girth Measurement' :
currentTask === 'breadths' ? 'Breadth Measurement' :
currentTask === 'basic' ? 'Measurement Procedure' : 'Measurement';
html += `<div class="collapsible-section">`;
html += `<h4 class="collapsible-header">${sectionTitle}</h4>`;
html += `<div class="collapsible-content">`;
html += `<p><strong>Definition:</strong> ${data.measurement.definition}</p>`;
html += `<p><strong>Subject position${currentTask === 'skinfolds' ? ' for measurement' : ''}:</strong> ${data.measurement.subjectPosition}</p>`;
if (data.measurement.method) {
html += `<p><strong>Method:</strong> ${data.measurement.method}</p>`;
}
if (data.measurement.technique) {
html += `<p><strong>Measurement technique:</strong> ${data.measurement.technique}</p>`;
}
if (data.measurement.notes) {
html += `<p><strong>Note${currentTask === 'skinfolds' ? ' on nomenclature' : ''}:</strong> ${data.measurement.notes}</p>`;
}
if (data.measurement.methods) {
// Special handling for front thigh skinfold multiple methods
data.measurement.methods.forEach(method => {
html += `<p><strong>${method.name}:</strong> ${method.description}</p>`;
});
if (data.measurement.additionalNotes) {
html += `<p>${data.measurement.additionalNotes}</p>`;
}
}
if (data.measurement.techniques) {
html += `<p><strong>General Technique Notes:</strong></p><ul>`;
data.measurement.techniques.forEach(technique => {
html += `<li>${technique}</li>`;
});
html += `</ul>`;
}
html += `</div></div>`;
}
return html;
}
function showInfoPanel(data) {
detailsPanel.classList.add('visible');
interactiveArea.classList.add('showing-info');
infoTitle.textContent = data.title;
infoContent.innerHTML = generateInstructionsHTML(data);
setupCollapsibleSections();
infoDisplay.style.display = 'block';
// Only auto-scroll for non-basic measurements to prevent unwanted scrolling
if (currentTask !== 'basic') {
infoDisplay.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
// Handle video for skinfolds, landmarks, girths, lengths, breadths, and basic measurements
if ((currentTask === 'skinfolds' || currentTask === 'landmarks' || currentTask === 'girths' || currentTask === 'lengths' || currentTask === 'breadths' || currentTask === 'basic') && data.videoId && data.startTime !== undefined && data.endTime !== undefined) {
currentVideoStartTime = data.startTime;
currentVideoEndTime = data.endTime;
const embedUrl = `https://www.youtube.com/embed/${data.videoId}?start=${currentVideoStartTime}&end=${currentVideoEndTime}&autoplay=1&rel=0`;
youtubePlayer.src = embedUrl;
videoPlayerContainer.style.display = 'block';
videoPlayerContainer.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
} else {
videoPlayerContainer.style.display = 'none';
youtubePlayer.src = 'about:blank';
currentVideoStartTime = 0;
currentVideoEndTime = 0;
}
}
function hideInfoPanel() {
detailsPanel.classList.remove('visible');
interactiveArea.classList.remove('showing-info');
infoDisplay.style.display = 'none';
videoPlayerContainer.style.display = 'none';
youtubePlayer.src = 'about:blank';
if (selectedDot) {
selectedDot.classList.remove('element-selected');
selectedDot = null;
}
}
// New event listener for task buttons
taskSelectContainer.addEventListener('click', function(event) {
if (event.target.classList.contains('task-button')) {
const selectedTask = event.target.dataset.task;
if (selectedTask === currentTask) return; // Do nothing if the same task is clicked
// Update active button
const currentActiveButton = taskSelectContainer.querySelector('.task-button.active');
if (currentActiveButton) {
currentActiveButton.classList.remove('active');
}
event.target.classList.add('active');
currentTask = selectedTask;
taskDescription.textContent = taskDescriptions[currentTask];
loadTaskData(currentTask);
updateQuizControlsVisibility();
// Reset quiz mode when switching tasks
if (isQuizMode) {
toggleQuizMode(false);
}
// Reinitialize developer sites if in developer mode
if (developerMode) {
initializeDeveloperSites();
}
}
});
// Event listeners for buttons
if (closeButton) {
closeButton.addEventListener('click', hideInfoPanel);
}
if (closeVideoButton) {
closeVideoButton.addEventListener('click', function() {
videoPlayerContainer.style.display = 'none';
youtubePlayer.src = 'about:blank';
});
}
if (restartVideoButton) {
restartVideoButton.addEventListener('click', function() {
if (currentVideoStartTime > 0) {
const embedUrl = `https://www.youtube.com/embed/${videoId}?start=${currentVideoStartTime}&end=${currentVideoEndTime}&autoplay=1&rel=0`;
youtubePlayer.src = embedUrl;
}
});
}
// Resize handling
function adjustDotPositions() {
const imageWidth = skinfoldImage.offsetWidth;
const imageHeight = skinfoldImage.offsetHeight;
if (imageWidth === 0 || imageHeight === 0) {
return;
}
}
skinfoldImage.onload = adjustDotPositions;
window.addEventListener('resize', adjustDotPositions);
if (skinfoldImage.complete && skinfoldImage.naturalHeight !== 0) {
adjustDotPositions();
}
// Developer mode functions
function toggleDeveloperMode() {
developerMode = !developerMode;
if (developerMode) {
startDeveloperMode();
} else {
stopDeveloperMode();
}
}
function startDeveloperMode() {
developerPanel.style.display = 'block';
document.body.classList.add('developer-mode-active');
// Hide measurement elements based on checkbox state
toggleOverlayVisibility();
// Initialize sites for current task
initializeDeveloperSites();
console.log('Developer mode: ON - Ready to align overlays for', currentTask);
}
function stopDeveloperMode() {
developerPanel.style.display = 'none';
document.body.classList.remove('developer-mode-active');
// Restore measurement elements
const allMeasurementElements = svgDotsContainer.querySelectorAll('.measurement-element, .measurement-dot');
allMeasurementElements.forEach(element => {
element.style.display = '';
});
currentSiteIndex = 0;
currentTaskSites = [];
lastYCoordinate = null;
updateLockedYDisplay();
// Clean up preview line
removePreviewLine();
isWaitingForEndPoint = false;
startPoint = null;
console.log('Developer mode: OFF');
}
function initializeDeveloperSites() {
if (!taskData || !taskData[currentTask]) return;
currentTaskSites = Object.keys(taskData[currentTask]);
currentSiteIndex = 0;
lastYCoordinate = null;
updateLockedYDisplay();
// Clean up any existing preview line
removePreviewLine();
isWaitingForEndPoint = false;
startPoint = null;
if (currentTaskSites.length > 0) {
updateDeveloperDisplay();
}
}
function updateDeveloperDisplay() {
if (currentTaskSites.length === 0) return;
const currentSite = currentTaskSites[currentSiteIndex];
const siteData = taskData[currentTask][currentSite];
currentSiteSpan.textContent = `${currentSite} (${currentSiteIndex + 1}/${currentTaskSites.length})`;
// Set prompt based on site type
if (siteData.type === "line") {
clickPromptSpan.textContent = `${currentSite} - Click START point`;
} else if (siteData.type === "ellipse") {
clickPromptSpan.textContent = `${currentSite} - Click CENTER point`;
} else {
clickPromptSpan.textContent = `${currentSite} - Click dot position`;
}
// Update definition display
updateSiteDefinition(siteData);
}
function updateSiteDefinition(siteData) {
let definition = 'No definition available';
// Get definition from the appropriate section
if (siteData.identification && siteData.identification.definition) {
definition = siteData.identification.definition;
} else if (siteData.measurement && siteData.measurement.definition) {
definition = siteData.measurement.definition;
}
// Add location info if available
if (siteData.identification && siteData.identification.location) {
definition += ' Location: ' + siteData.identification.location;
}
definitionText.textContent = definition;
}
function toggleOverlayVisibility() {
const allMeasurementElements = svgDotsContainer.querySelectorAll('.measurement-element, .measurement-dot');
const shouldHide = hideOverlaysCheckbox.checked;
allMeasurementElements.forEach(element => {
element.style.display = shouldHide ? 'none' : '';
});
}
function updateLockedYDisplay() {
if (lastYCoordinate !== null) {
lockedYValueSpan.textContent = `(Y: ${lastYCoordinate}%)`;
} else {
lockedYValueSpan.textContent = '';
}
}
function createPreviewLine() {
if (!startPoint) return;
previewLine = document.createElementNS("http://www.w3.org/2000/svg", "line");
previewLine.setAttribute("x1", startPoint.x + "%");
previewLine.setAttribute("y1", startPoint.y + "%");
previewLine.setAttribute("x2", startPoint.x + "%");
previewLine.setAttribute("y2", startPoint.y + "%");
previewLine.setAttribute("stroke", "#FF6B35");
previewLine.setAttribute("stroke-width", "2");
previewLine.setAttribute("opacity", "0.8");
previewLine.style.pointerEvents = "none";
svgDotsContainer.appendChild(previewLine);
}
function updatePreviewLine(endX, endY) {
if (!previewLine || !startPoint) return;
previewLine.setAttribute("x2", endX + "%");
previewLine.setAttribute("y2", endY + "%");
}
function removePreviewLine() {
if (previewLine && svgDotsContainer.contains(previewLine)) {
svgDotsContainer.removeChild(previewLine);
}
previewLine = null;
}
function nextSite() {
// Clean up preview line when switching sites
removePreviewLine();
isWaitingForEndPoint = false;
startPoint = null;
// Clear Y-axis lock when moving to new site
lastYCoordinate = null;
updateLockedYDisplay();
currentSiteIndex++;
if (currentSiteIndex >= currentTaskSites.length) {
currentSiteIndex = 0;
}
updateDeveloperDisplay();
}
function prevSite() {
// Clean up preview line when switching sites
removePreviewLine();
isWaitingForEndPoint = false;
startPoint = null;
// Clear Y-axis lock when moving to new site
lastYCoordinate = null;
updateLockedYDisplay();
currentSiteIndex--;
if (currentSiteIndex < 0) {
currentSiteIndex = currentTaskSites.length - 1;
}
updateDeveloperDisplay();
}
function outputCoordinates() {
if (Object.keys(alignmentCoordinates).length === 0) {
console.log('No alignment coordinates recorded yet.');
return;
}
console.log('Alignment Coordinates:');
console.log(JSON.stringify(alignmentCoordinates, null, 2));
// Also copy to clipboard if possible
if (navigator.clipboard) {