Skip to content

Commit d9847ab

Browse files
committed
fix: resolve issue with fNIRS data display to ensure correct rendering
1 parent 219cf4a commit d9847ab

2 files changed

Lines changed: 111 additions & 4 deletions

File tree

src/pages/DatasetDetailPage.tsx

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,47 @@ const DatasetDetailPage: React.FC = () => {
515515
// };
516516

517517
const is2DPreviewCandidate = (obj: any): boolean => {
518-
if (!obj || typeof obj !== "object") return false;
519-
if (!obj._ArrayType_ || !obj._ArraySize_ || !obj._ArrayZipData_)
518+
// return true;
519+
console.log("obj", obj);
520+
if (typeof obj === "string" && obj.includes("db=optics-at-martinos")) {
520521
return false;
522+
}
523+
if (typeof obj === "string" && obj.endsWith(".jdb")) {
524+
return true;
525+
}
526+
if (!obj || typeof obj !== "object") {
527+
return false;
528+
}
529+
console.log("=======after first condition");
530+
if (!obj._ArrayType_ || !obj._ArraySize_ || !obj._ArrayZipData_) {
531+
console.log("inside second condition");
532+
return false;
533+
}
521534
const dim = obj._ArraySize_;
535+
console.log("array.isarray(dim)", Array.isArray(dim));
536+
console.log("dim.length", dim.length === 1 || dim.length === 2);
537+
522538
return (
523539
Array.isArray(dim) &&
524540
(dim.length === 1 || dim.length === 2) &&
525541
dim.every((v) => typeof v === "number" && v > 0)
526542
);
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;
527559
};
528560
// for add spinner ---- start
529561
// When legacy preview is actually ready, turn off spinner & open modal
@@ -622,8 +654,18 @@ const DatasetDetailPage: React.FC = () => {
622654
typeof dataOrUrl === "string" ? extractFileName(dataOrUrl) : "";
623655
if (isPreviewableFile(fileName)) {
624656
(window as any).previewdataurl(dataOrUrl, idx);
657+
const is2D = is2DPreviewCandidate(dataOrUrl);
625658
const panel = document.getElementById("chartpanel");
626-
if (panel) panel.style.display = "none"; // 🔒 Hide chart panel on 3D external
659+
console.log("is2D", is2D);
660+
console.log("panel", panel);
661+
662+
if (is2D) {
663+
console.log("📊 2D data → rendering inline with dopreview()");
664+
if (panel) panel.style.display = "block"; // 🔓 Show it!
665+
setPreviewOpen(false); // ⛔ Don't open modal
666+
} else {
667+
if (panel) panel.style.display = "none"; // 🔒 Hide chart panel on 3D external
668+
}
627669
//add spinner
628670
// setPreviewDataKey(dataOrUrl);
629671
// setPreviewOpen(true);

src/utils/preview.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ function previewdata(key, idx, isinternal, hastime) {
246246
isinternal,
247247
intdata: window.intdata,
248248
});
249+
console.log("key in previewdata", key);
249250
if (!hasthreejs) {
250251
$.when(
251252
$.getScript("https://mcx.space/cloud/js/OrbitControls.js"),
@@ -255,9 +256,11 @@ function previewdata(key, idx, isinternal, hastime) {
255256
).done(function () {
256257
hasthreejs = true;
257258
dopreview(key, idx, isinternal, hastime);
259+
console.log("into the previewdata function if");
258260
});
259261
} else {
260262
dopreview(key, idx, isinternal, hastime);
263+
console.log("into the previewdata function else");
261264
}
262265
}
263266

@@ -281,8 +284,21 @@ function dopreview(key, idx, isinternal, hastime) {
281284
return;
282285
}
283286
} else {
287+
// dataroot = key;
288+
// console.log("into dopreview external data's dataroot", dataroot);
289+
284290
if (window.extdata && window.extdata[idx] && window.extdata[idx][2]) {
285-
dataroot = window.extdata[idx][2];
291+
if (typeof key === "object") {
292+
dataroot = key;
293+
console.log("if key is object", typeof key);
294+
} else {
295+
dataroot = window.extdata[idx][2];
296+
console.log("type of key", typeof key);
297+
}
298+
299+
// dataroot = key;
300+
301+
console.log("into dopreview external data's dataroot", dataroot);
286302
} else {
287303
console.error("❌ External data not ready for index", idx);
288304
return;
@@ -302,7 +318,9 @@ function dopreview(key, idx, isinternal, hastime) {
302318
dataroot = window.extdata[idx][2];
303319
}
304320
} else if (dataroot instanceof nj.NdArray) {
321+
console.log("dataroot before ndim", dataroot);
305322
ndim = dataroot.shape.length;
323+
console.log("ndim", ndim);
306324
}
307325

308326
if (ndim < 3 && ndim > 0) {
@@ -327,9 +345,16 @@ function dopreview(key, idx, isinternal, hastime) {
327345
'<h4>Data preview</h4><a href="javascript:void(0)" class="closebtn" onclick="$(\'#chartpanel\').hide()" title="Close">&times;</a><div id="plotchart"></div>'
328346
);
329347
if (dataroot instanceof nj.NdArray) {
348+
console.log("dataroot", dataroot);
330349
if (dataroot.shape[0] > dataroot.shape[1])
331350
dataroot = dataroot.transpose();
351+
console.log("is nj.NdArray:", dataroot instanceof nj.NdArray);
352+
console.log("dtype:", dataroot.dtype);
353+
console.log("shape:", dataroot.shape);
354+
console.log("size:", dataroot.size);
355+
332356
let plotdata = dataroot.tolist();
357+
console.log("plotdata", plotdata);
333358
if (hastime.length == 0) {
334359
if (plotdata[0] instanceof Array)
335360
plotdata.unshift([...Array(plotdata[0].length).keys()]);
@@ -357,12 +382,14 @@ function dopreview(key, idx, isinternal, hastime) {
357382
: hastime[i];
358383
}
359384
let u = new uPlot(opts, plotdata, document.getElementById("plotchart"));
385+
console.log("first u", u);
360386
} else {
361387
let u = new uPlot(
362388
opts,
363389
[[...Array(dataroot.length).keys()], dataroot],
364390
document.getElementById("plotchart")
365391
);
392+
console.log("second u", u);
366393
}
367394
// add spinner
368395
// --- NEW LOGIC for 2D plot ---
@@ -1782,6 +1809,7 @@ function previewdataurl(url, idx) {
17821809
}
17831810

17841811
var plotdata = bjd;
1812+
console.log("plotdata", plotdata);
17851813

17861814
if (linkpath.length > 1 && !linkpath[1].match(/^Mesh[NSEVT]/)) {
17871815
let objpath = linkpath[1].split(/(?<!\\)\./);
@@ -1855,6 +1883,7 @@ function previewdataurl(url, idx) {
18551883
plotdata.hasOwnProperty("data") &&
18561884
plotdata.data.hasOwnProperty("dataTimeSeries")
18571885
) {
1886+
console.log("into the datatimeseries condition");
18581887
let serieslabel = true;
18591888
if (plotdata.data.hasOwnProperty("measurementList")) {
18601889
serieslabel = Array(plotdata.data.measurementList.length);
@@ -1866,6 +1895,8 @@ function previewdataurl(url, idx) {
18661895
plotdata.data.measurementList[i].detectorIndex;
18671896
}
18681897
}
1898+
console.log("serieslabel in plotdata.hasownproperty", serieslabel);
1899+
console.log("plotdata 2nd", plotdata);
18691900
previewdata(
18701901
nj.concatenate(
18711902
plotdata.data.time.reshape(plotdata.data.time.size, 1),
@@ -1886,6 +1917,40 @@ function previewdataurl(url, idx) {
18861917
console.log("window.extdata in preview", window.extdata); //
18871918
}
18881919
window.extdata[idx][2] = plotdata;
1920+
// window.extdata[idx][2] = bjd;
1921+
// urldata[url] = bjd; // Update cache
1922+
1923+
// // Case 1: 2D Time-Series Data (fNIRS)
1924+
// if (
1925+
// bjd.hasOwnProperty("data") &&
1926+
// bjd.data.hasOwnProperty("dataTimeSeries")
1927+
// ) {
1928+
// console.log("into the datatimeseries condition");
1929+
// let serieslabel = true;
1930+
// if (bjd.data.hasOwnProperty("measurementList")) {
1931+
// serieslabel = Array(bjd.data.measurementList.length);
1932+
// for (let i = 0; i < serieslabel.length; i++) {
1933+
// serieslabel[i] =
1934+
// "S" +
1935+
// bjd.data.measurementList[i].sourceIndex +
1936+
// "D" +
1937+
// bjd.data.measurementList[i].detectorIndex;
1938+
// }
1939+
// }
1940+
1941+
// // Prepare the specific numjs array needed for the 2D plot
1942+
// const plotData2D = nj.concatenate(
1943+
// bjd.data.time.reshape(bjd.data.time.size, 1),
1944+
// bjd.data.dataTimeSeries
1945+
// ).T;
1946+
1947+
// // Trigger the preview with the 2D data
1948+
// previewdata(plotData2D, idx, false, serieslabel);
1949+
// } else {
1950+
// // Case 2: All Other Data (NIfTI, Mesh, etc.)
1951+
// // Trigger the preview with the complete processed object.
1952+
// previewdata(bjd, idx, false);
1953+
// }
18891954

18901955
// ✅ Special case: time series preview
18911956
if (plotdata?.data?.dataTimeSeries) {

0 commit comments

Comments
 (0)