-
-
Notifications
You must be signed in to change notification settings - Fork 15
all comments added #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
all comments added #360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -517,6 +517,7 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0 | |
| /** | ||
| * Clear all colored region overlays from a container | ||
| * @param {HTMLElement} container - The container element | ||
| * @returns {void} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what it's worth, adding |
||
| */ | ||
| export function clearColoredRegions(container) { | ||
| if (!container) return; | ||
|
|
@@ -527,6 +528,7 @@ export function clearColoredRegions(container) { | |
|
|
||
| /** | ||
| * Clear all colored region overlays in the entire image container | ||
| * @returns {void} | ||
| */ | ||
| export function clearAllColoredRegions() { | ||
| const container = document.getElementById("bone-image-container"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| // js/description.js | ||
| const GITHUB_RAW_URL = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/data/descriptions/"; | ||
|
|
||
| /** | ||
| * Fetches the description JSON for the given bone/subbone ID from GitHub and | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're transitioning away from fetching our data from GitHub, this should no longer explicitly say that the data is coming from there. In fact, it should not specify where the data is coming from at all, since we're planning on refactoring this to go through other functions anyway. |
||
| * renders it as a list of bullet points inside the `#description-Container` element. | ||
| * Shows an error message in the container if the fetch fails. | ||
| * @param {string} id - The bone or subbone ID (e.g. `"ilium"`, `"iliac_crest"`), | ||
| * used to construct the filename `{id}_description.json`. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| export async function loadDescription(id) { | ||
| const container = document.getElementById("description-Container"); | ||
| container.innerHTML = ""; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,22 @@ document.addEventListener("DOMContentLoaded", () => { | |
| // ---- Map/lookup you can extend later ----------------- | ||
| let _boneById = {}; // filled in setupDropdownListeners | ||
|
|
||
| /** | ||
| * Returns the `#bone-image-container` element, which serves as the host for | ||
| * displayed bone images and their annotation overlays. | ||
| * @returns {HTMLElement|null} The image container element, or null if not found. | ||
| */ | ||
| function getImageStage() { | ||
| return /** @type {HTMLElement|null} */ (document.getElementById("bone-image-container")); | ||
| } | ||
|
|
||
| /** | ||
| * Clears any existing annotation overlay from the image stage. | ||
| * Annotation loading is now handled directly in the dropdown change listeners | ||
| * via the `opts.annotationsUrl` option passed to `loadBoneImages`. | ||
| * @param {string} boneId - The bone ID (unused; retained for future use). | ||
| * @returns {Promise<void>} | ||
| */ | ||
| // Function maybeLoadAnnotations: Logic removed. Annotation URL construction is now in the listeners. | ||
| async function maybeLoadAnnotations(boneId) { | ||
| const stage = getImageStage(); | ||
|
|
@@ -32,7 +44,12 @@ async function maybeLoadAnnotations(boneId) { | |
| // Backend API base (runs on 8000) | ||
| const API_BASE = "http://127.0.0.1:8000"; | ||
|
|
||
| /** Helper: fetch images for a bone/sub-bone and render them */ | ||
| /** Helper: fetch images for a bone/sub-bone and render them | ||
| * @param {string} boneId - The bone or subbone ID to load images for. | ||
| * @param {Object} [options={}] - Options forwarded to `displayBoneImages`, e.g. | ||
| * `{ annotationsUrl: string, boneId: string, isBonesetSelection: boolean }`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't include the example of the options here. If the options that |
||
| * @returns {Promise<void>} | ||
| */ | ||
| async function loadBoneImages(boneId, options = {}) { | ||
| const stage = getImageStage(); | ||
| if (!boneId) { | ||
|
|
@@ -57,6 +74,12 @@ async function loadBoneImages(boneId, options = {}) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Populates the boneset `<select>` element with options from the provided array. | ||
| * Disables the dropdown if no bonesets are available. | ||
| * @param {Array<{id: string, name: string}>} bonesets - Array of boneset objects. | ||
| * @returns {void} | ||
| */ | ||
| export function populateBonesetDropdown(bonesets) { | ||
| const bonesetSelect = document.getElementById("boneset-select"); | ||
| if (!bonesetSelect) { | ||
|
|
@@ -78,6 +101,13 @@ export function populateBonesetDropdown(bonesets) { | |
| bonesetSelect.disabled = false; | ||
| } | ||
|
|
||
| /** | ||
| * Wires up change event listeners on the boneset, bone, and subbone `<select>` elements. | ||
| * Each listener loads images, descriptions, and annotations appropriate to the selection. | ||
| * @param {Object} combinedData - The full application data set containing: | ||
| * `bonesets` {Array}, `bones` {Array}, and `subbones` {Array}. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expected properties of You've already done this correct with |
||
| * @returns {void} | ||
| */ | ||
| export function setupDropdownListeners(combinedData) { | ||
| const bonesetSelect = document.getElementById("boneset-select"); | ||
| const boneSelect = document.getElementById("bone-select"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,29 +9,42 @@ import { imageCaptions } from "./imageCaptions.js"; | |
| let currentBoneId = null; | ||
| let currentIsBonesetSelection = false; // Track if this is a boneset selection | ||
|
|
||
| /** | ||
| * Returns the `#bone-image-container` DOM element. | ||
| * @returns {HTMLElement|null} The image container element, or null if not found. | ||
| */ | ||
| function getImageContainer() { | ||
| return /** @type {HTMLElement|null} */ ( | ||
| document.getElementById("bone-image-container") | ||
| ); | ||
| } | ||
|
|
||
| /** Helper function to get captions for a boneId */ | ||
| /** Helper function to get captions for a boneId | ||
| * @param {string|null} boneId - The bone or subbone ID. | ||
| * @returns {{image1: string|null, image2: string|null}} Caption strings for the two images, or nulls if not found. | ||
| */ | ||
| function getCaptionsForBone(boneId) { | ||
| if (!boneId || !imageCaptions[boneId]) { | ||
| return { image1: null, image2: null }; | ||
| } | ||
| return imageCaptions[boneId]; | ||
| } | ||
|
|
||
| /** Helper to clear existing caption container */ | ||
| /** Removes the `#caption-container` element from the DOM if it exists. | ||
| * @returns {void} | ||
| */ | ||
| function clearCaptionContainer() { | ||
| const existingCaptions = document.getElementById("caption-container"); | ||
| if (existingCaptions) { | ||
| existingCaptions.remove(); | ||
| } | ||
| } | ||
|
|
||
| /** ---- Empty-state / clearing ------------------------------------------- */ | ||
| /** | ||
| * Renders the empty-state placeholder message inside the image container | ||
| * and clears all annotations, colored regions, and captions. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify that "annotations" refers to text annotations specifically. (In some parts of the repo, we also use "annotation" to refer to the colored region annotations, or other image modifications entirely, so we want to be specific when referring to text annotations.) |
||
| * @returns {void} | ||
| */ | ||
| export function showPlaceholder() { | ||
| const c = getImageContainer(); | ||
| if (!c) return; | ||
|
|
@@ -53,6 +66,10 @@ export function showPlaceholder() { | |
| if (imagesContent) imagesContent.classList.remove("has-images"); | ||
| } | ||
|
|
||
| /** | ||
| * Clears all images, annotations, colored regions, and captions from the image container. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above: "annotations" → "text annotations" |
||
| * @returns {void} | ||
| */ | ||
| export function clearImages() { | ||
| const c = getImageContainer(); | ||
| if (c) { | ||
|
|
@@ -72,8 +89,16 @@ export function clearImages() { | |
| if (imagesContent) imagesContent.classList.remove("has-images"); | ||
| } | ||
|
|
||
| /** ---- Public entry: render images array -------------------------------- | ||
| * Optionally pass { annotationsUrl: 'templates/data/annotations/xyz.json', boneId: 'bone_name' } | ||
| /** | ||
| * Renders one or more bone images into the image container, applying the appropriate | ||
| * layout (single, two-up, or grid) based on the number of images provided. | ||
| * Also loads colored region overlays and text annotation overlays if applicable. | ||
| * @param {Array<{url?: string, src?: string, alt?: string, filename?: string}>} images - Array of image objects to display. | ||
| * @param {Object} [options={}] - Optional display configuration: | ||
| * @param {string} [options.annotationsUrl] - API URL for text annotation JSON. | ||
| * @param {string} [options.boneId] - Bone ID used for colored region overlays. | ||
| * @param {boolean} [options.isBonesetSelection] - True when displaying the full boneset view. | ||
| * @returns {void} | ||
| */ | ||
| export function displayBoneImages(images, options = {}) { | ||
| const container = getImageContainer(); | ||
|
|
@@ -114,6 +139,13 @@ export function displayBoneImages(images, options = {}) { | |
| } | ||
|
|
||
| //** ---- Single image ------------------------------------------------------ */ | ||
| /** | ||
| * Renders a single bone image with its colored region overlay and text annotations. | ||
| * @param {{url?: string, src?: string, alt?: string, filename?: string}} image - The image object to display. | ||
| * @param {HTMLElement} container - The image container element. | ||
| * @param {Object} [options={}] - Options forwarded from `displayBoneImages`. | ||
| * @returns {void} | ||
| */ | ||
| function displaySingleImage(image, container, options = {}) { | ||
| // Get captions for this bone | ||
| const captions = getCaptionsForBone(currentBoneId); | ||
|
|
@@ -197,6 +229,15 @@ const TWO_IMAGE_ROTATION = { | |
| right: { rot_deg: 0, flipH: false }, | ||
| }; | ||
|
|
||
| /** | ||
| * Applies a CSS rotation (and optional horizontal flip) to an image element | ||
| * based on the PowerPoint rotation template for the given view. | ||
| * @param {HTMLImageElement} imgEl - The image element to transform. | ||
| * @param {Object} [options={}] - Rotation parameters. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This incorrectly lists the default value for |
||
| * @param {number} [options.rot_deg=0] - Rotation angle in degrees. | ||
| * @param {boolean} [options.flipH=false] - Whether to flip the image horizontally. | ||
| * @returns {void} | ||
| */ | ||
| function applyRotation(imgEl, { rot_deg = 0, flipH = false } = {}) { | ||
| const parts = []; | ||
| if (flipH) parts.push("scaleX(-1)"); | ||
|
|
@@ -206,6 +247,14 @@ function applyRotation(imgEl, { rot_deg = 0, flipH = false } = {}) { | |
| imgEl.style.willChange = "transform"; | ||
| } | ||
|
|
||
| /** | ||
| * Renders two bone images side by side, each with its own colored region overlay. | ||
| * Appends a two-column caption bar beneath the images if captions are available. | ||
| * @param {Array<{url?: string, src?: string, alt?: string, filename?: string}>} images - Array of exactly two image objects. | ||
| * @param {HTMLElement} container - The image container element. | ||
| * @param {Object} [options={}] - Options forwarded from `displayBoneImages`. | ||
| * @returns {void} | ||
| */ | ||
| function displayTwoImages(images, container, options = {}) { | ||
| // Get captions for this bone | ||
| const captions = getCaptionsForBone(currentBoneId); | ||
|
|
@@ -299,6 +348,13 @@ function displayTwoImages(images, container, options = {}) { | |
| } | ||
|
|
||
| /** ---- 3+ images grid ---------------------------------------------------- */ | ||
| /** | ||
| * Renders three or more bone images in a wrapping grid layout. | ||
| * Does not load colored regions or annotations (used for supplementary views). | ||
| * @param {Array<{url?: string, src?: string, alt?: string, filename?: string}>} images - Array of image objects. | ||
| * @param {HTMLElement} container - The image container element. | ||
| * @returns {void} | ||
| */ | ||
| function displayMultipleImages(images, container) { | ||
| const wrapper = document.createElement("div"); | ||
| wrapper.className = "multiple-image-wrapper"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct—this function expects the fields
normalized_geometryand eitherannotationsortext_annotations. Although really I think that's a bit messy...why is this function expecting two possible formats, when really only one should exist? The line where it's checking for eitherannotationsortext_annotationsshould be modified such that it's only looking for one of the two—whichever one actually is expected to exist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: The expected properties should be listed in the format documented here: https://jsdoc.app/tags-param#parameters-with-properties
You've already done this correctly with
imageDisplay.applyRotation