Skip to content

Commit 0704c19

Browse files
committed
fix: ensures is2DPreviewCandidate always relies on the preview.js output
1 parent c3ed4b6 commit 0704c19

2 files changed

Lines changed: 24 additions & 28 deletions

File tree

src/pages/DatasetDetailPage.tsx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ const DatasetDetailPage: React.FC = () => {
498498
"Is Internal:",
499499
isInternal
500500
);
501+
// Clear any stale preview type from last run
502+
delete (window as any).__previewType;
501503
// fix spinner
502504
setIsPreviewLoading(true); // Show the spinner overlay
503505
setPreviewIndex(idx);
@@ -515,14 +517,21 @@ const DatasetDetailPage: React.FC = () => {
515517
// };
516518

517519
const is2DPreviewCandidate = (obj: any): boolean => {
518-
// return true;
519-
console.log("obj", obj);
520-
if (typeof obj === "string" && obj.includes("db=optics-at-martinos")) {
521-
return false;
522-
}
523-
if (typeof obj === "string" && obj.endsWith(".jdb")) {
524-
return true;
520+
if (typeof window !== "undefined" && (window as any).__previewType) {
521+
return (window as any).__previewType === "2d";
525522
}
523+
// if (window.__previewType) {
524+
// console.log("work~~~~~~~");
525+
// return window.__previewType === "2d";
526+
// }
527+
console.log("is 2d preview candidate !== 2d");
528+
console.log("obj", obj);
529+
// if (typeof obj === "string" && obj.includes("db=optics-at-martinos")) {
530+
// return false;
531+
// }
532+
// if (typeof obj === "string" && obj.endsWith(".jdb")) {
533+
// return true;
534+
// }
526535
if (!obj || typeof obj !== "object") {
527536
return false;
528537
}
@@ -540,22 +549,6 @@ const DatasetDetailPage: React.FC = () => {
540549
(dim.length === 1 || dim.length === 2) &&
541550
dim.every((v) => typeof v === "number" && v > 0)
542551
);
543-
544-
// 2. Ensure `dim` is a valid array of numbers.
545-
// if (!Array.isArray(dim) || dim.some((v) => typeof v !== "number")) {
546-
// return false;
547-
// }
548-
549-
// 3. THE CORE FIX: Count dimensions with a size greater than 1.
550-
// const significantDimensions = dim.filter((size) => size > 1).length;
551-
552-
// 4. If there are 1 or 2 significant dimensions, it can be plotted in 2D.
553-
// This will correctly handle shapes like:
554-
// - [1500] (significantDimensions = 1) -> true
555-
// - [52, 1500] (significantDimensions = 2) -> true
556-
// - [52, 1500, 1] (significantDimensions = 2) -> true
557-
// - [64, 64, 20] (significantDimensions = 3) -> false
558-
// return significantDimensions > 0 && significantDimensions <= 2;
559552
};
560553
// for add spinner ---- start
561554
// When legacy preview is actually ready, turn off spinner & open modal
@@ -566,6 +559,7 @@ const DatasetDetailPage: React.FC = () => {
566559
setPreviewOpen(true);
567560
}
568561
delete window.__onPreviewReady;
562+
delete (window as any).__previewType; // for is2DPreviewCandidate
569563
};
570564
// -----end
571565

src/utils/preview.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ function drawpreview(cfg) {
232232
}
233233
// for spinner
234234
// --- Signal React that 3D preview is ready ---
235+
window.__previewType = "3d";
235236
if (typeof window.__onPreviewReady === "function") {
236237
window.__onPreviewReady();
237238
}
@@ -402,6 +403,7 @@ function dopreview(key, idx, isinternal, hastime) {
402403

403404
// for spinner
404405
// --- Signal React that 2D preview is ready ---
406+
window.__previewType = "2d";
405407
if (typeof window.__onPreviewReady === "function") {
406408
window.__onPreviewReady();
407409
}
@@ -1741,7 +1743,7 @@ function previewdataurl(url, idx) {
17411743
if (urldata.hasOwnProperty(url)) {
17421744
const cached = urldata[url];
17431745

1744-
// fNIRS / time-series (cached)
1746+
// fNIRS / time-series (cached)
17451747
if (cached?.data?.dataTimeSeries) {
17461748
let serieslabel = true;
17471749
if (cached.data.measurementList) {
@@ -1761,17 +1763,17 @@ function previewdataurl(url, idx) {
17611763
cached.data.dataTimeSeries
17621764
).T;
17631765

1764-
previewdata(plotData2D, idx, false, serieslabel); // 🔔 triggers __onPreviewReady
1766+
previewdata(plotData2D, idx, false, serieslabel); // triggers __onPreviewReady
17651767
return;
17661768
}
17671769

1768-
// Mesh/volume (cached)
1770+
// Mesh/volume (cached)
17691771
if (cached instanceof nj.NdArray || cached?.MeshNode) {
1770-
previewdata(cached, idx, false); // 🔔 triggers __onPreviewReady
1772+
previewdata(cached, idx, false); // triggers __onPreviewReady
17711773
return;
17721774
}
17731775

1774-
// 🔂 Fallback: still try to preview whatever it is
1776+
// Fallback: still try to preview whatever it is
17751777
previewdata(cached, idx, false);
17761778
return;
17771779
}

0 commit comments

Comments
 (0)