Skip to content

Commit 61c964c

Browse files
Merge pull request #372 from oss-slu/cleanup
Cleanup
2 parents 79b1750 + 455c139 commit 61c964c

20 files changed

Lines changed: 88 additions & 629 deletions

boneset-api/server.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,8 @@ app.get("/api/search", searchLimiter, (req, res) => {
496496
}
497497
});
498498

499-
// CORRECTED SERVER STARTUP LOGIC
500-
// 1. Initialize cache first. 2. Start server only if run directly (for testability).
501499
async function startServer() {
502-
await initializeSearchCache(); // Wait for the cache to be built
500+
await initializeSearchCache();
503501

504502
// Start the server only if this file is run directly (not imported)
505503
if (require.main == module) {
@@ -509,7 +507,7 @@ async function startServer() {
509507
}
510508
}
511509

512-
startServer(); // Call the async function to begin startup
510+
startServer();
513511

514512
// Export for tests or other modules if needed
515513
module.exports = {

editor/push.html

Lines changed: 0 additions & 24 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
"jest-environment-jsdom": "^30.2.0"
3636
},
3737
"directories": {
38-
"test": "tests"
38+
"test": "templates/tests"
3939
}
4040
}

templates/js/annotationOverlay.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// templates/js/annotationOverlay.js
2-
// Small, self-contained overlay module.
3-
4-
const PPT_EMU = { W: 9_144_000, H: 6_858_000 }; // PowerPoint slide size in EMUs
5-
61
function ensureStage(container) {
72
let stage = container.querySelector(".annotation-stage");
83
if (!stage) {
@@ -31,14 +26,14 @@ export function clearAnnotations(container) {
3126
* @param {Object} norm - The normalized geometry {normX, normY, normW, normH}.
3227
* @returns {Object} Pixel coordinates {left, top, width, height}.
3328
*/
34-
function normalizedRectToPx(rect, box, norm) { // <--- RENAMED to reflect change
35-
// 🛑 FIX: Input coordinates (rect.x, rect.y, etc.) are now normalized decimals (0.0 to 1.0).
29+
function normalizedRectToPx(rect, box, norm) {
30+
// Input coordinates (rect.x, rect.y, etc.) are now normalized decimals (0.0 to 1.0).
3631

3732
// Normalized Offset (normX, normY are also 0.0 to 1.0)
3833
const normalizedOffsetX = norm.normX;
3934
const normalizedOffsetY = norm.normY;
4035

41-
// We now calculate pixel coordinates by: (Normalized Coord - Normalized Offset) * Effective Pixel Size (box.w/h)
36+
// We calculate pixel coordinates by: (Normalized Coord - Normalized Offset) * Effective Pixel Size (box.w/h)
4237
return {
4338
left: (rect.x - normalizedOffsetX) * box.w,
4439
top: (rect.y - normalizedOffsetY) * box.h,
@@ -55,8 +50,7 @@ function normalizedRectToPx(rect, box, norm) { // <--- RENAMED to reflect change
5550
* @returns {Object} Pixel coordinates {x, y}.
5651
*/
5752
function normalizedPointToPx(pt, box, norm) { // <--- RENAMED to reflect change
58-
// 🛑 FIX: Input coordinates (pt.x, pt.y) are now normalized decimals (0.0 to 1.0).
59-
53+
// Input coordinates (pt.x, pt.y) are normalized decimals (0.0 to 1.0).
6054
const normalizedOffsetX = norm.normX;
6155
const normalizedOffsetY = norm.normY;
6256

@@ -81,21 +75,21 @@ export function drawAnnotations(container, annotationsJson) {
8175
svg.innerHTML = "";
8276
labels.innerHTML = "";
8377

84-
// 1. Get current pixel dimensions of the image container.
78+
// Get current pixel dimensions of the image container.
8579
const rect = container.getBoundingClientRect();
8680

87-
// 2. Extract the normalization factors from the JSON (provided by backend).
81+
// Extract the normalization factors from the JSON (provided by backend).
8882
const norm = annotationsJson.normalized_geometry || { normX: 0, normY: 0, normW: 1, normH: 1 };
8983

90-
// 3. Define the *effective* coordinate box for scaling.
84+
// Define the *effective* coordinate box for scaling.
9185
// We scale the container size (rect.width/height) by the crop ratios (normW/normH).
9286
// This calculates the effective pixel dimensions relative to the full PPT slide size.
9387
const box = {
9488
w: rect.width / norm.normW,
9589
h: rect.height / norm.normH
9690
};
9791

98-
// 4. Get the list of annotations.
92+
// Get the list of annotations.
9993
const list = annotationsJson.annotations || annotationsJson.text_annotations || [];
10094

10195
list.forEach((a) => {
@@ -118,8 +112,8 @@ export function drawAnnotations(container, annotationsJson) {
118112
display: "flex",
119113
alignItems: "center",
120114
justifyContent: "center",
121-
whiteSpace: "pre-line", // 👈 KEY: show newlines
122-
textAlign: "center", // optional: center both lines
115+
whiteSpace: "pre-line", // show newlines
116+
textAlign: "center", // center both lines
123117
});
124118

125119
labels.appendChild(el);
@@ -150,7 +144,7 @@ export async function loadAndDrawAnnotations(container, jsonUrl) {
150144
if (!res.ok) return;
151145
const data = await res.json();
152146

153-
// The backend now provides data in the structure expected by drawAnnotations
147+
// The backend provides data in the structure expected by drawAnnotations
154148
drawAnnotations(container, data);
155149
attachAutoscale(container); // keep aligned on resize
156150
}
@@ -166,7 +160,4 @@ function attachAutoscale(container) {
166160
});
167161
ro.observe(container);
168162
stage.__resizeObs = ro;
169-
}
170-
171-
// Optional global for non-module usage
172-
window.AnnotationOverlay = { clearAnnotations, drawAnnotations, loadAndDrawAnnotations };
163+
}

templates/js/api.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// api.js - Centralized API configuration and data fetching
2-
3-
// Centralized API configuration
41
const API_CONFIG = {
52
BASE_URL: "http://127.0.0.1:8000",
63
ENDPOINTS: {
@@ -25,20 +22,6 @@ export async function fetchCombinedData() {
2522
}
2623
}
2724

28-
export async function fetchMockBoneData() {
29-
try {
30-
const response = await fetch(API_CONFIG.ENDPOINTS.MOCK_BONE_DATA);
31-
if (!response.ok) {
32-
throw new Error(`HTTP error! status: ${response.status}`);
33-
}
34-
const data = await response.json();
35-
return data;
36-
} catch (error) {
37-
console.error("Error fetching mock bone data:", error);
38-
return null;
39-
}
40-
}
41-
4225
/**
4326
* Fetch full bone data (description + images) for a single bone from the backend API.
4427
* The backend pulls these files from the data GitHub branch.

templates/js/coloredRegionsOverlay.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const OVERLAY_ADJUSTMENTS = {
8181
*/
8282
async function fetchColoredRegionData(boneId, isBonesetSelection = false) {
8383
if (!boneId) {
84-
console.debug("[ColoredRegions] No boneId provided for colored regions");
84+
console.error("[ColoredRegions] No boneId provided for colored regions");
8585
return null;
8686
}
8787

@@ -90,7 +90,7 @@ async function fetchColoredRegionData(boneId, isBonesetSelection = false) {
9090
// Map ilium to bony_pelvis for boneset selections
9191
let mappedBoneId = boneId;
9292
if (boneId === "ilium" && isBonesetSelection) {
93-
console.log("[ColoredRegions] Mapping \"ilium\" to \"bony_pelvis\" for boneset selection");
93+
console.debug("[ColoredRegions] Mapping \"ilium\" to \"bony_pelvis\" for boneset selection");
9494
mappedBoneId = "bony_pelvis";
9595
}
9696

@@ -146,9 +146,9 @@ function convertCommandToPixels(command, dimensions, debugInfo = {}) {
146146
if (command.x !== undefined) {
147147
converted.x = emuToPixels(command.x, slideWidth, imageWidth);
148148
if (debugInfo.isFirstCommand) {
149-
console.log(`[ColoredRegions] First coord conversion: EMU(${command.x}, ${command.y}) -> Pixel(${converted.x.toFixed(2)}, ${emuToPixels(command.y, slideHeight, imageHeight).toFixed(2)})`);
150-
console.log(`[ColoredRegions] EMU dimensions: ${slideWidth} x ${slideHeight}`);
151-
console.log(`[ColoredRegions] Pixel dimensions: ${imageWidth} x ${imageHeight}`);
149+
console.debug(`[ColoredRegions] First coord conversion: EMU(${command.x}, ${command.y}) -> Pixel(${converted.x.toFixed(2)}, ${emuToPixels(command.y, slideHeight, imageHeight).toFixed(2)})`);
150+
console.debug(`[ColoredRegions] EMU dimensions: ${slideWidth} x ${slideHeight}`);
151+
console.debug(`[ColoredRegions] Pixel dimensions: ${imageWidth} x ${imageHeight}`);
152152
}
153153
}
154154
if (command.y !== undefined) {
@@ -235,14 +235,14 @@ function createColoredRegionsSVG(coloredRegions, imageWidth, imageHeight, imageD
235235
svg.style.width = "100%";
236236
svg.style.height = "100%";
237237
svg.style.pointerEvents = "none"; // Allow clicks to pass through to image
238-
239-
console.log(`[ColoredRegions DEBUG] Creating SVG for bone: ${boneId}, imageIndex: ${imageIndex}`);
240-
console.log("[ColoredRegions DEBUG] OVERLAY_ADJUSTMENTS lookup:", OVERLAY_ADJUSTMENTS[boneId]);
238+
239+
console.debug(`[ColoredRegions DEBUG] Creating SVG for bone: ${boneId}, imageIndex: ${imageIndex}`);
240+
console.debug("[ColoredRegions DEBUG] OVERLAY_ADJUSTMENTS lookup:", OVERLAY_ADJUSTMENTS[boneId]);
241241

242242
// Apply positioning adjustments if defined for this bone and image
243243
if (OVERLAY_ADJUSTMENTS[boneId] && OVERLAY_ADJUSTMENTS[boneId][imageIndex]) {
244244
const adjustments = OVERLAY_ADJUSTMENTS[boneId][imageIndex];
245-
console.log("[ColoredRegions DEBUG] Found adjustments:", adjustments);
245+
console.debug("[ColoredRegions DEBUG] Found adjustments:", adjustments);
246246
const transforms = [];
247247

248248
if (adjustments.x !== 0 || adjustments.y !== 0) {
@@ -260,7 +260,7 @@ function createColoredRegionsSVG(coloredRegions, imageWidth, imageHeight, imageD
260260
if (transforms.length > 0) {
261261
svg.style.transform = transforms.join(" ");
262262
svg.style.transformOrigin = "center";
263-
console.log(`[ColoredRegions] Applied positioning adjustments for ${boneId} image ${imageIndex}: ${svg.style.transform}`);
263+
console.debug(`[ColoredRegions] Applied positioning adjustments for ${boneId} image ${imageIndex}: ${svg.style.transform}`);
264264
}
265265
}
266266

@@ -273,8 +273,8 @@ function createColoredRegionsSVG(coloredRegions, imageWidth, imageHeight, imageD
273273
imageWidth: imageWidth,
274274
imageHeight: imageHeight
275275
};
276-
277-
console.log("[ColoredRegions] Coordinate conversion:", {
276+
277+
console.debug("[ColoredRegions] Coordinate conversion:", {
278278
sourceWidth: dimensions.slideWidth,
279279
sourceHeight: dimensions.slideHeight,
280280
targetWidth: dimensions.imageWidth,
@@ -357,7 +357,6 @@ function createColoredRegionsSVG(coloredRegions, imageWidth, imageHeight, imageD
357357
path.setAttribute("data-region-type", "fill");
358358
}
359359

360-
// Add to SVG
361360
svg.appendChild(path);
362361

363362
console.debug(`Created colored region path ${pathIndex + 1}/${pathDataArray.length}: ${region.anatomical_name} (${region.color_name})`);
@@ -382,9 +381,8 @@ function createColoredRegionsSVG(coloredRegions, imageWidth, imageHeight, imageD
382381
* @returns {Promise<void>}
383382
*/
384383
export async function displayColoredRegions(imageElement, boneId, imageIndex = 0, isBonesetSelection = false) {
385-
console.log("[ColoredRegions] ============ START displayColoredRegions ============");
386-
console.log(`[ColoredRegions] boneId: ${boneId}, imageIndex: ${imageIndex}, isBonesetSelection: ${isBonesetSelection}`);
387-
console.log("[ColoredRegions] imageElement:", imageElement);
384+
console.debug(`[ColoredRegions] boneId: ${boneId}, imageIndex: ${imageIndex}, isBonesetSelection: ${isBonesetSelection}`);
385+
console.debug("[ColoredRegions] imageElement:", imageElement);
388386

389387
if (!imageElement || !boneId) {
390388
console.debug("[ColoredRegions] Missing image element or boneId for colored regions");
@@ -395,7 +393,7 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
395393
let mappedBoneId = boneId;
396394
if (boneId === "ilium" && isBonesetSelection) {
397395
mappedBoneId = "bony_pelvis";
398-
console.log("[ColoredRegions] Using mapped bone ID \"bony_pelvis\" for positioning adjustments");
396+
console.debug("[ColoredRegions] Using mapped bone ID \"bony_pelvis\" for positioning adjustments");
399397
}
400398

401399
// Fetch colored region data
@@ -404,7 +402,7 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
404402

405403
// Return early if no colored region data exists
406404
if (!regionData) {
407-
console.debug(`[ColoredRegions] No colored regions to display for ${boneId}`);
405+
console.log(`[ColoredRegions] No colored regions to display for ${boneId}`);
408406
return;
409407
}
410408

@@ -413,8 +411,8 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
413411
let regionsToDisplay = [];
414412

415413
if (regionData.images && Array.isArray(regionData.images)) {
416-
// New structure: data organized by image
417-
console.log(`[ColoredRegions] Using new multi-image structure with ${regionData.images.length} images`);
414+
// One possible structure: data organized by image
415+
console.debug(`[ColoredRegions] Using organized-by-image structure with ${regionData.images.length} images`);
418416

419417
if (imageIndex >= 0 && imageIndex < regionData.images.length) {
420418
imageData = regionData.images[imageIndex];
@@ -424,8 +422,8 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
424422
return;
425423
}
426424
} else if (regionData.colored_regions) {
427-
// Old structure: single set of regions for all images
428-
console.log("[ColoredRegions] Using old single-image structure");
425+
// Alternate structure: single set of regions for all images
426+
console.debug("[ColoredRegions] Using alternate structure");
429427
regionsToDisplay = regionData.colored_regions;
430428
imageData = {
431429
width: regionData.image_dimensions?.width,
@@ -442,7 +440,7 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
442440

443441
// Wait for image to load to get correct dimensions
444442
if (!imageElement.complete) {
445-
console.log("[ColoredRegions] Waiting for image to complete loading...");
443+
console.debug("[ColoredRegions] Waiting for image to complete loading...");
446444
await new Promise(resolve => {
447445
imageElement.addEventListener("load", resolve, { once: true });
448446
});
@@ -454,8 +452,8 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
454452
const imageWidth = imageElement.naturalWidth;
455453
const imageHeight = imageElement.naturalHeight;
456454

457-
console.log(`[ColoredRegions] Image natural dimensions: ${imageWidth}x${imageHeight}`);
458-
console.log(`[ColoredRegions] Image displayed dimensions: ${imageElement.offsetWidth}x${imageElement.offsetHeight}`);
455+
console.debug(`[ColoredRegions] Image natural dimensions: ${imageWidth}x${imageHeight}`);
456+
console.debug(`[ColoredRegions] Image displayed dimensions: ${imageElement.offsetWidth}x${imageElement.offsetHeight}`);
459457

460458
if (imageWidth === 0 || imageHeight === 0) {
461459
console.warn("[ColoredRegions] Image has zero dimensions, cannot display colored regions");
@@ -492,13 +490,13 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
492490

493491
// Add the SVG overlay
494492
parent.appendChild(svg);
495-
496-
console.log("[ColoredRegions] SVG appended to parent container");
497-
console.log("[ColoredRegions] Parent element:", parent);
498-
console.log("[ColoredRegions] Parent classes:", parent.className);
499-
console.log("[ColoredRegions] SVG data-bone attribute:", svg.getAttribute("data-bone"));
500-
console.log("[ColoredRegions] SVG element:", svg);
501-
console.log(`[ColoredRegions] SVG has ${svg.children.length} path elements`);
493+
494+
console.debug("[ColoredRegions] SVG appended to parent container");
495+
console.debug("[ColoredRegions] Parent element:", parent);
496+
console.debug("[ColoredRegions] Parent classes:", parent.className);
497+
console.debug("[ColoredRegions] SVG data-bone attribute:", svg.getAttribute("data-bone"));
498+
console.debug("[ColoredRegions] SVG element:", svg);
499+
console.debug(`[ColoredRegions] SVG has ${svg.children.length} path elements`);
502500

503501
console.log(`[ColoredRegions] Successfully displayed ${regionsToDisplay.length} colored regions for image ${imageIndex}`);
504502
}

templates/js/description.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// js/description.js
21
const GITHUB_RAW_URL = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/data/descriptions/";
32

43
export async function loadDescription(id) {

0 commit comments

Comments
 (0)