Skip to content

Commit 566c101

Browse files
Copilotlstein
andcommitted
Make colorizeUmap async to show spinner before heavy Plotly operations
Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
1 parent 3646ca8 commit 566c101

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

  • photomap/frontend/static/javascript

photomap/frontend/static/javascript/umap.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ export async function fetchUmapData() {
238238
scrollZoom: true,
239239
};
240240

241-
Plotly.newPlot("umapPlot", [allPointsTrace, currentImageTrace], layout, config).then((gd) => {
241+
Plotly.newPlot("umapPlot", [allPointsTrace, currentImageTrace], layout, config).then(async (gd) => {
242242
document.getElementById("umapContent").style.display = "block";
243243
setUmapWindowSize("fullscreen");
244244
hideUmapSpinner();
245245

246246
window.dispatchEvent(new CustomEvent("umapRedrawn"));
247247

248-
setUmapColorMode();
248+
await setUmapColorMode();
249249
let hoverTimer = null;
250250
let isHovering = false;
251251

@@ -410,7 +410,7 @@ export async function fetchUmapData() {
410410
// Dispatch event to notify that UMAP data has been loaded
411411
window.dispatchEvent(new CustomEvent("umapDataLoaded"));
412412

413-
setUmapColorMode();
413+
await setUmapColorMode();
414414
} finally {
415415
hideUmapSpinner();
416416
}
@@ -457,7 +457,7 @@ plotDiv.addEventListener("mouseleave", () => {
457457
});
458458

459459
// --- Dynamic Colorization ---
460-
export function colorizeUmap({ highlight = false, searchResults = [] } = {}) {
460+
export async function colorizeUmap({ highlight = false, searchResults = [] } = {}) {
461461
if (!points.length) {
462462
return;
463463
}
@@ -467,6 +467,9 @@ export function colorizeUmap({ highlight = false, searchResults = [] } = {}) {
467467
return;
468468
}
469469

470+
// Yield to the browser to allow spinner to render before heavy Plotly operations
471+
await new Promise((resolve) => setTimeout(resolve, 0));
472+
470473
if (highlight && searchResults.length > 0) {
471474
const searchSet = new Set(searchResults.map((r) => r.index));
472475

@@ -569,8 +572,8 @@ window.addEventListener("stateReady", () => {
569572
const highlightCheckbox = document.getElementById("umapHighlightSelection");
570573
if (highlightCheckbox) {
571574
highlightCheckbox.checked = false;
572-
highlightCheckbox.addEventListener("change", () => {
573-
setUmapColorMode();
575+
highlightCheckbox.addEventListener("change", async () => {
576+
await setUmapColorMode();
574577
});
575578
}
576579

@@ -661,9 +664,9 @@ function updateExitFullscreenCheckboxState() {
661664
}
662665

663666
// --- Update colorization after search or cluster selection ---
664-
window.addEventListener("searchResultsChanged", (e) => {
667+
window.addEventListener("searchResultsChanged", async (e) => {
665668
updateUmapColorModeAvailability(e.detail.results);
666-
setUmapColorMode();
669+
await setUmapColorMode();
667670
// deactivate fullscreen mode when search results have come in (if enabled)
668671
if (state.searchResults.length > 0 && isFullscreen && state.umapExitFullscreenOnSelection) {
669672
setTimeout(() => toggleFullscreen(false), 100); // slight delay to avoid flicker
@@ -920,8 +923,8 @@ function removeUmapThumbnail() {
920923
umapThumbnailDiv = null;
921924
}
922925

923-
export function setUmapColorMode() {
924-
colorizeUmap({
926+
export async function setUmapColorMode() {
927+
await colorizeUmap({
925928
highlight: document.getElementById("umapHighlightSelection")?.checked,
926929
searchResults: state.searchResults,
927930
});
@@ -943,7 +946,7 @@ function updateUmapColorModeAvailability(searchResults = []) {
943946
highlightCheckbox.disabled = true;
944947
highlightCheckbox.parentElement.style.opacity = "0.5";
945948
}
946-
setUmapColorMode();
949+
// Note: setUmapColorMode is called by the searchResultsChanged event handler
947950
}
948951

949952
// ------------- Handling Landmark Thumbnails -------------

0 commit comments

Comments
 (0)